Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / utils / mono-md5.c
index c4e0438a0310d2e21bc5bea0ec4c0bf2b3dbf073..e353c84256aa0fff865ed77ba9b94510c531e45a 100644 (file)
@@ -1,5 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
+/**
+ * \file
  * This code implements the MD5 message-digest algorithm.
  * The algorithm is due to Ron Rivest.  This code was
  * written by Colin Plumb in 1993, no copyright is claimed.
 #include <string.h>
 #include "mono-digest.h"
 
+#if HAVE_COMMONCRYPTO_COMMONDIGEST_H
+
+/**
+ * mono_md5_init:
+ */
+void
+mono_md5_init (MonoMD5Context *ctx)
+{
+       CC_MD5_Init (ctx);
+}
+
+/**
+ * mono_md5_update:
+ */
+void
+mono_md5_update (MonoMD5Context *ctx, const guchar *buf, guint32 len)
+{
+       CC_MD5_Update (ctx, buf, len);
+}
+
+/**
+ * mono_md5_final:
+ */
+void
+mono_md5_final (MonoMD5Context *ctx, guchar digest[16])
+{
+       CC_MD5_Final (digest, ctx);
+}
+
+#else
+
 static void md5_transform (guint32 buf[4], const guint32 in[16]);
 
 static gint _ie = 0x44332211;
@@ -295,18 +327,18 @@ md5_transform (guint32 buf[4], const guint32 in[16])
        buf[3] += d;
 }
 
-
+#endif
 
 
 /**
- * mono_md5_get_digest: get the md5 hash of a buffer
- * @buffer: byte buffer
- * @buffer_size: buffer size (in bytes)
- * @digest: 16 bytes buffer receiving the hash code.
+ * mono_md5_get_digest:
+ * \param buffer byte buffer
+ * \param buffer_size buffer size (in bytes)
+ * \param digest 16-byte buffer receiving the hash code.
  * 
- * Get the md5 hash of a buffer. The result is put in 
- * the 16 bytes buffer @digest .
- **/
+ * Get the MD5 hash of a buffer. The result is put in 
+ * the 16-byte buffer \p digest.
+ */
 void
 mono_md5_get_digest (const guchar *buffer, gint buffer_size, guchar digest[16])
 {      
@@ -320,13 +352,15 @@ mono_md5_get_digest (const guchar *buffer, gint buffer_size, guchar digest[16])
 
 
 /**
- * mono_md5_get_digest_from_file: get the md5 hash of a file
- * @filename: file name
- * @digest: 16 bytes buffer receiving the hash code.
+ * mono_md5_get_digest_from_file:
+ * \param filename file name
+ * \param digest 16-byte buffer receiving the hash code.
  * 
- * Get the md5 hash of a file. The result is put in 
- * the 16 bytes buffer @digest .
- **/
+ * Get the MD5 hash of a file. The result is put in 
+ * the 16-byte buffer \p digest.
+ * 
+ * If an IO error happens the value in \p digest is not updated.
+ */
 void
 mono_md5_get_digest_from_file (const gchar *filename, guchar digest[16])
 {      
@@ -347,6 +381,8 @@ mono_md5_get_digest_from_file (const gchar *filename, guchar digest[16])
        if (ferror(fp)) {
                fclose(fp);
                return;
+       } else {
+               fclose(fp);
        }
 
        mono_md5_final (&ctx, digest);