annotate src/md5/hmactest.c @ 304:d5ce2ba71e7b

manual formating of Received: hdrs; changed hdr for local receival Now the Received: headers are much friendlier to read. About folding: We must fold any line at 998 chars before transfer. We should fold the lines we produce at 78 chars. That is what RFC 2821 requests. We should think about it, somewhen. The header for locally (i.e. non-SMTP) received mail is changed to the format postfix uses. This matches RFC 2821 better. The `from' clause should contain a domain or IP, not a user name. Also, the `with' clause should contain a registered standard protocol name, which ``local'' is not.
author markus schnalke <meillo@marmaro.de>
date Thu, 09 Dec 2010 18:28:11 -0300 (2010-12-09)
parents 38f86ae6171b
children 41958685480d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
1 #include <stdio.h>
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
2 #include <stdlib.h>
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
3 #include <sys/time.h>
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
4 #include <string.h>
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
5 #include "md5.h"
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
6 #include "hmac_md5.h"
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
7
212
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
8 /*
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
9 instead of pad0_copy(d, s, sz) use:
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
10 memset(d, 0, sz);
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
11 memcpy(d, s, strlen(s));
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
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
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
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
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
25 }
212
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
26 */
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
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
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
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
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
35
212
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
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
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
39 printf("%.2x", 0xFF & (unsigned int) digest[i]);
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
40 printf("\n\n");
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
41
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
42
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
43 puts("---- The next two should be equal");
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
44
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
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
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
48 printf("%.2x", 0xFF & (unsigned int) digest[i]);
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
49 printf("\n\n");
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
50
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
51
212
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
52 /* pad0_copy(secret, "tanstaaftanstaaf", 64); */
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
53 /* let's do it easier ... */
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
54 memset(secret, 0, sizeof(secret));
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
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
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
58 printf("%.2x", 0xFF & (unsigned int) digest[i]);
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
59 printf("\n\n");
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
60
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
61
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
62 puts("---- Following are the test vectors from RFC 2104");
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
63
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
64
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
65 char* d01 = "Hi There";
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
66 char k01[16];
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
67 for (i=0; i<16; i++) {
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
68 k01[i] = 0x0b;
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
69 }
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
70 printf("9294727a3638bb1c13f48ef8158bfc9d (should be)\n");
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
71 hmac_md5(d01, strlen(d01), k01, sizeof(k01), digest);
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
72 for (i = 0; i < 16; i++) {
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
73 printf("%.2x", 0xFF & (unsigned int) digest[i]);
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
74 }
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
75 printf(" (was computed)\n\n");
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
76
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
77
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
78 char* d02 = "what do ya want for nothing?";
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
79 char* k02 = "Jefe";
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
80 printf("750c783e6ab0b503eaa86e310a5db738 (should be)\n");
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
81 hmac_md5(d02, strlen(d02), k02, strlen(k02), digest);
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
82 for (i = 0; i < 16; i++) {
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
83 printf("%.2x", 0xFF & (unsigned int) digest[i]);
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
84 }
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
85 printf(" (was computed)\n\n");
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
86
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
87
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
88 char d03[50];
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
89 for (i=0; i<sizeof(d03); i++) {
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
90 d03[i] = 0xdd;
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
91 }
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
92 char k03[16];
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
93 for (i=0; i<sizeof(k03); i++) {
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
94 k03[i] = 0xaa;
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
95 }
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
96 printf("56be34521d144c88dbb8c733f0e8b3f6 (should be)\n");
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
97 hmac_md5(d03, sizeof(d03), k03, sizeof(k03), digest);
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
98 for (i = 0; i < 16; i++) {
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
99 printf("%.2x", 0xFF & (unsigned int) digest[i]);
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
100 }
38f86ae6171b improved hmactest
meillo@marmaro.de
parents: 209
diff changeset
101 printf(" (was computed)\n\n");
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
102
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
103 exit(0);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
104 }