Mercurial > masqmail
annotate src/md5/hmactest.c @ 373:4cab237ce923
Fixed bug in matching of allowed recipients.
Thanks to Juergen Daubert for finding and reporting the issue.
The code had evaluated completely different data ...
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Sat, 14 Jan 2012 11:47:57 +0100 |
parents | b27f66555ba8 |
children |
rev | line source |
---|---|
0 | 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" | |
7 | |
212 | 8 /* |
367
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
9 ** instead of pad0_copy(d, s, sz) use: |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
10 ** memset(d, 0, sz); |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
11 ** memcpy(d, s, strlen(s)); |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
12 ** |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
13 ** static void |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
14 ** pad0_copy(char *d, char *s, int sz) |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
15 ** { |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
16 ** int i = 0; |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
17 ** while (*s && (i < sz)) { |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
18 ** *(d++) = *(s++); |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
19 ** i++; |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
20 ** } |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
21 ** while (i <= sz) { |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
22 ** *(d++) = 0; |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
23 ** i++; |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
24 ** } |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
25 ** } |
212 | 26 */ |
0 | 27 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
28 int |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
29 main() |
0 | 30 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
31 int i; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
32 char digest[16]; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
33 char *msgid = "<1896.697170952@postoffice.reston.mci.net>"; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
34 char secret[65]; |
0 | 35 |
212 | 36 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
37 hmac_md5("<48157.953508124@mail.class-c.net>", 34, "no!SpamAtAll", 12, digest); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
38 for (i = 0; i < 16; i++) |
212 | 39 printf("%.2x", 0xFF & (unsigned int) digest[i]); |
40 printf("\n\n"); | |
41 | |
42 | |
43 puts("---- The next two should be equal"); | |
44 | |
0 | 45 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
46 hmac_md5(msgid, strlen(msgid), "tanstaaftanstaaf", 16, digest); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
47 for (i = 0; i < 16; i++) |
212 | 48 printf("%.2x", 0xFF & (unsigned int) digest[i]); |
49 printf("\n\n"); | |
50 | |
0 | 51 |
212 | 52 /* pad0_copy(secret, "tanstaaftanstaaf", 64); */ |
53 /* let's do it easier ... */ | |
54 memset(secret, 0, sizeof(secret)); | |
55 memcpy(secret, "tanstaaftanstaaf", 16); | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
56 hmac_md5(msgid, strlen(msgid), secret, 64, digest); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
57 for (i = 0; i < 16; i++) |
212 | 58 printf("%.2x", 0xFF & (unsigned int) digest[i]); |
59 printf("\n\n"); | |
60 | |
61 | |
62 puts("---- Following are the test vectors from RFC 2104"); | |
63 | |
64 | |
366
41958685480d
Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents:
212
diff
changeset
|
65 char *d01 = "Hi There"; |
212 | 66 char k01[16]; |
67 for (i=0; i<16; i++) { | |
68 k01[i] = 0x0b; | |
69 } | |
70 printf("9294727a3638bb1c13f48ef8158bfc9d (should be)\n"); | |
71 hmac_md5(d01, strlen(d01), k01, sizeof(k01), digest); | |
72 for (i = 0; i < 16; i++) { | |
73 printf("%.2x", 0xFF & (unsigned int) digest[i]); | |
74 } | |
75 printf(" (was computed)\n\n"); | |
76 | |
77 | |
366
41958685480d
Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents:
212
diff
changeset
|
78 char *d02 = "what do ya want for nothing?"; |
41958685480d
Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents:
212
diff
changeset
|
79 char *k02 = "Jefe"; |
212 | 80 printf("750c783e6ab0b503eaa86e310a5db738 (should be)\n"); |
81 hmac_md5(d02, strlen(d02), k02, strlen(k02), digest); | |
82 for (i = 0; i < 16; i++) { | |
83 printf("%.2x", 0xFF & (unsigned int) digest[i]); | |
84 } | |
85 printf(" (was computed)\n\n"); | |
86 | |
87 | |
88 char d03[50]; | |
89 for (i=0; i<sizeof(d03); i++) { | |
90 d03[i] = 0xdd; | |
91 } | |
92 char k03[16]; | |
93 for (i=0; i<sizeof(k03); i++) { | |
94 k03[i] = 0xaa; | |
95 } | |
96 printf("56be34521d144c88dbb8c733f0e8b3f6 (should be)\n"); | |
97 hmac_md5(d03, sizeof(d03), k03, sizeof(k03), digest); | |
98 for (i = 0; i < 16; i++) { | |
99 printf("%.2x", 0xFF & (unsigned int) digest[i]); | |
100 } | |
101 printf(" (was computed)\n\n"); | |
0 | 102 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
103 exit(0); |
0 | 104 } |