diff options
Diffstat (limited to 'src/lib/md5.h')
-rw-r--r-- | src/lib/md5.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/lib/md5.h b/src/lib/md5.h new file mode 100644 index 00000000..ad1151e9 --- /dev/null +++ b/src/lib/md5.h | |||
@@ -0,0 +1,64 @@ | |||
1 | /* | ||
2 | * This code implements the MD5 message-digest algorithm. | ||
3 | * The algorithm is due to Ron Rivest. This code was | ||
4 | * written by Colin Plumb in 1993, no copyright is claimed. | ||
5 | * This code is in the public domain; do with it what you wish. | ||
6 | * | ||
7 | * Equivalent code is available from RSA Data Security, Inc. | ||
8 | * This code has been tested against that, and is equivalent, | ||
9 | * except that you don't need to include two pages of legalese | ||
10 | * with every copy. | ||
11 | * | ||
12 | * To compute the message digest of a chunk of bytes, declare an | ||
13 | * MD5Context structure, pass it to MD5Init, call MD5Update as | ||
14 | * needed on buffers full of bytes, and then call MD5Final, which | ||
15 | * will fill a supplied 16-byte array with the digest. | ||
16 | */ | ||
17 | |||
18 | #ifndef MHD_MD5_H | ||
19 | #define MHD_MD5_H | ||
20 | |||
21 | #include "platform.h" | ||
22 | |||
23 | #define MD5_BLOCK_SIZE 64 | ||
24 | #define MD5_DIGEST_SIZE 16 | ||
25 | #define MD5_DIGEST_STRING_LENGTH (MD5_DIGEST_SIZE * 2 + 1) | ||
26 | |||
27 | struct MD5Context | ||
28 | { | ||
29 | uint32_t state[4]; /* state */ | ||
30 | uint64_t count; /* number of bits, mod 2^64 */ | ||
31 | uint8_t buffer[MD5_BLOCK_SIZE]; /* input buffer */ | ||
32 | }; | ||
33 | |||
34 | /* | ||
35 | * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious | ||
36 | * initialization constants. | ||
37 | */ | ||
38 | void MD5Init(struct MD5Context *ctx); | ||
39 | |||
40 | /* | ||
41 | * Update context to reflect the concatenation of another buffer full | ||
42 | * of bytes. | ||
43 | */ | ||
44 | void MD5Update(struct MD5Context *ctx, const unsigned char *input, size_t len); | ||
45 | |||
46 | /* | ||
47 | * Pad pad to 64-byte boundary with the bit pattern | ||
48 | * 1 0* (64-bit count of bits processed, MSB-first) | ||
49 | */ | ||
50 | void MD5Pad(struct MD5Context *ctx); | ||
51 | |||
52 | /* | ||
53 | * Final wrapup--call MD5Pad, fill in digest and zero out ctx. | ||
54 | */ | ||
55 | void MD5Final(unsigned char digest[MD5_DIGEST_SIZE], struct MD5Context *ctx); | ||
56 | |||
57 | /* | ||
58 | * The core of the MD5 algorithm, this alters an existing MD5 hash to | ||
59 | * reflect the addition of 16 longwords of new data. MD5Update blocks | ||
60 | * the data and converts bytes into longwords for this routine. | ||
61 | */ | ||
62 | void MD5Transform(uint32_t state[4], const uint8_t block[MD5_BLOCK_SIZE]); | ||
63 | |||
64 | #endif /* !MHD_MD5_H */ | ||