s/qmail 4.3.24
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
15
16void hmac_md5(char *text,int text_len,char * key,int key_len,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 char tk[16];
22 int i;
23
24 if (key_len > 64) {
25 MD5Init(&context);
26 MD5Update(&context,(unsigned char *) key,key_len);
27 MD5Final((unsigned char *) tk,&context);
28 key = tk;
29 key_len = 16;
30 }
31
32 byte_zero((char *)k_ipad,sizeof(k_ipad));
33 byte_zero((char *)k_opad,sizeof(k_opad));
34 byte_copy((char *)k_ipad,key_len,key);
35 byte_copy((char *)k_opad,key_len,key);
36
37 for (i = 0; i < 64; i++) {
38 k_ipad[i] ^= 0x36;
39 k_opad[i] ^= 0x5c;
40 }
41
42 MD5Init(&context); /* init context for 1st pass */
43 MD5Update(&context,k_ipad,64); /* start with inner pad */
44 MD5Update(&context,(unsigned char *) text,text_len); /* then text of datagram */
45 MD5Final((unsigned char *) digest,&context); /* finish up 1st pass */
46
47 MD5Init(&context); /* init context for 2nd pass */
48 MD5Update(&context,k_opad,64); /* start with outer pad */
49 MD5Update(&context,(unsigned char *) digest,16); /* then results of 1st hash */
50 MD5Final((unsigned char *) digest,&context); /* finish up 2nd pass */
51}
stralloc key
void hmac_md5(char *text, int text_len, char *key, int key_len, char *digest)
Definition hmac_md5.c:16
stralloc text
void MD5Init(MD5_CTX *)
Definition md5c.c:94
void MD5Final(unsigned char[16], MD5_CTX *)
Definition md5c.c:143
void MD5Update(MD5_CTX *, unsigned char *, unsigned int)
Definition md5.h:31