projects
/
m6w6
/
libmemcached
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
This includes work for partitioning by key. Dormando wished for these methods.
[m6w6/libmemcached]
/
lib
/
md5.c
diff --git
a/lib/md5.c
b/lib/md5.c
index e12d5d1bea57d3fb480f250626696e96d7d9fd78..61f8d692898123085deb7f56e37413078423981b 100644
(file)
--- a/
lib/md5.c
+++ b/
lib/md5.c
@@
-30,6
+30,7
@@
documentation and/or software.
*/
*/
+#include <string.h>
#include <sys/types.h>
/* POINTER defines a generic pointer type */
#include <sys/types.h>
/* POINTER defines a generic pointer type */
@@
-47,9
+48,12
@@
typedef struct {
unsigned char buffer[64]; /* input buffer */
} MD5_CTX;
unsigned char buffer[64]; /* input buffer */
} MD5_CTX;
-static void MD5Init PROTO_LIST ((MD5_CTX *));
-static void MD5Update PROTO_LIST ((MD5_CTX *, unsigned char *, unsigned int));
-static void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *));
+static void MD5Init (MD5_CTX *context); /* context */
+static void MD5Update ( MD5_CTX *context, /* context */
+ unsigned char *input, /* input block */
+ unsigned int inputLen); /* length of input block */
+static void MD5Final ( unsigned char digest[16], /* message digest */
+ MD5_CTX *context); /* context */
/* Constants for MD5Transform routine. */
/* Constants for MD5Transform routine. */
@@
-71,13
+75,12
@@
static void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *));
#define S44 21
#define S44 21
-static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
-static void Encode PROTO_LIST
- ((unsigned char *, UINT4 *, unsigned int));
-static void Decode PROTO_LIST
- ((UINT4 *, unsigned char *, unsigned int));
-static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
-static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
+static void MD5Transform (UINT4 state[4],
+ unsigned char block[64]);
+static void Encode (unsigned char *output,
+ UINT4 *input,
+ unsigned int len);
+static void Decode(UINT4 *output, unsigned char *input, unsigned int len);
static unsigned char PADDING[64] = {
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
static unsigned char PADDING[64] = {
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@
-123,24
+126,15
@@
Rotation is separate from addition to prevent recomputation.
/*
Just a simple method for getting the signature
/*
Just a simple method for getting the signature
- result must be ==
32
+ result must be ==
16
*/
*/
-void md5_signature(
const unsigned char *key, unsigned int length,
char *result)
+void md5_signature(
unsigned char *key, unsigned int length, unsigned
char *result)
{
{
- const char *hex = "0123456789abcdef";
MD5_CTX my_md5;
MD5_CTX my_md5;
- unsigned char hash[16];
- char *r, i;
MD5Init(&my_md5);
MD5Init(&my_md5);
- (void)MD5Update(&my_md5, buf, length);
- MD5Final(hash, &my_md5);
-
- for (i = 0, r = result; i < 16; i++)
- {
- *r++ = hex[hash[i] >> 4];
- *r++ = hex[hash[i] & 0xF];
- }
+ (void)MD5Update(&my_md5, key, length);
+ MD5Final(result, &my_md5);
}
/* MD5 initialization. Begins an MD5 operation, writing a new context.
}
/* MD5 initialization. Begins an MD5 operation, writing a new context.
@@
-183,7
+177,7
@@
static void MD5Update (
/* Transform as many times as possible.
*/
if (inputLen >= partLen) {
/* Transform as many times as possible.
*/
if (inputLen >= partLen) {
-
MD5_
memcpy((POINTER)&context->buffer[idx], (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, context->buffer);
for (i = partLen; i + 63 < inputLen; i += 64)
@@
-195,7
+189,7
@@
static void MD5Update (
i = 0;
/* Buffer remaining input */
i = 0;
/* Buffer remaining input */
-
MD5_
memcpy((POINTER)&context->buffer[idx], (POINTER)&input[i],
+ memcpy((POINTER)&context->buffer[idx], (POINTER)&input[i],
inputLen-i);
}
inputLen-i);
}
@@
-227,7
+221,7
@@
static void MD5Final (
/* Zeroize sensitive information.
*/
/* Zeroize sensitive information.
*/
-
MD5_memset
((POINTER)context, 0, sizeof (*context));
+
memset
((POINTER)context, 0, sizeof (*context));
}
/* MD5 basic transformation. Transforms state based on block.
}
/* MD5 basic transformation. Transforms state based on block.
@@
-320,7
+314,7
@@
static void MD5Transform (
/* Zeroize sensitive information.
*/
/* Zeroize sensitive information.
*/
-
MD5_memset
((POINTER)x, 0, sizeof (x));
+
memset
((POINTER)x, 0, sizeof (x));
}
/* Encodes input (UINT4) into output (unsigned char). Assumes len is
}
/* Encodes input (UINT4) into output (unsigned char). Assumes len is
@@
-356,35
+350,3
@@
unsigned int len)
output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
(((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
}
output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
(((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
}
-
-/* Note: Replace "for loop" with standard memcpy if possible.
- */
-
-#ifndef MD5_memcpy
-static void MD5_memcpy (output, input, len)
-POINTER output;
-POINTER input;
-unsigned int len;
-{
- unsigned int i;
-
- for (i = 0; i < len; i++)
- output[i] = input[i];
-}
-#endif
-
-/* Note: Replace "for loop" with standard memset if possible.
- */
-
-#ifndef MD5_memset
-static void MD5_memset (output, value, len)
-POINTER output;
-int value;
-unsigned int len;
-{
- unsigned int i;
-
- for (i = 0; i < len; i++)
- ((char *)output)[i] = (char)value;
-}
-#endif