nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | #include <glib.h> |
2 | #include <string.h> |
||
3 | #include <stdlib.h> |
||
4 | |||
5 | /* HMAC-MD5 test vectors as per RFC 2202 */ |
||
6 | |||
7 | /* Test 1 */ |
||
8 | guint8 key_md5_test1[] = { |
||
9 | 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, |
||
10 | 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b }; |
||
11 | guint8 result_md5_test1[] = { |
||
12 | 0x92, 0x94, 0x72, 0x7a, 0x36, 0x38, 0xbb, 0x1c, 0x13, 0xf4, |
||
13 | 0x8e, 0xf8, 0x15, 0x8b, 0xfc, 0x9d }; |
||
14 | |||
15 | /* Test 2 */ |
||
16 | guint8 result_md5_test2[] = { |
||
17 | 0x75, 0x0c, 0x78, 0x3e, 0x6a, 0xb0, 0xb5, 0x03, 0xea, 0xa8, |
||
18 | 0x6e, 0x31, 0x0a, 0x5d, 0xb7, 0x38 }; |
||
19 | |||
20 | /* Test 3 */ |
||
21 | guint8 key_md5_test3[] = { |
||
22 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
23 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa }; |
||
24 | guint8 data_md5_test3[] = { |
||
25 | 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, |
||
26 | 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, |
||
27 | 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, |
||
28 | 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, |
||
29 | 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd }; |
||
30 | guint8 result_md5_test3[] = { |
||
31 | 0x56, 0xbe, 0x34, 0x52, 0x1d, 0x14, 0x4c, 0x88, 0xdb, 0xb8, |
||
32 | 0xc7, 0x33, 0xf0, 0xe8, 0xb3, 0xf6 }; |
||
33 | |||
34 | /* Test 4 */ |
||
35 | guint8 key_md5_test4[] = { |
||
36 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, |
||
37 | 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, |
||
38 | 0x15, 0x16, 0x17, 0x18, 0x19 }; |
||
39 | guint8 data_md5_test4[] = { |
||
40 | 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, |
||
41 | 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, |
||
42 | 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, |
||
43 | 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, |
||
44 | 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd }; |
||
45 | guint8 result_md5_test4[] = { |
||
46 | 0x69, 0x7e, 0xaf, 0x0a, 0xca, 0x3a, 0x3a, 0xea, 0x3a, 0x75, |
||
47 | 0x16, 0x47, 0x46, 0xff, 0xaa, 0x79 }; |
||
48 | |||
49 | /* Test 5 */ |
||
50 | guint8 key_md5_test5[] = { |
||
51 | 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, |
||
52 | 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c}; |
||
53 | guint8 result_md5_test5[] = { |
||
54 | 0x56, 0x46, 0x1e, 0xf2, 0x34, 0x2e, 0xdc, 0x00, 0xf9, 0xba, |
||
55 | 0xb9, 0x95, 0x69, 0x0e, 0xfd, 0x4c }; |
||
56 | |||
57 | /* Test 6 */ |
||
58 | guint8 key_md5_test6[] = { |
||
59 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
60 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
61 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
62 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
63 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
64 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
65 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
66 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa }; |
||
67 | guint8 result_md5_test6[] = { |
||
68 | 0x6b, 0x1a, 0xb7, 0xfe, 0x4b, 0xd7, 0xbf, 0x8f, 0x0b, 0x62, |
||
69 | 0xe6, 0xce, 0x61, 0xb9, 0xd0, 0xcd }; |
||
70 | |||
71 | /* Test 6 */ |
||
72 | guint8 key_md5_test7[] = { |
||
73 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
74 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
75 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
76 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
77 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
78 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
79 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
80 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa }; |
||
81 | guint8 result_md5_test7[] = { |
||
82 | 0x6f, 0x63, 0x0f, 0xad, 0x67, 0xcd, 0xa0, 0xee, 0x1f, 0xb1, |
||
83 | 0xf5, 0x62, 0xdb, 0x3a, 0xa5, 0x3e }; |
||
84 | |||
85 | /* HMAC-SHA1, HMAC-SHA256 and HMAC-SHA512 test vectors |
||
86 | * as per RFCs 2202 and 4868. |
||
87 | * |
||
88 | * See: https://tools.ietf.org/html/rfc4868#section-2.7.1 */ |
||
89 | |||
90 | /* Test 1 */ |
||
91 | guint8 key_sha_test1[] = { |
||
92 | 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, |
||
93 | 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b }; |
||
94 | guint8 result_sha1_test1[] = { |
||
95 | 0xb6, 0x17, 0x31, 0x86, 0x55, 0x05, 0x72, 0x64, 0xe2, 0x8b, |
||
96 | 0xc0, 0xb6, 0xfb, 0x37, 0x8c, 0x8e, 0xf1, 0x46, 0xbe, 0x00 }; |
||
97 | guint8 result_sha256_test1[] = { |
||
98 | 0xb0, 0x34, 0x4c, 0x61, 0xd8, 0xdb, 0x38, 0x53, 0x5c, 0xa8, |
||
99 | 0xaf, 0xce, 0xaf, 0x0b, 0xf1, 0x2b, 0x88, 0x1d, 0xc2, 0x00, |
||
100 | 0xc9, 0x83, 0x3d, 0xa7, 0x26, 0xe9, 0x37, 0x6c, 0x2e, 0x32, |
||
101 | 0xcf, 0xf7 }; |
||
102 | guint8 result_sha512_test1[] = { |
||
103 | 0x87, 0xaa, 0x7c, 0xde, 0xa5, 0xef, 0x61, 0x9d, 0x4f, 0xf0, |
||
104 | 0xb4, 0x24, 0x1a, 0x1d, 0x6c, 0xb0, 0x23, 0x79, 0xf4, 0xe2, |
||
105 | 0xce, 0x4e, 0xc2, 0x78, 0x7a, 0xd0, 0xb3, 0x05, 0x45, 0xe1, |
||
106 | 0x7c, 0xde, 0xda, 0xa8, 0x33, 0xb7, 0xd6, 0xb8, 0xa7, 0x02, |
||
107 | 0x03, 0x8b, 0x27, 0x4e, 0xae, 0xa3, 0xf4, 0xe4, 0xbe, 0x9d, |
||
108 | 0x91, 0x4e, 0xeb, 0x61, 0xf1, 0x70, 0x2e, 0x69, 0x6c, 0x20, |
||
109 | 0x3a, 0x12, 0x68, 0x54 }; |
||
110 | |||
111 | /* Test 2 */ |
||
112 | guint8 result_sha1_test2[] = { |
||
113 | 0xef, 0xfc, 0xdf, 0x6a, 0xe5, 0xeb, 0x2f, 0xa2, 0xd2, 0x74, |
||
114 | 0x16, 0xd5, 0xf1, 0x84, 0xdf, 0x9c, 0x25, 0x9a, 0x7c, 0x79 }; |
||
115 | guint8 result_sha256_test2[] = { |
||
116 | 0x5b, 0xdc, 0xc1, 0x46, 0xbf, 0x60, 0x75, 0x4e, 0x6a, 0x04, |
||
117 | 0x24, 0x26, 0x08, 0x95, 0x75, 0xc7, 0x5a, 0x00, 0x3f, 0x08, |
||
118 | 0x9d, 0x27, 0x39, 0x83, 0x9d, 0xec, 0x58, 0xb9, 0x64, 0xec, |
||
119 | 0x38, 0x43 }; |
||
120 | guint8 result_sha512_test2[] = { |
||
121 | 0x16, 0x4b, 0x7a, 0x7b, 0xfc, 0xf8, 0x19, 0xe2, 0xe3, 0x95, |
||
122 | 0xfb, 0xe7, 0x3b, 0x56, 0xe0, 0xa3, 0x87, 0xbd, 0x64, 0x22, |
||
123 | 0x2e, 0x83, 0x1f, 0xd6, 0x10, 0x27, 0x0c, 0xd7, 0xea, 0x25, |
||
124 | 0x05, 0x54, 0x97, 0x58, 0xbf, 0x75, 0xc0, 0x5a, 0x99, 0x4a, |
||
125 | 0x6d, 0x03, 0x4f, 0x65, 0xf8, 0xf0, 0xe6, 0xfd, 0xca, 0xea, |
||
126 | 0xb1, 0xa3, 0x4d, 0x4a, 0x6b, 0x4b, 0x63, 0x6e, 0x07, 0x0a, |
||
127 | 0x38, 0xbc, 0xe7, 0x37 }; |
||
128 | |||
129 | /* Test 3 */ |
||
130 | guint8 key_sha_test3[] = { |
||
131 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
132 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa }; |
||
133 | guint8 data_sha_test3[] = { |
||
134 | 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, |
||
135 | 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, |
||
136 | 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, |
||
137 | 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, |
||
138 | 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd }; |
||
139 | guint8 result_sha1_test3[] = { |
||
140 | 0x12, 0x5d, 0x73, 0x42, 0xb9, 0xac, 0x11, 0xcd, 0x91, 0xa3, |
||
141 | 0x9a, 0xf4, 0x8a, 0xa1, 0x7b, 0x4f, 0x63, 0xf1, 0x75, 0xd3 }; |
||
142 | guint8 result_sha256_test3[] = { |
||
143 | 0x77, 0x3e, 0xa9, 0x1e, 0x36, 0x80, 0x0e, 0x46, 0x85, 0x4d, |
||
144 | 0xb8, 0xeb, 0xd0, 0x91, 0x81, 0xa7, 0x29, 0x59, 0x09, 0x8b, |
||
145 | 0x3e, 0xf8, 0xc1, 0x22, 0xd9, 0x63, 0x55, 0x14, 0xce, 0xd5, |
||
146 | 0x65, 0xfe }; |
||
147 | guint8 result_sha512_test3[] = { |
||
148 | 0xfa, 0x73, 0xb0, 0x08, 0x9d, 0x56, 0xa2, 0x84, 0xef, 0xb0, |
||
149 | 0xf0, 0x75, 0x6c, 0x89, 0x0b, 0xe9, 0xb1, 0xb5, 0xdb, 0xdd, |
||
150 | 0x8e, 0xe8, 0x1a, 0x36, 0x55, 0xf8, 0x3e, 0x33, 0xb2, 0x27, |
||
151 | 0x9d, 0x39, 0xbf, 0x3e, 0x84, 0x82, 0x79, 0xa7, 0x22, 0xc8, |
||
152 | 0x06, 0xb4, 0x85, 0xa4, 0x7e, 0x67, 0xc8, 0x07, 0xb9, 0x46, |
||
153 | 0xa3, 0x37, 0xbe, 0xe8, 0x94, 0x26, 0x74, 0x27, 0x88, 0x59, |
||
154 | 0xe1, 0x32, 0x92, 0xfb }; |
||
155 | |||
156 | /* Test 4 */ |
||
157 | guint8 key_sha_test4[] = { |
||
158 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, |
||
159 | 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, |
||
160 | 0x15, 0x16, 0x17, 0x18, 0x19 }; |
||
161 | guint8 data_sha_test4[] = { |
||
162 | 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, |
||
163 | 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, |
||
164 | 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, |
||
165 | 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, |
||
166 | 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd }; |
||
167 | guint8 result_sha1_test4[] = { |
||
168 | 0x4c, 0x90, 0x07, 0xf4, 0x02, 0x62, 0x50, 0xc6, 0xbc, 0x84, |
||
169 | 0x14, 0xf9, 0xbf, 0x50, 0xc8, 0x6c, 0x2d, 0x72, 0x35, 0xda }; |
||
170 | guint8 result_sha256_test4[] = { |
||
171 | 0x82, 0x55, 0x8a, 0x38, 0x9a, 0x44, 0x3c, 0x0e, 0xa4, 0xcc, |
||
172 | 0x81, 0x98, 0x99, 0xf2, 0x08, 0x3a, 0x85, 0xf0, 0xfa, 0xa3, |
||
173 | 0xe5, 0x78, 0xf8, 0x07, 0x7a, 0x2e, 0x3f, 0xf4, 0x67, 0x29, |
||
174 | 0x66, 0x5b }; |
||
175 | guint8 result_sha512_test4[] = { |
||
176 | 0xb0, 0xba, 0x46, 0x56, 0x37, 0x45, 0x8c, 0x69, 0x90, 0xe5, |
||
177 | 0xa8, 0xc5, 0xf6, 0x1d, 0x4a, 0xf7, 0xe5, 0x76, 0xd9, 0x7f, |
||
178 | 0xf9, 0x4b, 0x87, 0x2d, 0xe7, 0x6f, 0x80, 0x50, 0x36, 0x1e, |
||
179 | 0xe3, 0xdb, 0xa9, 0x1c, 0xa5, 0xc1, 0x1a, 0xa2, 0x5e, 0xb4, |
||
180 | 0xd6, 0x79, 0x27, 0x5c, 0xc5, 0x78, 0x80, 0x63, 0xa5, 0xf1, |
||
181 | 0x97, 0x41, 0x12, 0x0c, 0x4f, 0x2d, 0xe2, 0xad, 0xeb, 0xeb, |
||
182 | 0x10, 0xa2, 0x98, 0xdd }; |
||
183 | |||
184 | /* Test 5 (note: different for SHA-256/SHA-512) */ |
||
185 | guint8 key_sha1_test5[] = { |
||
186 | 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, |
||
187 | 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c }; |
||
188 | guint8 result_sha1_test5[] = { |
||
189 | 0x4c, 0x1a, 0x03, 0x42, 0x4b, 0x55, 0xe0, 0x7f, 0xe7, 0xf2, |
||
190 | 0x7b, 0xe1, 0xd5, 0x8b, 0xb9, 0x32, 0x4a, 0x9a, 0x5a, 0x04 }; |
||
191 | |||
192 | /* Test 6 & 7 (note: different for SHA-1 and SHA-256/SHA-512) */ |
||
193 | guint8 key_sha1_test6_7[] = { |
||
194 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
195 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
196 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
197 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
198 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
199 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
200 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
201 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa }; |
||
202 | |||
203 | guint8 result_sha1_test6[] = { |
||
204 | 0xaa, 0x4a, 0xe5, 0xe1, 0x52, 0x72, 0xd0, 0x0e, 0x95, 0x70, |
||
205 | 0x56, 0x37, 0xce, 0x8a, 0x3b, 0x55, 0xed, 0x40, 0x21, 0x12 }; |
||
206 | |||
207 | guint8 result_sha1_test7[] = { |
||
208 | 0xe8, 0xe9, 0x9d, 0xf, 0x45, 0x23, 0x7d, 0x78, 0x6d, 0x6b, |
||
209 | 0xba, 0xa7, 0x96, 0x5c, 0x78, 0x8, 0xbb, 0xff, 0x1a, 0x91 }; |
||
210 | |||
211 | /* Test 5 & 6 for SHA-256 and SHA-512. */ |
||
212 | guint8 key_sha256_test5_6[] = { |
||
213 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
214 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
215 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
216 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
217 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
218 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
219 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
220 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
221 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
222 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
223 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
224 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
225 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||
226 | 0xaa }; |
||
227 | |||
228 | guint8 result_sha256_test5[] = { |
||
229 | 0x60, 0xe4, 0x31, 0x59, 0x1e, 0xe0, 0xb6, 0x7f, 0x0d, 0x8a, |
||
230 | 0x26, 0xaa, 0xcb, 0xf5, 0xb7, 0x7f, 0x8e, 0x0b, 0xc6, 0x21, |
||
231 | 0x37, 0x28, 0xc5, 0x14, 0x05, 0x46, 0x04, 0x0f, 0x0e, 0xe3, |
||
232 | 0x7f, 0x54 }; |
||
233 | guint8 result_sha512_test5[] = { |
||
234 | 0x80, 0xb2, 0x42, 0x63, 0xc7, 0xc1, 0xa3, 0xeb, 0xb7, 0x14, |
||
235 | 0x93, 0xc1, 0xdd, 0x7b, 0xe8, 0xb4, 0x9b, 0x46, 0xd1, 0xf4, |
||
236 | 0x1b, 0x4a, 0xee, 0xc1, 0x12, 0x1b, 0x01, 0x37, 0x83, 0xf8, |
||
237 | 0xf3, 0x52, 0x6b, 0x56, 0xd0, 0x37, 0xe0, 0x5f, 0x25, 0x98, |
||
238 | 0xbd, 0x0f, 0xd2, 0x21, 0x5d, 0x6a, 0x1e, 0x52, 0x95, 0xe6, |
||
239 | 0x4f, 0x73, 0xf6, 0x3f, 0x0a, 0xec, 0x8b, 0x91, 0x5a, 0x98, |
||
240 | 0x5d, 0x78, 0x65, 0x98 }; |
||
241 | |||
242 | guint8 result_sha256_test6[] = { |
||
243 | 0x9b, 0x09, 0xff, 0xa7, 0x1b, 0x94, 0x2f, 0xcb, 0x27, 0x63, |
||
244 | 0x5f, 0xbc, 0xd5, 0xb0, 0xe9, 0x44, 0xbf, 0xdc, 0x63, 0x64, |
||
245 | 0x4f, 0x07, 0x13, 0x93, 0x8a, 0x7f, 0x51, 0x53, 0x5c, 0x3a, |
||
246 | 0x35, 0xe2 }; |
||
247 | guint8 result_sha512_test6[] = { |
||
248 | 0xe3, 0x7b, 0x6a, 0x77, 0x5d, 0xc8, 0x7d, 0xba, 0xa4, 0xdf, |
||
249 | 0xa9, 0xf9, 0x6e, 0x5e, 0x3f, 0xfd, 0xde, 0xbd, 0x71, 0xf8, |
||
250 | 0x86, 0x72, 0x89, 0x86, 0x5d, 0xf5, 0xa3, 0x2d, 0x20, 0xcd, |
||
251 | 0xc9, 0x44, 0xb6, 0x02, 0x2c, 0xac, 0x3c, 0x49, 0x82, 0xb1, |
||
252 | 0x0d, 0x5e, 0xeb, 0x55, 0xc3, 0xe4, 0xde, 0x15, 0x13, 0x46, |
||
253 | 0x76, 0xfb, 0x6d, 0xe0, 0x44, 0x60, 0x65, 0xc9, 0x74, 0x40, |
||
254 | 0xfa, 0x8c, 0x6a, 0x58 }; |
||
255 | |||
256 | |||
257 | typedef struct { |
||
258 | GChecksumType digest_type; |
||
259 | gconstpointer key; |
||
260 | gsize key_len; |
||
261 | gconstpointer data; |
||
262 | gsize data_len; |
||
263 | gconstpointer result; |
||
264 | } HmacCase; |
||
265 | |||
266 | HmacCase hmac_md5_tests[] = { |
||
267 | { G_CHECKSUM_MD5, key_md5_test1, 16, "Hi There", 8, result_md5_test1 }, |
||
268 | { G_CHECKSUM_MD5, "Jefe", 4, "what do ya want for nothing?", 28, |
||
269 | result_md5_test2 }, |
||
270 | { G_CHECKSUM_MD5, key_md5_test3, 16, data_md5_test3, 50, |
||
271 | result_md5_test3 }, |
||
272 | { G_CHECKSUM_MD5, key_md5_test4, 25, data_md5_test4, 50, |
||
273 | result_md5_test4 }, |
||
274 | { G_CHECKSUM_MD5, key_md5_test5, 16, "Test With Truncation", 20, |
||
275 | result_md5_test5 }, |
||
276 | { G_CHECKSUM_MD5, key_md5_test6, 80, |
||
277 | "Test Using Larger Than Block-Size Key - Hash Key First", 54, |
||
278 | result_md5_test6 }, |
||
279 | { G_CHECKSUM_MD5, key_md5_test7, 80, |
||
280 | "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", |
||
281 | 73, result_md5_test7 }, |
||
282 | { -1, NULL, 0, NULL, 0, NULL }, |
||
283 | }; |
||
284 | |||
285 | HmacCase hmac_sha1_tests[] = { |
||
286 | { G_CHECKSUM_SHA1, key_sha_test1, 20, "Hi There", 8, result_sha1_test1 }, |
||
287 | { G_CHECKSUM_SHA1, "Jefe", 4, "what do ya want for nothing?", 28, |
||
288 | result_sha1_test2 }, |
||
289 | { G_CHECKSUM_SHA1, key_sha_test3, 20, data_sha_test3, 50, |
||
290 | result_sha1_test3 }, |
||
291 | { G_CHECKSUM_SHA1, key_sha_test4, 25, data_sha_test4, 50, |
||
292 | result_sha1_test4 }, |
||
293 | { G_CHECKSUM_SHA1, key_sha1_test5, 20, "Test With Truncation", 20, |
||
294 | result_sha1_test5 }, |
||
295 | { G_CHECKSUM_SHA1, key_sha1_test6_7, 80, |
||
296 | "Test Using Larger Than Block-Size Key - Hash Key First", 54, |
||
297 | result_sha1_test6 }, |
||
298 | { G_CHECKSUM_SHA1, key_sha1_test6_7, 80, |
||
299 | "Test Using Larger Than Block-Size Key and Larger" \ |
||
300 | " Than One Block-Size Data", 73, result_sha1_test7, }, |
||
301 | { -1, NULL, 0, NULL, 0, NULL }, |
||
302 | }; |
||
303 | |||
304 | HmacCase hmac_sha256_tests[] = { |
||
305 | { G_CHECKSUM_SHA256, key_sha_test1, 20, "Hi There", 8, result_sha256_test1 }, |
||
306 | { G_CHECKSUM_SHA256, "Jefe", 4, "what do ya want for nothing?", 28, |
||
307 | result_sha256_test2 }, |
||
308 | { G_CHECKSUM_SHA256, key_sha_test3, 20, data_sha_test3, 50, |
||
309 | result_sha256_test3 }, |
||
310 | { G_CHECKSUM_SHA256, key_sha_test4, 25, data_sha_test4, 50, |
||
311 | result_sha256_test4 }, |
||
312 | { G_CHECKSUM_SHA256, key_sha256_test5_6, 131, |
||
313 | "Test Using Larger Than Block-Size Key - Hash Key First", 54, |
||
314 | result_sha256_test5 }, |
||
315 | { G_CHECKSUM_SHA256, key_sha256_test5_6, 131, |
||
316 | "This is a test using a larger than block-size key and a larger than " |
||
317 | "block-size data. The key needs to be hashed before being used by the " |
||
318 | "HMAC algorithm.", 152, result_sha256_test6, }, |
||
319 | { -1, NULL, 0, NULL, 0, NULL }, |
||
320 | }; |
||
321 | |||
322 | HmacCase hmac_sha512_tests[] = { |
||
323 | { G_CHECKSUM_SHA512, key_sha_test1, 20, "Hi There", 8, result_sha512_test1 }, |
||
324 | { G_CHECKSUM_SHA512, "Jefe", 4, "what do ya want for nothing?", 28, |
||
325 | result_sha512_test2 }, |
||
326 | { G_CHECKSUM_SHA512, key_sha_test3, 20, data_sha_test3, 50, |
||
327 | result_sha512_test3 }, |
||
328 | { G_CHECKSUM_SHA512, key_sha_test4, 25, data_sha_test4, 50, |
||
329 | result_sha512_test4 }, |
||
330 | { G_CHECKSUM_SHA512, key_sha256_test5_6, 131, |
||
331 | "Test Using Larger Than Block-Size Key - Hash Key First", 54, |
||
332 | result_sha512_test5 }, |
||
333 | { G_CHECKSUM_SHA512, key_sha256_test5_6, 131, |
||
334 | "This is a test using a larger than block-size key and a larger than " |
||
335 | "block-size data. The key needs to be hashed before being used by the " |
||
336 | "HMAC algorithm.", 152, result_sha512_test6, }, |
||
337 | { -1, NULL, 0, NULL, 0, NULL }, |
||
338 | }; |
||
339 | |||
340 | |||
341 | static void |
||
342 | test_hmac (HmacCase *t) |
||
343 | { |
||
344 | GHmac *hmac; |
||
345 | gsize digest_len, hmac_len; |
||
346 | gpointer digest; |
||
347 | |||
348 | hmac_len = digest_len = g_checksum_type_get_length (t->digest_type); |
||
349 | digest = g_malloc (hmac_len); |
||
350 | |||
351 | hmac = g_hmac_new (t->digest_type, t->key, t->key_len); |
||
352 | g_hmac_update (hmac, t->data, t->data_len); |
||
353 | g_hmac_get_digest (hmac, digest, &digest_len); |
||
354 | |||
355 | g_assert_cmpmem (digest, hmac_len, t->result, digest_len); |
||
356 | |||
357 | g_free (digest); |
||
358 | g_hmac_unref (hmac); |
||
359 | } |
||
360 | |||
361 | static void |
||
362 | test_hmac_ref_unref (void) |
||
363 | { |
||
364 | GHmac *hmac, *check; |
||
365 | |||
366 | hmac = g_hmac_new (G_CHECKSUM_SHA1, (guchar*)"aaa", 3); |
||
367 | check = g_hmac_ref (hmac); |
||
368 | g_assert (check == hmac); |
||
369 | g_hmac_unref (check); |
||
370 | g_hmac_unref (hmac); |
||
371 | } |
||
372 | |||
373 | static void |
||
374 | test_hmac_copy (void) |
||
375 | { |
||
376 | GHmac *hmac, *check; |
||
377 | |||
378 | hmac = g_hmac_new (G_CHECKSUM_SHA256, (guchar*)"aaa", 3); |
||
379 | check = g_hmac_copy (hmac); |
||
380 | g_assert (check != hmac); |
||
381 | g_assert_cmpstr (g_hmac_get_string (hmac), ==, g_hmac_get_string (check)); |
||
382 | g_hmac_unref (check); |
||
383 | g_hmac_unref (hmac); |
||
384 | } |
||
385 | |||
386 | static void |
||
387 | test_hmac_for_data (void) |
||
388 | { |
||
389 | gchar *string; |
||
390 | GHmac *hmac; |
||
391 | |||
392 | string = g_compute_hmac_for_data (G_CHECKSUM_SHA1, |
||
393 | (guchar*)"aaa", 3, |
||
394 | (guchar*)"bcdef", 5); |
||
395 | |||
396 | hmac = g_hmac_new (G_CHECKSUM_SHA1, (guchar*)"aaa", 3); |
||
397 | g_hmac_update (hmac, (guchar*)"bcdef", 5); |
||
398 | g_assert_cmpstr (string, ==, g_hmac_get_string (hmac)); |
||
399 | g_hmac_unref (hmac); |
||
400 | g_free (string); |
||
401 | } |
||
402 | |||
403 | static void |
||
404 | test_hmac_for_string (void) |
||
405 | { |
||
406 | gchar *string; |
||
407 | GHmac *hmac; |
||
408 | |||
409 | string = g_compute_hmac_for_string (G_CHECKSUM_SHA1, |
||
410 | (guchar*)"aaa", 3, |
||
411 | "bcdef", -1); |
||
412 | |||
413 | hmac = g_hmac_new (G_CHECKSUM_SHA1, (guchar*)"aaa", 3); |
||
414 | g_hmac_update (hmac, (guchar*)"bcdef", 5); |
||
415 | g_assert_cmpstr (string, ==, g_hmac_get_string (hmac)); |
||
416 | g_hmac_unref (hmac); |
||
417 | g_free (string); |
||
418 | } |
||
419 | |||
420 | int |
||
421 | main (int argc, |
||
422 | char **argv) |
||
423 | { |
||
424 | int i; |
||
425 | g_test_init (&argc, &argv, NULL); |
||
426 | |||
427 | for (i = 0 ; hmac_sha1_tests[i].key_len > 0 ; i++) |
||
428 | { |
||
429 | gchar *name = g_strdup_printf ("/hmac/sha1-%d", i + 1); |
||
430 | g_test_add_data_func (name, hmac_sha1_tests + i, |
||
431 | (void (*)(const void *)) test_hmac); |
||
432 | g_free (name); |
||
433 | } |
||
434 | |||
435 | for (i = 0 ; hmac_sha256_tests[i].key_len > 0 ; i++) |
||
436 | { |
||
437 | gchar *name = g_strdup_printf ("/hmac/sha256-%d", i + 1); |
||
438 | g_test_add_data_func (name, hmac_sha256_tests + i, |
||
439 | (void (*)(const void *)) test_hmac); |
||
440 | g_free (name); |
||
441 | } |
||
442 | |||
443 | for (i = 0 ; hmac_sha512_tests[i].key_len > 0 ; i++) |
||
444 | { |
||
445 | gchar *name = g_strdup_printf ("/hmac/sha512-%d", i + 1); |
||
446 | g_test_add_data_func (name, hmac_sha512_tests + i, |
||
447 | (void (*)(const void *)) test_hmac); |
||
448 | g_free (name); |
||
449 | } |
||
450 | |||
451 | for (i = 0 ; hmac_md5_tests[i].key_len > 0 ; i++) |
||
452 | { |
||
453 | gchar *name = g_strdup_printf ("/hmac/md5-%d", i + 1); |
||
454 | g_test_add_data_func (name, hmac_md5_tests + i, |
||
455 | (void (*)(const void *)) test_hmac); |
||
456 | g_free (name); |
||
457 | } |
||
458 | |||
459 | g_test_add_func ("/hmac/ref-unref", test_hmac_ref_unref); |
||
460 | g_test_add_func ("/hmac/copy", test_hmac_copy); |
||
461 | g_test_add_func ("/hmac/for-data", test_hmac_for_data); |
||
462 | g_test_add_func ("/hmac/for-string", test_hmac_for_string); |
||
463 | |||
464 | return g_test_run (); |
||
465 | } |