aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/test_md5.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/test_md5.c')
-rw-r--r--src/microhttpd/test_md5.c406
1 files changed, 233 insertions, 173 deletions
diff --git a/src/microhttpd/test_md5.c b/src/microhttpd/test_md5.c
index d9517206..2825c09f 100644
--- a/src/microhttpd/test_md5.c
+++ b/src/microhttpd/test_md5.c
@@ -33,7 +33,7 @@ static int verbose = 0; /* verbose level (0-1)*/
33 33
34struct str_with_len 34struct str_with_len
35{ 35{
36 const char * const str; 36 const char *const str;
37 const size_t len; 37 const size_t len;
38}; 38};
39 39
@@ -46,17 +46,22 @@ struct data_unit1
46}; 46};
47 47
48static const struct data_unit1 data_units1[] = { 48static const struct data_unit1 data_units1[] = {
49 {D_STR_W_LEN("1234567890!@~%&$@#{}[]\\/!?`."), 49 {D_STR_W_LEN ("1234567890!@~%&$@#{}[]\\/!?`."),
50 {0x1c, 0x68, 0xc2, 0xe5, 0x1f, 0x63, 0xc9, 0x5f, 0x17, 0xab, 0x1f, 0x20, 0x8b, 0x86, 0x39, 0x57}}, 50 {0x1c, 0x68, 0xc2, 0xe5, 0x1f, 0x63, 0xc9, 0x5f, 0x17, 0xab, 0x1f, 0x20,
51 {D_STR_W_LEN("Simple string."), 51 0x8b, 0x86, 0x39, 0x57}},
52 {0xf1, 0x2b, 0x7c, 0xad, 0xa0, 0x41, 0xfe, 0xde, 0x4e, 0x68, 0x16, 0x63, 0xb4, 0x60, 0x5d, 0x78}}, 52 {D_STR_W_LEN ("Simple string."),
53 {D_STR_W_LEN("abcdefghijklmnopqrstuvwxyz"), 53 {0xf1, 0x2b, 0x7c, 0xad, 0xa0, 0x41, 0xfe, 0xde, 0x4e, 0x68, 0x16, 0x63,
54 {0xc3, 0xfc, 0xd3, 0xd7, 0x61, 0x92, 0xe4, 0x00, 0x7d, 0xfb, 0x49, 0x6c, 0xca, 0x67, 0xe1, 0x3b}}, 54 0xb4, 0x60, 0x5d, 0x78}},
55 {D_STR_W_LEN("zyxwvutsrqponMLKJIHGFEDCBA"), 55 {D_STR_W_LEN ("abcdefghijklmnopqrstuvwxyz"),
56 {0x05, 0x61, 0x3a, 0x6b, 0xde, 0x75, 0x3a, 0x45, 0x91, 0xa8, 0x81, 0xb0, 0xa7, 0xe2, 0xe2, 0x0e}}, 56 {0xc3, 0xfc, 0xd3, 0xd7, 0x61, 0x92, 0xe4, 0x00, 0x7d, 0xfb, 0x49, 0x6c,
57 {D_STR_W_LEN("abcdefghijklmnopqrstuvwxyzzyxwvutsrqponMLKJIHGFEDCBA" 57 0xca, 0x67, 0xe1, 0x3b}},
58 "abcdefghijklmnopqrstuvwxyzzyxwvutsrqponMLKJIHGFEDCBA"), 58 {D_STR_W_LEN ("zyxwvutsrqponMLKJIHGFEDCBA"),
59 {0xaf, 0xab, 0xc7, 0xe9, 0xe7, 0x17, 0xbe, 0xd6, 0xc0, 0x0f, 0x78, 0x8c, 0xde, 0xdd, 0x11, 0xd1}}, 59 {0x05, 0x61, 0x3a, 0x6b, 0xde, 0x75, 0x3a, 0x45, 0x91, 0xa8, 0x81, 0xb0,
60 0xa7, 0xe2, 0xe2, 0x0e}},
61 {D_STR_W_LEN ("abcdefghijklmnopqrstuvwxyzzyxwvutsrqponMLKJIHGFEDCBA"
62 "abcdefghijklmnopqrstuvwxyzzyxwvutsrqponMLKJIHGFEDCBA"),
63 {0xaf, 0xab, 0xc7, 0xe9, 0xe7, 0x17, 0xbe, 0xd6, 0xc0, 0x0f, 0x78, 0x8c,
64 0xde, 0xdd, 0x11, 0xd1}},
60}; 65};
61 66
62static const size_t units1_num = sizeof(data_units1) / sizeof(data_units1[0]); 67static const size_t units1_num = sizeof(data_units1) / sizeof(data_units1[0]);
@@ -74,85 +79,134 @@ struct data_unit2
74}; 79};
75 80
76static const struct data_unit2 data_units2[] = { 81static const struct data_unit2 data_units2[] = {
77 { { {97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 82 { { {97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
78 117, 118, 119, 120, 121, 122}, 26},/* a..z ASCII sequence */ 83 112, 113, 114, 115, 116,
79 {0xc3, 0xfc, 0xd3, 0xd7, 0x61, 0x92, 0xe4, 0x00, 0x7d, 0xfb, 0x49, 0x6c, 0xca, 0x67, 0xe1, 0x3b} 84 117, 118, 119, 120, 121, 122}, 26}, /* a..z ASCII sequence */
80 }, 85 {0xc3, 0xfc, 0xd3, 0xd7, 0x61, 0x92, 0xe4, 0x00, 0x7d, 0xfb, 0x49, 0x6c,
81 { { {65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 86 0xca, 0x67, 0xe1, 0x3b}},
82 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 87 { { {65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
83 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65 88 65, 65, 65, 65, 65, 65,
84 }, 72 },/* 'A' x 72 times */ 89 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
85 {0x24, 0xa5, 0xef, 0x36, 0x82, 0x80, 0x3a, 0x06, 0x2f, 0xea, 0xad, 0xad, 0x76, 0xda, 0xbd, 0xa8} 90 65, 65, 65, 65, 65, 65,
86 }, 91 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
87 { { {19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 92 65, 65, 65, 65, 65, 65}, 72 },/* 'A' x 72 times */
88 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 93 {0x24, 0xa5, 0xef, 0x36, 0x82, 0x80, 0x3a, 0x06, 0x2f, 0xea, 0xad, 0xad,
89 68, 69, 70, 71, 72, 73}, 55},/* 19..73 sequence */ 94 0x76, 0xda, 0xbd, 0xa8}},
90 {0x6d, 0x2e, 0x6e, 0xde, 0x5d, 0x64, 0x6a, 0x17, 0xf1, 0x09, 0x2c, 0xac, 0x19, 0x10, 0xe3, 0xd6} 95 { { {19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
91 }, 96 37, 38, 39, 40, 41, 42,
92 { { {7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 97 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
93 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 98 61, 62, 63, 64, 65, 66, 67,
94 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69}, 63},/* 7..69 sequence */ 99 68, 69, 70, 71, 72, 73}, 55}, /* 19..73 sequence */
95 {0x88, 0x13, 0x48, 0x47, 0x73, 0xaa, 0x92, 0xf2, 0xc9, 0xdd, 0x69, 0xb3, 0xac, 0xf4, 0xba, 0x6e} 100 {0x6d, 0x2e, 0x6e, 0xde, 0x5d, 0x64, 0x6a, 0x17, 0xf1, 0x09, 0x2c, 0xac,
96 }, 101 0x19, 0x10, 0xe3, 0xd6}},
97 { { {38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 102 { { {7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
98 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 103 26, 27, 28, 29, 30, 31,
99 87, 88, 89, 90, 91, 92}, 55},/* 38..92 sequence */ 104 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
100 {0x80, 0xf0, 0x05, 0x7e, 0xa2, 0xf7, 0xc8, 0x43, 0x12, 0xd3, 0xb1, 0x61, 0xab, 0x52, 0x3b, 0xaf} 105 50, 51, 52, 53, 54, 55, 56,
101 }, 106 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69}, 63}, /* 7..69 sequence */
102 { { {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 107 {0x88, 0x13, 0x48, 0x47, 0x73, 0xaa, 0x92, 0xf2, 0xc9, 0xdd, 0x69, 0xb3,
103 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 108 0xac, 0xf4, 0xba, 0x6e}},
104 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72}, 109 { { {38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
110 56, 57, 58, 59, 60, 61,
111 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
112 80, 81, 82, 83, 84, 85, 86,
113 87, 88, 89, 90, 91, 92}, 55}, /* 38..92 sequence */
114 {0x80, 0xf0, 0x05, 0x7e, 0xa2, 0xf7, 0xc8, 0x43, 0x12, 0xd3, 0xb1, 0x61,
115 0xab, 0x52, 0x3b, 0xaf}},
116 { { {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
117 21, 22, 23, 24, 25, 26, 27,
118 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
119 46, 47, 48, 49, 50, 51, 52,
120 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
121 71, 72},
105 72},/* 1..72 sequence */ 122 72},/* 1..72 sequence */
106 {0xc3, 0x28, 0xc5, 0xad, 0xc9, 0x26, 0xa9, 0x99, 0x95, 0x4a, 0x5e, 0x25, 0x50, 0x34, 0x51, 0x73} 123 {0xc3, 0x28, 0xc5, 0xad, 0xc9, 0x26, 0xa9, 0x99, 0x95, 0x4a, 0x5e, 0x25,
107 }, 124 0x50, 0x34, 0x51, 0x73}},
108 { { {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 125 { { {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
109 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 126 21, 22, 23, 24, 25, 26,
110 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 127 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
111 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 128 45, 46, 47, 48, 49, 50, 51,
112 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 129 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
113 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 130 70, 71, 72, 73, 74, 75, 76,
114 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 131 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
115 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 132 95, 96, 97, 98, 99, 100,
116 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 133 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
117 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 134 115, 116, 117, 118, 119, 120,
118 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 135 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
119 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255}, 256}, /* 0..255 sequence */ 136 135, 136, 137, 138, 139, 140,
120 {0xe2, 0xc8, 0x65, 0xdb, 0x41, 0x62, 0xbe, 0xd9, 0x63, 0xbf, 0xaa, 0x9e, 0xf6, 0xac, 0x18, 0xf0} 137 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154,
121 }, 138 155, 156, 157, 158, 159, 160,
122 { { {199, 198, 197, 196, 195, 194, 193, 192, 191, 190, 189, 188, 187, 186, 185, 184, 183, 182, 181, 180, 139 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174,
123 179, 178, 177, 176, 175, 174, 173, 172, 171, 170, 169, 168, 167, 166, 165, 164, 163, 162, 161, 160, 140 175, 176, 177, 178, 179, 180,
124 159, 158, 157, 156, 155, 154, 153, 152, 151, 150, 149, 148, 147, 146, 145, 144, 143, 142, 141, 140, 141 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194,
125 139}, 61}, /* 199..139 sequence */ 142 195, 196, 197, 198, 199, 200,
126 {0xbb, 0x3f, 0xdb, 0x4a, 0x96, 0x03, 0x36, 0x37, 0x38, 0x78, 0x5e, 0x44, 0xbf, 0x3a, 0x85, 0x51} 143 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214,
127 }, 144 215, 216, 217, 218, 219, 220,
128 { { {255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240, 239, 238, 237, 236, 145 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234,
129 235, 234, 233, 232, 231, 230, 229, 228, 227, 226, 225, 224, 223, 222, 221, 220, 219, 218, 217, 216, 146 235, 236, 237, 238, 239, 240,
130 215, 214, 213, 212, 211, 210, 209, 208, 207, 206, 205, 204, 203, 202, 201, 200, 199, 198, 197, 196, 147 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
131 195, 194, 193, 192, 191, 190, 189, 188, 187, 186, 185, 184, 183, 182, 181, 180, 179, 178, 177, 176, 148 255}, 256}, /* 0..255 sequence */
132 175, 174, 173, 172, 171, 170, 169, 168, 167, 166, 165, 164, 163, 162, 161, 160, 159, 158, 157, 156, 149 {0xe2, 0xc8, 0x65, 0xdb, 0x41, 0x62, 0xbe, 0xd9, 0x63, 0xbf, 0xaa, 0x9e,
133 155, 154, 153, 152, 151, 150, 149, 148, 147, 146, 145, 144, 143, 142, 141, 140, 139, 138, 137, 136, 150 0xf6, 0xac, 0x18, 0xf0}},
134 135, 134, 133, 132, 131, 130, 129, 128, 127, 126, 125, 124, 123, 122, 121, 120, 119, 118, 117, 116, 151 { { {199, 198, 197, 196, 195, 194, 193, 192, 191, 190, 189, 188, 187, 186,
135 115, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 100, 99, 98, 97, 96, 95, 152 185, 184, 183, 182, 181, 180,
136 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 153 179, 178, 177, 176, 175, 174, 173, 172, 171, 170, 169, 168, 167, 166,
137 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 154 165, 164, 163, 162, 161, 160,
138 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 155 159, 158, 157, 156, 155, 154, 153, 152, 151, 150, 149, 148, 147, 146,
139 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, 255}, /* 255..1 sequence */ 156 145, 144, 143, 142, 141, 140,
140 {0x52, 0x21, 0xa5, 0x83, 0x4f, 0x38, 0x7c, 0x73, 0xba, 0x18, 0x22, 0xb1, 0xf9, 0x7e, 0xae, 0x8b} 157 139}, 61}, /* 199..139 sequence */
141 }, 158 {0xbb, 0x3f, 0xdb, 0x4a, 0x96, 0x03, 0x36, 0x37, 0x38, 0x78, 0x5e, 0x44,
142 { { {41, 35, 190, 132, 225, 108, 214, 174, 82, 144, 73, 241, 241, 187, 233, 235, 179, 166, 219, 60, 135, 159 0xbf, 0x3a, 0x85, 0x51}},
143 12, 62, 153, 36, 94, 13, 28, 6, 183, 71, 222, 179, 18, 77, 200, 67, 187, 139, 166, 31, 3, 90, 125, 9, 160 { { {255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242,
144 56, 37, 31, 93, 212, 203, 252, 150, 245, 69, 59, 19, 13, 137, 10, 28, 219, 174, 50, 32, 154, 80, 238, 161 241, 240, 239, 238, 237, 236,
145 64, 120, 54, 253, 18, 73, 50, 246, 158, 125, 73, 220, 173, 79, 20, 242, 68, 64, 102, 208, 107, 196, 162 235, 234, 233, 232, 231, 230, 229, 228, 227, 226, 225, 224, 223, 222,
146 48, 183, 50, 59, 161, 34, 246, 34, 145, 157, 225, 139, 31, 218, 176, 202, 153, 2, 185, 114, 157, 73, 163 221, 220, 219, 218, 217, 216,
147 44, 128, 126, 197, 153, 213, 233, 128, 178, 234, 201, 204, 83, 191, 103, 214, 191, 20, 214, 126, 45, 164 215, 214, 213, 212, 211, 210, 209, 208, 207, 206, 205, 204, 203, 202,
148 220, 142, 102, 131, 239, 87, 73, 97, 255, 105, 143, 97, 205, 209, 30, 157, 156, 22, 114, 114, 230, 165 201, 200, 199, 198, 197, 196,
149 29, 240, 132, 79, 74, 119, 2, 215, 232, 57, 44, 83, 203, 201, 18, 30, 51, 116, 158, 12, 244, 213, 166 195, 194, 193, 192, 191, 190, 189, 188, 187, 186, 185, 184, 183, 182,
150 212, 159, 212, 164, 89, 126, 53, 207, 50, 34, 244, 204, 207, 211, 144, 45, 72, 211, 143, 117, 230, 167 181, 180, 179, 178, 177, 176,
151 217, 29, 42, 229, 192, 247, 43, 120, 129, 135, 68, 14, 95, 80, 0, 212, 97, 141, 190, 123, 5, 21, 7, 168 175, 174, 173, 172, 171, 170, 169, 168, 167, 166, 165, 164, 163, 162,
152 59, 51, 130, 31, 24, 112, 146, 218, 100, 84, 206, 177, 133, 62, 105, 21, 248, 70, 106, 4, 150, 115, 169 161, 160, 159, 158, 157, 156,
153 14, 217, 22, 47, 103, 104, 212, 247, 74, 74, 208, 87, 104}, 255}, /* pseudo-random data */ 170 155, 154, 153, 152, 151, 150, 149, 148, 147, 146, 145, 144, 143, 142,
154 {0x55, 0x61, 0x2c, 0xeb, 0x29, 0xee, 0xa8, 0xb2, 0xf6, 0x10, 0x7b, 0xc1, 0x5b, 0x0f, 0x01, 0x95} 171 141, 140, 139, 138, 137, 136,
155 } 172 135, 134, 133, 132, 131, 130, 129, 128, 127, 126, 125, 124, 123, 122,
173 121, 120, 119, 118, 117, 116,
174 115, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102,
175 101, 100, 99, 98, 97, 96, 95,
176 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77,
177 76, 75, 74, 73, 72, 71, 70,
178 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52,
179 51, 50, 49, 48, 47, 46, 45,
180 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27,
181 26, 25, 24, 23, 22, 21, 20,
182 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, 255}, /* 255..1 sequence */
183 {0x52, 0x21, 0xa5, 0x83, 0x4f, 0x38, 0x7c, 0x73, 0xba, 0x18, 0x22, 0xb1,
184 0xf9, 0x7e, 0xae, 0x8b}},
185 { { {41, 35, 190, 132, 225, 108, 214, 174, 82, 144, 73, 241, 241, 187, 233,
186 235, 179, 166, 219, 60, 135,
187 12, 62, 153, 36, 94, 13, 28, 6, 183, 71, 222, 179, 18, 77, 200, 67, 187,
188 139, 166, 31, 3, 90, 125, 9,
189 56, 37, 31, 93, 212, 203, 252, 150, 245, 69, 59, 19, 13, 137, 10, 28,
190 219, 174, 50, 32, 154, 80, 238,
191 64, 120, 54, 253, 18, 73, 50, 246, 158, 125, 73, 220, 173, 79, 20, 242,
192 68, 64, 102, 208, 107, 196,
193 48, 183, 50, 59, 161, 34, 246, 34, 145, 157, 225, 139, 31, 218, 176, 202,
194 153, 2, 185, 114, 157, 73,
195 44, 128, 126, 197, 153, 213, 233, 128, 178, 234, 201, 204, 83, 191, 103,
196 214, 191, 20, 214, 126, 45,
197 220, 142, 102, 131, 239, 87, 73, 97, 255, 105, 143, 97, 205, 209, 30,
198 157, 156, 22, 114, 114, 230,
199 29, 240, 132, 79, 74, 119, 2, 215, 232, 57, 44, 83, 203, 201, 18, 30, 51,
200 116, 158, 12, 244, 213,
201 212, 159, 212, 164, 89, 126, 53, 207, 50, 34, 244, 204, 207, 211, 144,
202 45, 72, 211, 143, 117, 230,
203 217, 29, 42, 229, 192, 247, 43, 120, 129, 135, 68, 14, 95, 80, 0, 212,
204 97, 141, 190, 123, 5, 21, 7,
205 59, 51, 130, 31, 24, 112, 146, 218, 100, 84, 206, 177, 133, 62, 105, 21,
206 248, 70, 106, 4, 150, 115,
207 14, 217, 22, 47, 103, 104, 212, 247, 74, 74, 208, 87, 104}, 255}, /* pseudo-random data */
208 {0x55, 0x61, 0x2c, 0xeb, 0x29, 0xee, 0xa8, 0xb2, 0xf6, 0x10, 0x7b, 0xc1,
209 0x5b, 0x0f, 0x01, 0x95}}
156}; 210};
157 211
158static const size_t units2_num = sizeof(data_units2) / sizeof(data_units2[0]); 212static const size_t units2_num = sizeof(data_units2) / sizeof(data_units2[0]);
@@ -171,17 +225,17 @@ static const size_t units2_num = sizeof(data_units2) / sizeof(data_units2[0]);
171 */ 225 */
172static void 226static void
173bin2hex (const uint8_t *bin, 227bin2hex (const uint8_t *bin,
174 size_t len, 228 size_t len,
175 char *hex) 229 char *hex)
176{ 230{
177 while (len-- > 0) 231 while (len-- > 0)
178 { 232 {
179 unsigned int b1, b2; 233 unsigned int b1, b2;
180 b1 = (*bin >> 4) & 0xf; 234 b1 = (*bin >> 4) & 0xf;
181 *hex++ = (char)((b1 > 9) ? (b1 + 'A' - 10) : (b1 + '0')); 235 *hex++ = (char) ((b1 > 9) ? (b1 + 'A' - 10) : (b1 + '0'));
182 b2 = *bin++ & 0xf; 236 b2 = *bin++ & 0xf;
183 *hex++ = (char)((b2 > 9) ? (b2 + 'A' - 10) : (b2 + '0')); 237 *hex++ = (char) ((b2 > 9) ? (b2 + 'A' - 10) : (b2 + '0'));
184 } 238 }
185 *hex = 0; 239 *hex = 0;
186} 240}
187 241
@@ -192,26 +246,28 @@ check_result (const char *test_name,
192 const uint8_t calcualted[MD5_DIGEST_SIZE], 246 const uint8_t calcualted[MD5_DIGEST_SIZE],
193 const uint8_t expected[MD5_DIGEST_SIZE]) 247 const uint8_t expected[MD5_DIGEST_SIZE])
194{ 248{
195 int failed = memcmp(calcualted, expected, MD5_DIGEST_SIZE); 249 int failed = memcmp (calcualted, expected, MD5_DIGEST_SIZE);
196 check_num++; /* Print 1-based numbers */ 250 check_num++; /* Print 1-based numbers */
197 if (failed) 251 if (failed)
198 { 252 {
199 char calc_str[MD5_DIGEST_STRING_LENGTH]; 253 char calc_str[MD5_DIGEST_STRING_LENGTH];
200 char expc_str[MD5_DIGEST_STRING_LENGTH]; 254 char expc_str[MD5_DIGEST_STRING_LENGTH];
201 bin2hex(calcualted, MD5_DIGEST_SIZE, calc_str); 255 bin2hex (calcualted, MD5_DIGEST_SIZE, calc_str);
202 bin2hex(expected, MD5_DIGEST_SIZE, expc_str); 256 bin2hex (expected, MD5_DIGEST_SIZE, expc_str);
203 fprintf (stderr, "FAILED: %s check %u: calculated digest %s, expected digest %s.\n", 257 fprintf (stderr,
204 test_name, check_num, calc_str, expc_str); 258 "FAILED: %s check %u: calculated digest %s, expected digest %s.\n",
205 fflush (stderr); 259 test_name, check_num, calc_str, expc_str);
206 } 260 fflush (stderr);
261 }
207 else if (verbose) 262 else if (verbose)
208 { 263 {
209 char calc_str[MD5_DIGEST_STRING_LENGTH]; 264 char calc_str[MD5_DIGEST_STRING_LENGTH];
210 bin2hex(calcualted, MD5_DIGEST_SIZE, calc_str); 265 bin2hex (calcualted, MD5_DIGEST_SIZE, calc_str);
211 printf ("PASSED: %s check %u: calculated digest %s match expected digest.\n", 266 printf (
212 test_name, check_num, calc_str); 267 "PASSED: %s check %u: calculated digest %s match expected digest.\n",
213 fflush (stdout); 268 test_name, check_num, calc_str);
214 } 269 fflush (stdout);
270 }
215 return failed ? 1 : 0; 271 return failed ? 1 : 0;
216} 272}
217 273
@@ -222,106 +278,110 @@ check_result (const char *test_name,
222 278
223/* Calculated MD5 as one pass for whole data */ 279/* Calculated MD5 as one pass for whole data */
224static int 280static int
225test1_str(void) 281test1_str (void)
226{ 282{
227 unsigned int i; 283 unsigned int i;
228 int num_failed = 0; 284 int num_failed = 0;
285
229 for (i = 0; i < units1_num; i++) 286 for (i = 0; i < units1_num; i++)
230 { 287 {
231 struct MD5Context ctx; 288 struct MD5Context ctx;
232 uint8_t digest[MD5_DIGEST_SIZE]; 289 uint8_t digest[MD5_DIGEST_SIZE];
233 290
234 MHD_MD5Init (&ctx); 291 MHD_MD5Init (&ctx);
235 MHD_MD5Update (&ctx, (const uint8_t*)data_units1[i].str_l.str, data_units1[i].str_l.len); 292 MHD_MD5Update (&ctx, (const uint8_t*) data_units1[i].str_l.str,
236 MHD_MD5Final (&ctx, digest); 293 data_units1[i].str_l.len);
237 num_failed += check_result (__FUNCTION__, i, digest, 294 MHD_MD5Final (&ctx, digest);
238 data_units1[i].digest); 295 num_failed += check_result (__FUNCTION__, i, digest,
239 } 296 data_units1[i].digest);
297 }
240 return num_failed; 298 return num_failed;
241} 299}
242 300
243 301
244static int 302static int
245test1_bin(void) 303test1_bin (void)
246{ 304{
247 unsigned int i; 305 unsigned int i;
248 int num_failed = 0; 306 int num_failed = 0;
249 307
250 for (i = 0; i < units2_num; i++) 308 for (i = 0; i < units2_num; i++)
251 { 309 {
252 struct MD5Context ctx; 310 struct MD5Context ctx;
253 uint8_t digest[MD5_DIGEST_SIZE]; 311 uint8_t digest[MD5_DIGEST_SIZE];
254 312
255 MHD_MD5Init (&ctx); 313 MHD_MD5Init (&ctx);
256 MHD_MD5Update (&ctx, data_units2[i].bin_l.bin, data_units2[i].bin_l.len); 314 MHD_MD5Update (&ctx, data_units2[i].bin_l.bin, data_units2[i].bin_l.len);
257 MHD_MD5Final (&ctx, digest); 315 MHD_MD5Final (&ctx, digest);
258 num_failed += check_result (__FUNCTION__, i, digest, 316 num_failed += check_result (__FUNCTION__, i, digest,
259 data_units2[i].digest); 317 data_units2[i].digest);
260 } 318 }
261 return num_failed; 319 return num_failed;
262} 320}
263 321
264 322
265/* Calculated MD5 as two iterations for whole data */ 323/* Calculated MD5 as two iterations for whole data */
266static int 324static int
267test2_str(void) 325test2_str (void)
268{ 326{
269 unsigned int i; 327 unsigned int i;
270 int num_failed = 0; 328 int num_failed = 0;
271 329
272 for (i = 0; i < units1_num; i++) 330 for (i = 0; i < units1_num; i++)
273 { 331 {
274 struct MD5Context ctx; 332 struct MD5Context ctx;
275 uint8_t digest[MD5_DIGEST_SIZE]; 333 uint8_t digest[MD5_DIGEST_SIZE];
276 size_t part_s = data_units1[i].str_l.len / 4; 334 size_t part_s = data_units1[i].str_l.len / 4;
277 335
278 MHD_MD5Init (&ctx); 336 MHD_MD5Init (&ctx);
279 MHD_MD5Update (&ctx, (const uint8_t*)data_units1[i].str_l.str, part_s); 337 MHD_MD5Update (&ctx, (const uint8_t*) data_units1[i].str_l.str, part_s);
280 MHD_MD5Update (&ctx, (const uint8_t*)data_units1[i].str_l.str + part_s, data_units1[i].str_l.len - part_s); 338 MHD_MD5Update (&ctx, (const uint8_t*) data_units1[i].str_l.str + part_s,
281 MHD_MD5Final (&ctx, digest); 339 data_units1[i].str_l.len - part_s);
282 num_failed += check_result (__FUNCTION__, i, digest, 340 MHD_MD5Final (&ctx, digest);
283 data_units1[i].digest); 341 num_failed += check_result (__FUNCTION__, i, digest,
284 } 342 data_units1[i].digest);
343 }
285 return num_failed; 344 return num_failed;
286} 345}
287 346
288 347
289static int 348static int
290test2_bin(void) 349test2_bin (void)
291{ 350{
292 unsigned int i; 351 unsigned int i;
293 int num_failed = 0; 352 int num_failed = 0;
294 353
295 for (i = 0; i < units2_num; i++) 354 for (i = 0; i < units2_num; i++)
296 { 355 {
297 struct MD5Context ctx; 356 struct MD5Context ctx;
298 uint8_t digest[MD5_DIGEST_SIZE]; 357 uint8_t digest[MD5_DIGEST_SIZE];
299 size_t part_s = data_units2[i].bin_l.len * 2 / 3; 358 size_t part_s = data_units2[i].bin_l.len * 2 / 3;
300 359
301 MHD_MD5Init (&ctx); 360 MHD_MD5Init (&ctx);
302 MHD_MD5Update (&ctx, data_units2[i].bin_l.bin, part_s); 361 MHD_MD5Update (&ctx, data_units2[i].bin_l.bin, part_s);
303 MHD_MD5Update (&ctx, data_units2[i].bin_l.bin + part_s, data_units2[i].bin_l.len - part_s); 362 MHD_MD5Update (&ctx, data_units2[i].bin_l.bin + part_s,
304 MHD_MD5Final (&ctx, digest); 363 data_units2[i].bin_l.len - part_s);
305 num_failed += check_result (__FUNCTION__, i, digest, 364 MHD_MD5Final (&ctx, digest);
306 data_units2[i].digest); 365 num_failed += check_result (__FUNCTION__, i, digest,
307 } 366 data_units2[i].digest);
367 }
308 return num_failed; 368 return num_failed;
309} 369}
310 370
311 371
312int 372int
313main(int argc, char * argv[]) 373main (int argc, char *argv[])
314{ 374{
315 int num_failed = 0; 375 int num_failed = 0;
316 (void)has_in_name; /* Mute compiler warning. */ 376 (void) has_in_name; /* Mute compiler warning. */
317 if (has_param(argc, argv, "-v") || has_param(argc, argv, "--verbose")) 377 if (has_param (argc, argv, "-v") || has_param (argc, argv, "--verbose"))
318 verbose = 1; 378 verbose = 1;
319 379
320 num_failed += test1_str(); 380 num_failed += test1_str ();
321 num_failed += test1_bin(); 381 num_failed += test1_bin ();
322 382
323 num_failed += test2_str(); 383 num_failed += test2_str ();
324 num_failed += test2_bin(); 384 num_failed += test2_bin ();
325 385
326 return num_failed ? 1 : 0; 386 return num_failed ? 1 : 0;
327} 387}