Mercurial > masqmail
annotate src/md5/hmactest.c @ 222:8cddc65765bd
added support for STARTTLS wrappers
added the route config option `instant_helo' which
causes masqmail, as SMTP client, not to wait for the
server's 220 greeting. Instead if says EHLO right at
once. You'll need this for STARTTLS wrappers that
usually eat the greeting line.
author | meillo@marmaro.de |
---|---|
date | Fri, 23 Jul 2010 10:57:53 +0200 |
parents | 38f86ae6171b |
children | 41958685480d |
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 /* |
9 instead of pad0_copy(d, s, sz) use: | |
10 memset(d, 0, sz); | |
11 memcpy(d, s, strlen(s)); | |
12 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
13 static void |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
14 pad0_copy(char *d, char *s, int sz) |
0 | 15 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
16 int i = 0; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
17 while (*s && (i < sz)) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
18 *(d++) = *(s++); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
19 i++; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
20 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
21 while (i <= sz) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
22 *(d++) = 0; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
23 i++; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
24 } |
0 | 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 | |
65 char* d01 = "Hi There"; | |
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 | |
78 char* d02 = "what do ya want for nothing?"; | |
79 char* k02 = "Jefe"; | |
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 } |