2008-10-28 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mono / utils / mono-sha1.c
index 88f5ddb739cf17a9ad8269637a9d6501aed6754c..8e77fa4af1205c1b9c874204349692ae136237fe 100644 (file)
@@ -72,17 +72,9 @@ A million repetitions of "a"
 
 #include <stdio.h>
 #include <string.h>
+#include <glib.h>
 #include "mono-digest.h"
 
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
-#define LITTLE_ENDIAN
-#endif
-
-typedef          long long int int64;
-typedef unsigned long long int uint64;
-typedef          long int int32;
-typedef unsigned long int uint32;
-
 
 /* #include <process.h> */     /* prototype for exit() - JHB */
 /* Using return() instead of exit() - SWR */
@@ -93,7 +85,7 @@ static void SHA1Transform(guint32 state[5], const guchar buffer[64]);
 
 /* blk0() and blk() perform the initial expand. */
 /* I got the idea of expanding during the round function from SSLeay */
-#ifdef LITTLE_ENDIAN
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
 #define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \
     |(rol(block->l[i],8)&0x00FF00FF))
 #else
@@ -127,10 +119,10 @@ static void SHAPrintContext(MonoSHA1Context *context, char *msg){
 
 static void SHA1Transform(guint32 state[5], const guchar buffer[64])
 {
-uint32 a, b, c, d, e;
+guint32 a, b, c, d, e;
 typedef union {
     unsigned char c[64];
-    uint32 l[16];
+    guint32 l[16];
 } CHAR64LONG16;
 CHAR64LONG16* block;
 #ifdef SHA1HANDSOFF
@@ -197,7 +189,7 @@ void mono_sha1_init(MonoSHA1Context* context)
 void mono_sha1_update(MonoSHA1Context* context, const guchar* data, guint32 len)       /*
 JHB */
 {
-uint32 i, j;   /* JHB */
+guint32 i, j;  /* JHB */
 
 #ifdef VERBOSE
     SHAPrintContext(context, "before");
@@ -225,7 +217,7 @@ uint32 i, j;        /* JHB */
 
 void mono_sha1_final( MonoSHA1Context* context, unsigned char digest[20])
 {
-uint32 i;      /* JHB */
+guint32 i;     /* JHB */
 unsigned char finalcount[8];
 
     for (i = 0; i < 8; i++) {
@@ -254,7 +246,7 @@ unsigned char finalcount[8];
 }
  
 void
-mono_sha1_get_digest (const gchar *buffer, gint buffer_size, guchar digest [20])
+mono_sha1_get_digest (const guchar *buffer, gint buffer_size, guchar digest [20])
 {      
        MonoSHA1Context ctx;
 
@@ -284,6 +276,8 @@ mono_sha1_get_digest_from_file (const gchar *filename, guchar digest [20])
        if (ferror(fp)) {
                fclose(fp);
                return;
+       } else {
+               fclose(fp);
        }
 
        mono_sha1_final (&ctx, digest);