Mercurial > masqmail-0.2
comparison src/md5/hmac_md5.c @ 162:52c82d755215
replaced the MD5 implementation with the one of Solar Designer
Until now, the sample code of RFC 1321 was used. It had an ugly license.
Now we use the implementation of Solar Designer, which is in the Public Domain.
http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5
author | meillo@marmaro.de |
---|---|
date | Sun, 18 Jul 2010 22:01:04 +0200 |
parents | 26e34ae9a3e3 |
children | b8c358b2e242 |
comparison
equal
deleted
inserted
replaced
161:6655f7708ee1 | 162:52c82d755215 |
---|---|
1 /* | 1 /* |
2 ** Function: hmac_md5 | 2 ** Function: hmac_md5 |
3 */ | 3 */ |
4 | 4 |
5 #include <string.h> | 5 #include <string.h> |
6 #include "global.h" | |
7 #include "md5.h" | 6 #include "md5.h" |
8 #include "hmac_md5.h" | 7 #include "hmac_md5.h" |
9 | 8 |
10 void | 9 void |
11 hmac_md5(unsigned char *text, int text_len, unsigned char *key, int key_len, unsigned char *digest) | 10 hmac_md5(unsigned char *text, int text_len, unsigned char *key, int key_len, unsigned char *digest) |
23 /* if key is longer than 64 bytes reset it to key=MD5(key) */ | 22 /* if key is longer than 64 bytes reset it to key=MD5(key) */ |
24 if (key_len > 64) { | 23 if (key_len > 64) { |
25 | 24 |
26 MD5_CTX tctx; | 25 MD5_CTX tctx; |
27 | 26 |
28 MD5Init(&tctx); | 27 MD5_Init(&tctx); |
29 MD5Update(&tctx, key, key_len); | 28 MD5_Update(&tctx, key, key_len); |
30 MD5Final(tk, &tctx); | 29 MD5_Final(tk, &tctx); |
31 | 30 |
32 key = tk; | 31 key = tk; |
33 key_len = 16; | 32 key_len = 16; |
34 } | 33 } |
35 | 34 |
56 k_opad[i] ^= 0x5c; | 55 k_opad[i] ^= 0x5c; |
57 } | 56 } |
58 /* | 57 /* |
59 * perform inner MD5 | 58 * perform inner MD5 |
60 */ | 59 */ |
61 MD5Init(&context); /* init context for 1st pass */ | 60 MD5_Init(&context); /* init context for 1st pass */ |
62 MD5Update(&context, k_ipad, 64); /* start with inner pad */ | 61 MD5_Update(&context, k_ipad, 64); /* start with inner pad */ |
63 MD5Update(&context, text, text_len); /* then text of datagram */ | 62 MD5_Update(&context, text, text_len); /* then text of datagram */ |
64 MD5Final(digest, &context); /* finish up 1st pass */ | 63 MD5_Final(digest, &context); /* finish up 1st pass */ |
65 /* | 64 /* |
66 * perform outer MD5 | 65 * perform outer MD5 |
67 */ | 66 */ |
68 MD5Init(&context); /* init context for 2nd pass */ | 67 MD5_Init(&context); /* init context for 2nd pass */ |
69 MD5Update(&context, k_opad, 64); /* start with outer pad */ | 68 MD5_Update(&context, k_opad, 64); /* start with outer pad */ |
70 MD5Update(&context, digest, 16); /* then results of 1st hash */ | 69 MD5_Update(&context, digest, 16); /* then results of 1st hash */ |
71 MD5Final(digest, &context); /* finish up 2nd pass */ | 70 MD5_Final(digest, &context); /* finish up 2nd pass */ |
72 } | 71 } |