annotate src/md5/hmactest.c @ 164:b8c358b2e242
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:20 +0200 |
parents |
26e34ae9a3e3 |
children |
ca99aa7f052a |
rev |
line source |
meillo@0
|
1 #include <stdio.h>
|
meillo@0
|
2 #include <stdlib.h>
|
meillo@0
|
3 #include <sys/time.h>
|
meillo@0
|
4 #include <string.h>
|
meillo@0
|
5 #include "md5.h"
|
meillo@0
|
6 #include "hmac_md5.h"
|
meillo@0
|
7
|
meillo@10
|
8 static void
|
meillo@10
|
9 pad0_copy(char *d, char *s, int sz)
|
meillo@0
|
10 {
|
meillo@10
|
11 int i = 0;
|
meillo@10
|
12 while (*s && (i < sz)) {
|
meillo@10
|
13 *(d++) = *(s++);
|
meillo@10
|
14 i++;
|
meillo@10
|
15 }
|
meillo@10
|
16 while (i <= sz) {
|
meillo@10
|
17 *(d++) = 0;
|
meillo@10
|
18 i++;
|
meillo@10
|
19 }
|
meillo@0
|
20 }
|
meillo@0
|
21
|
meillo@10
|
22 int
|
meillo@10
|
23 main()
|
meillo@0
|
24 {
|
meillo@10
|
25 int i;
|
meillo@10
|
26 // unsigned char digest[16];
|
meillo@10
|
27 char digest[16];
|
meillo@10
|
28 char *msgid = "<1896.697170952@postoffice.reston.mci.net>";
|
meillo@10
|
29 char secret[65];
|
meillo@0
|
30
|
meillo@10
|
31 hmac_md5("<48157.953508124@mail.class-c.net>", 34, "no!SpamAtAll", 12, digest);
|
meillo@10
|
32 for (i = 0; i < 16; i++)
|
meillo@10
|
33 printf("%x", (unsigned int) digest[i]);
|
meillo@10
|
34 printf("\n");
|
meillo@0
|
35
|
meillo@10
|
36 hmac_md5(msgid, strlen(msgid), "tanstaaftanstaaf", 16, digest);
|
meillo@10
|
37 for (i = 0; i < 16; i++)
|
meillo@10
|
38 printf("%x", (unsigned int) digest[i]);
|
meillo@10
|
39 printf("\n");
|
meillo@0
|
40
|
meillo@10
|
41 pad0_copy(secret, "tanstaaftanstaaf", 64);
|
meillo@10
|
42 hmac_md5(msgid, strlen(msgid), secret, 64, digest);
|
meillo@10
|
43 for (i = 0; i < 16; i++)
|
meillo@10
|
44 printf("%x", (unsigned int) digest[i]);
|
meillo@10
|
45 printf("\n");
|
meillo@0
|
46
|
meillo@10
|
47 exit(0);
|
meillo@0
|
48 }
|