s/qmail 4.2.29a
Next generation secure email transport
Loading...
Searching...
No Matches
hmac_md5.c
Go to the documentation of this file.
1#include "global.h"
2#include "md5.h"
3#include "str.h"
4#include "byte.h"
5
16void hmac_md5(unsigned char *text,int text_len,unsigned char * key,int key_len,unsigned char *digest)
17{
18 MD5_CTX context;
19 unsigned char k_ipad[65]; /* inner padding - key XORd with ipad */
20 unsigned char k_opad[65]; /* outer padding - key XORd with opad */
21 unsigned char tk[16];
22 int i;
23
24 if (key_len > 64) {
25 MD5_CTX tctx;
26 MD5Init(&tctx);
27 MD5Update(&tctx,key,key_len);
28 MD5Final(tk,&tctx);
29 key = tk;
30 key_len = 16;
31 }
32
33 byte_zero(k_ipad,sizeof(k_ipad));
34 byte_zero(k_opad,sizeof(k_opad));
35 byte_copy(k_ipad,key_len,key);
36 byte_copy(k_opad,key_len,key);
37
38 for (i = 0; i < 64; i++) {
39 k_ipad[i] ^= 0x36;
40 k_opad[i] ^= 0x5c;
41 }
42
43 MD5Init(&context); /* init context for 1st pass */
44 MD5Update(&context,k_ipad,64); /* start with inner pad */
45 MD5Update(&context,text,text_len); /* then text of datagram */
46 MD5Final(digest,&context); /* finish up 1st pass */
47
48 MD5Init(&context); /* init context for 2nd pass */
49 MD5Update(&context,k_opad,64); /* start with outer pad */
50 MD5Update(&context,digest,16); /* then results of 1st hash */
51 MD5Final(digest,&context); /* finish up 2nd pass */
52}
stralloc key
Definition: fastforward.c:116
void hmac_md5(unsigned char *text, int text_len, unsigned char *key, int key_len, unsigned char *digest)
Definition: hmac_md5.c:16
stralloc text
Definition: maildirwatch.c:21
void MD5Init(MD5_CTX *context)
Definition: md5c.c:96
void MD5Final(digest, MD5_CTX *context)
Definition: md5c.c:154
void MD5Update(MD5_CTX *context, unsigned char *input, unsigned int inputLen)
Definition: md5c.c:113
Definition: md5.h:34