[runtime] Fix DISABLE_REFLECTION_EMIT build.
[mono.git] / mono / utils / mono-sha1.c
index 8e77fa4af1205c1b9c874204349692ae136237fe..4a6415f3fde705cff9e03433c353ad5fc06dfe05 100644 (file)
@@ -1,4 +1,5 @@
-/*
+/**
+\file
 SHA-1 in C
 By Steve Reid <sreid@sea-to-sky.net>
 100% Public Domain
@@ -75,6 +76,36 @@ A million repetitions of "a"
 #include <glib.h>
 #include "mono-digest.h"
 
+#if HAVE_COMMONCRYPTO_COMMONDIGEST_H
+
+/**
+ * mono_sha1_init:
+ */
+void
+mono_sha1_init (MonoSHA1Context* context)
+{
+       CC_SHA1_Init (context);
+}
+
+/**
+ * mono_sha1_update:
+ */
+void
+mono_sha1_update (MonoSHA1Context* context, const guchar* data, guint32 len)
+{
+       CC_SHA1_Update (context, data, len);
+}
+
+/**
+ * mono_sha1_final:
+ */
+void
+mono_sha1_final (MonoSHA1Context* context, unsigned char digest[20])
+{
+       CC_SHA1_Final (digest, context);
+}
+
+#else
 
 /* #include <process.h> */     /* prototype for exit() - JHB */
 /* Using return() instead of exit() - SWR */
@@ -126,7 +157,7 @@ typedef union {
 } CHAR64LONG16;
 CHAR64LONG16* block;
 #ifdef SHA1HANDSOFF
-static unsigned char workspace[64];
+    unsigned char workspace[64];
     block = (CHAR64LONG16*)workspace;
     memcpy(block, buffer, 64);
 #else
@@ -244,7 +275,12 @@ unsigned char finalcount[8];
     SHA1Transform(context->state, context->buffer);
 #endif
 }
+
+#endif
+
+/**
+ * mono_sha1_get_digest:
+ */
 void
 mono_sha1_get_digest (const guchar *buffer, gint buffer_size, guchar digest [20])
 {      
@@ -256,6 +292,16 @@ mono_sha1_get_digest (const guchar *buffer, gint buffer_size, guchar digest [20]
        
 }
 
+/**
+ * mono_sha1_get_digest_from_file:
+ * \param filename file name
+ * \param digest 20-byte buffer receiving the hash code.
+ * 
+ * Get the SHA-1 hash of a file. The result is put in 
+ * the 20-byte buffer \p digest.
+ * 
+ * If an IO error happens the value in \p digest is not updated.
+ */
 void
 mono_sha1_get_digest_from_file (const gchar *filename, guchar digest [20])
 {      
@@ -283,11 +329,11 @@ mono_sha1_get_digest_from_file (const gchar *filename, guchar digest [20])
        mono_sha1_final (&ctx, digest);
 }
 
-/*
+/**
  * mono_digest_get_public_token:
  *
  * Get the public token from public key data.
- * @token must point to at least 8 bytes of storage.
+ * \p token must point to at least 8 bytes of storage.
  */
 void 
 mono_digest_get_public_token (guchar* token, const guchar *pubkey, guint32 len)