masqmail

view src/md5/hmactest.c @ 211:0f36c0a46f82

replaced hmac_md5.c with an own implementation of RFC 2104 Until now the sample code of the RFC itself was used, but it lacked a license or copyright notice. See the comment in hmac_md5.c for details.
author meillo@marmaro.de
date Sun, 18 Jul 2010 22:20:36 +0200
parents dcb315792513
children 38f86ae6171b
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/time.h>
4 #include <string.h>
5 #include "md5.h"
6 #include "hmac_md5.h"
8 static void
9 pad0_copy(char *d, char *s, int sz)
10 {
11 int i = 0;
12 while (*s && (i < sz)) {
13 *(d++) = *(s++);
14 i++;
15 }
16 while (i <= sz) {
17 *(d++) = 0;
18 i++;
19 }
20 }
22 int
23 main()
24 {
25 int i;
26 /* unsigned char digest[16]; */
27 char digest[16];
28 char *msgid = "<1896.697170952@postoffice.reston.mci.net>";
29 char secret[65];
31 hmac_md5("<48157.953508124@mail.class-c.net>", 34, "no!SpamAtAll", 12, digest);
32 for (i = 0; i < 16; i++)
33 printf("%x", (unsigned int) digest[i]);
34 printf("\n");
36 hmac_md5(msgid, strlen(msgid), "tanstaaftanstaaf", 16, digest);
37 for (i = 0; i < 16; i++)
38 printf("%x", (unsigned int) digest[i]);
39 printf("\n");
41 pad0_copy(secret, "tanstaaftanstaaf", 64);
42 hmac_md5(msgid, strlen(msgid), secret, 64, digest);
43 for (i = 0; i < 16; i++)
44 printf("%x", (unsigned int) digest[i]);
45 printf("\n");
47 exit(0);
48 }