]> jfr.im git - irc/evilnet/x3.git/blobdiff - src/md5.c
Minor typo in previous commit where returning 0 when it should have been 1 from opser...
[irc/evilnet/x3.git] / src / md5.c
index 7b8edbc1e1437fb328fb9d74824f3b7654182483..c454a0409f34be1ae023bb6bad8b3bce46915523 100644 (file)
--- a/src/md5.c
+++ b/src/md5.c
@@ -5,7 +5,7 @@
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation; either version 3 of the License, or
  *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
@@ -139,10 +139,10 @@ MD5_CTX *context;                                        /* context */
 unsigned char *input;                                /* input block */
 unsigned int inputLen;                     /* length of input block */
 {
-  unsigned int i, index, partLen;
+  unsigned int i, idx, partLen;
 
   /* Compute number of bytes mod 64 */
-  index = (unsigned int)((context->count[0] >> 3) & 0x3F);
+  idx = (unsigned int)((context->count[0] >> 3) & 0x3F);
 
   /* Update number of bits */
   if ((context->count[0] += ((UINT4)inputLen << 3))
@@ -150,23 +150,23 @@ unsigned int inputLen;                     /* length of input block */
       context->count[1]++;
   context->count[1] += ((UINT4)inputLen >> 29);
 
-  partLen = 64 - index;
+  partLen = 64 - idx;
 
   /* Transform as many times as possible. */
   if (inputLen >= partLen) {
-      memcpy((POINTER)&context->buffer[index], (POINTER)input, partLen);
+      memcpy((POINTER)&context->buffer[idx], (POINTER)input, partLen);
       MD5Transform (context->state, context->buffer);
 
       for (i = partLen; i + 63 < inputLen; i += 64)
          MD5Transform (context->state, &input[i]);
 
-      index = 0;
+      idx = 0;
   }
   else
     i = 0;
 
   /* Buffer remaining input */
-  memcpy((POINTER)&context->buffer[index], (POINTER)&input[i],
+  memcpy((POINTER)&context->buffer[idx], (POINTER)&input[i],
   inputLen-i);
 }
 
@@ -178,14 +178,14 @@ unsigned char digest[16];                         /* message digest */
 MD5_CTX *context;                                       /* context */
 {
   unsigned char bits[8];
-  unsigned int index, padLen;
+  unsigned int idx, padLen;
 
   /* Save number of bits */
   Encode (bits, context->count, 8);
 
   /* Pad out to 56 mod 64. */
-  index = (unsigned int)((context->count[0] >> 3) & 0x3f);
-  padLen = (index < 56) ? (56 - index) : (120 - index);
+  idx = (unsigned int)((context->count[0] >> 3) & 0x3f);
+  padLen = (idx < 56) ? (56 - idx) : (120 - idx);
   MD5Update (context, PADDING, padLen);
 
   /* Append length (before padding) */
@@ -439,6 +439,7 @@ void md5_process( md5_context *ctx, uint8 data[64] )
     C = ctx->state[2];
     D = ctx->state[3];
 
+#undef F
 #define F(x,y,z) (z ^ (x & (y ^ z)))
 
     P( A, B, C, D,  0,  7, 0xD76AA478 );
@@ -611,30 +612,7 @@ void md5_finish( md5_context *ctx, uint8 digest[16] )
  * those are the standard RFC 1321 test vectors
  */
 
-static char *msg[] = 
-{
-    "",
-    "a",
-    "abc",
-    "message digest",
-    "abcdefghijklmnopqrstuvwxyz",
-    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
-    "12345678901234567890123456789012345678901234567890123456789012" \
-        "345678901234567890"
-};
-
-static char *val[] =
-{
-    "d41d8cd98f00b204e9800998ecf8427e",
-    "0cc175b9c0f1b6a831c399e269772661",
-    "900150983cd24fb0d6963f7d28e17f72",
-    "f96b697d7cb7938d525a2f31aaf161d0",
-    "c3fcd3d76192e4007dfb496cca67e13b",
-    "d174ab98d277d9f5a5611c2c9f419d9f",
-    "57edf4a22be3c955ac49da2e2107b67a"
-};
-
-char* md5(char* pass, char* output)
+char* md5(const char* pass, char* output)
 {
     md5_context ctx;
     int j;
@@ -647,7 +625,8 @@ char* md5(char* pass, char* output)
     {
         sprintf(output + j * 2, "%02x", md5sum[j]);
     }
-    printf("The hash of %s is %s\n\n", pass, output);
+    /* printf("The hash of %s is %s\n\n", pass, output); */
+    return 0;
 }
 
 const char *
@@ -657,22 +636,22 @@ cryptpass(const char *pass, char *buffer)
 }
 
 int
-checkpass(const char *pass, const char *crypt)
+checkpass(const char *pass, const char *crypted)
 {
-    char new_crypt[MD5_CRYPT_LENGTH], hseed[9];
+    char new_crypted[MD5_CRYPT_LENGTH], hseed[9];
     int seed;
 
-    if (crypt[0] == '$') {
+    if (crypted[0] == '$') {
         /* new-style crypt, use "seed" after '$' */
-        strncpy(hseed, crypt+1, 8);
+        strncpy(hseed, crypted+1, 8);
         hseed[8] = 0;
         seed = strtoul(hseed, NULL, 16);
-        cryptpass_real(pass, new_crypt, seed);
+        cryptpass_real(pass, new_crypted, seed);
     } else {
         /* new "old-style" md5 crypt compatable with php, md5sum etc */
-        md5(pass, new_crypt);
+        md5(pass, new_crypted);
     }
-    return !strcmp(crypt, new_crypt);
+    return !strcmp(crypted, new_crypted);
 }