Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / nettle / testsuite / serpent-test.c
blob9f40c3fc1ba36d65719c5643296b8b5bb4b2897e
1 #include "testutils.h"
2 #include "serpent.h"
4 static const struct tstring *
5 tstring_hex_reverse (const char *hex)
7 struct tstring *s = tstring_hex (hex);
8 uint8_t *p;
9 unsigned length, i;
11 length = s->length;
12 p = s->data;
14 for (i = 0; i < (length+1)/2; i++)
16 uint8_t t = p[i];
17 p[i] = p[length - 1 - i];
18 p[length - 1 - i] = t;
20 return s;
23 #define RHEX(x) tstring_hex_reverse(x)
25 void
26 test_main(void)
28 /* From libgcrypt */
29 test_cipher(&nettle_serpent128,
30 SHEX("0000000000000000 0000000000000000"),
31 SHEX("D29D576FCEA3A3A7 ED9099F29273D78E"),
32 SHEX("B2288B968AE8B086 48D1CE9606FD992D"));
33 test_cipher(&nettle_serpent192,
34 SHEX("0000000000000000 0000000000000000 0000000000000000"),
35 SHEX("D29D576FCEABA3A7 ED9899F2927BD78E"),
36 SHEX("130E353E1037C224 05E8FAEFB2C3C3E9"));
37 test_cipher(&nettle_serpent256,
38 SHEX("0000000000000000 0000000000000000"
39 "0000000000000000 0000000000000000"),
40 SHEX("D095576FCEA3E3A7 ED98D9F29073D78E"),
41 SHEX("B90EE5862DE69168 F2BDD5125B45472B"));
42 test_cipher(&nettle_serpent256,
43 SHEX("0000000000000000 0000000000000000"
44 "0000000000000000 0000000000000000"),
45 SHEX("0000000001000000 0200000003000000"),
46 SHEX("2061A42782BD52EC 691EC383B03BA77C"));
48 /* The first test for each key size from the ecb_vk.txt and ecb_vt.txt
49 * files in the serpent package. */
51 /* NOTE: These vectors uses strange byte-reversed order of inputs
52 and outputs. */
53 /* 128 bit key */
55 /* vk, 1 */
56 test_cipher(&nettle_serpent128,
57 RHEX("8000000000000000 0000000000000000"),
58 RHEX("0000000000000000 0000000000000000"),
59 RHEX("49AFBFAD9D5A3405 2CD8FFA5986BD2DD"));
61 /* vt, 1 */
62 test_cipher(&nettle_serpent128,
63 RHEX("0000000000000000 0000000000000000"),
64 RHEX("8000000000000000 0000000000000000"),
65 RHEX("10B5FFB720B8CB90 02A1142B0BA2E94A"));
67 /* 192 bit key */
69 /* vk, 1 */
70 test_cipher(&nettle_serpent192,
71 RHEX("8000000000000000 0000000000000000"
72 "0000000000000000"),
73 RHEX("0000000000000000 0000000000000000"),
74 RHEX("E78E5402C7195568 AC3678F7A3F60C66"));
76 /* vt, 1 */
77 test_cipher(&nettle_serpent192,
78 RHEX("0000000000000000 0000000000000000"
79 "0000000000000000"),
80 RHEX("8000000000000000 0000000000000000"),
81 RHEX("B10B271BA25257E1 294F2B51F076D0D9"));
83 /* 256 bit key */
85 /* vk, 1 */
86 test_cipher(&nettle_serpent256,
87 RHEX("8000000000000000 0000000000000000"
88 "0000000000000000 0000000000000000"),
89 RHEX("0000000000000000 0000000000000000"),
90 RHEX("ABED96E766BF28CB C0EBD21A82EF0819"));
92 /* vt, 1 */
93 test_cipher(&nettle_serpent256,
94 RHEX("0000000000000000 0000000000000000"
95 "0000000000000000 0000000000000000"),
96 RHEX("8000000000000000 0000000000000000"),
97 RHEX("DA5A7992B1B4AE6F 8C004BC8A7DE5520"));
99 /* Test vectors from
100 http://www.cs.technion.ac.il/~biham/Reports/Serpent/ */
102 /* serpent128 */
103 /* Set 4, vector# 0 */
104 test_cipher(&nettle_serpent128,
105 SHEX("000102030405060708090A0B0C0D0E0F"),
106 SHEX("00112233445566778899AABBCCDDEEFF"),
107 SHEX("563E2CF8740A27C164804560391E9B27"));
109 /* Set 4, vector# 1 */
110 test_cipher(&nettle_serpent128,
111 SHEX("2BD6459F82C5B300952C49104881FF48"),
112 SHEX("EA024714AD5C4D84EA024714AD5C4D84"),
113 SHEX("92D7F8EF2C36C53409F275902F06539F"));
115 /* serpent192 */
116 /* Set 4, vector# 0 */
117 test_cipher(&nettle_serpent192,
118 SHEX("000102030405060708090A0B0C0D0E0F1011121314151617"),
119 SHEX("00112233445566778899AABBCCDDEEFF"),
120 SHEX("6AB816C82DE53B93005008AFA2246A02"));
122 /* Set 4, vector# 1 */
123 test_cipher(&nettle_serpent192,
124 SHEX("2BD6459F82C5B300952C49104881FF482BD6459F82C5B300"),
125 SHEX("EA024714AD5C4D84EA024714AD5C4D84"),
126 SHEX("827B18C2678A239DFC5512842000E204"));
128 /* serpent256 */
129 /* Set 4, vector# 0 */
130 test_cipher(&nettle_serpent256,
131 SHEX("000102030405060708090A0B0C0D0E0F"
132 "101112131415161718191A1B1C1D1E1F"),
133 SHEX("00112233445566778899AABBCCDDEEFF"),
134 SHEX("2868B7A2D28ECD5E4FDEFAC3C4330074"));
136 /* Set 4, vector# 1 */
137 test_cipher(&nettle_serpent256,
138 SHEX("2BD6459F82C5B300952C49104881FF48"
139 "2BD6459F82C5B300952C49104881FF48"),
140 SHEX("EA024714AD5C4D84EA024714AD5C4D84"),
141 SHEX("3E507730776B93FDEA661235E1DD99F0"));
143 /* Test key padding. We use nettle_serpent256, which actually works
144 also with key sizes smaller than 32 bytes. */
145 test_cipher(&nettle_serpent256,
146 SHEX("00112233440100000000000000000000"
147 "00000000000000000000000000000000"),
148 SHEX("0000000001000000 0200000003000000"),
149 SHEX("C1415AC653FD7C7F D917482EE8EBFE25"));
151 /* Currrently, key sizes smaller than SERPENT_MIN_KEY_SIZE bytes
152 (128 bits) are not supported. */
153 test_cipher(&nettle_serpent256,
154 SHEX("0011223344"),
155 SHEX("0000000001000000 0200000003000000"),
156 SHEX("C1415AC653FD7C7F D917482EE8EBFE25"));
158 test_cipher(&nettle_serpent256,
159 SHEX("00112233445566778899aabbccddeeff"
160 "00010000000000000000000000000000"),
161 SHEX("0000000001000000 0200000003000000"),
162 SHEX("8EB9C958EAFFDF42 009755D7B6458838"));
164 test_cipher(&nettle_serpent256,
165 SHEX("00112233445566778899aabbccddeeff"
166 "00"),
167 SHEX("0000000001000000 0200000003000000"),
168 SHEX("8EB9C958EAFFDF42 009755D7B6458838"));
170 test_cipher(&nettle_serpent256,
171 SHEX("00112233445566778899aabbccddeeff"
172 "00112201000000000000000000000000"),
173 SHEX("0000000001000000 0200000003000000"),
174 SHEX("C8A078D8212AC96D 9060E30EC5CBB5C7"));
176 test_cipher(&nettle_serpent256,
177 SHEX("00112233445566778899aabbccddeeff"
178 "001122"),
179 SHEX("0000000001000000 0200000003000000"),
180 SHEX("C8A078D8212AC96D 9060E30EC5CBB5C7"));
182 /* Test with multiple blocks. */
183 test_cipher(&nettle_serpent128,
184 SHEX("e87450aa0fd87293fd0371483a459bd2"),
185 SHEX("a78a7a8d392f629d bd13674c8dce6fa2"),
186 SHEX("b3d488986c80dea7 c5ebdab4907871c9"));
188 test_cipher(&nettle_serpent128,
189 SHEX("e87450aa0fd87293fd0371483a459bd2"),
190 SHEX("a78a7a8d392f629d bd13674c8dce6fa2"
191 "930c74dec02a11d8 c80d90b5e5c887a7"),
192 SHEX("b3d488986c80dea7 c5ebdab4907871c9"
193 "a4b92b13b79afb37 5518b01bfd706a37"));
195 test_cipher(&nettle_serpent128,
196 SHEX("e87450aa0fd87293fd0371483a459bd2"),
197 SHEX("a78a7a8d392f629d bd13674c8dce6fa2"
198 "930c74dec02a11d8 c80d90b5e5c887a7"
199 "83c92a921b5b2028 d9cb313a5f07ab09"),
200 SHEX("b3d488986c80dea7 c5ebdab4907871c9"
201 "a4b92b13b79afb37 5518b01bfd706a37"
202 "8e44c2d463df4531 165461699edbad03"));
204 test_cipher(&nettle_serpent128,
205 SHEX("91c8e949e12f0e38 7b2473238a3df1b6"),
206 SHEX("00000000 00000001 00000002 00000003"
207 "00000004 00000005 00000006 00000007"
208 "00000008 00000009 0000000a 0000000b"
209 "0000000c 0000000d 0000000e 0000000f"),
210 SHEX("2db9f0a39d4f31a4 b1a83cd1032fe1bd"
211 "3606caa84a220b1b f6f43ff80a831203"
212 "8c6c8d2793dc10b3 904d30e194f086a6"
213 "b2f3e932b9b3f8d1 d4d074f7bd1ff7a3"));
215 test_cipher(&nettle_serpent128,
216 SHEX("e87450aa0fd87293fd0371483a459bd2"),
217 SHEX("a78a7a8d392f629d bd13674c8dce6fa2"
218 "930c74dec02a11d8 c80d90b5e5c887a7"
219 "83c92a921b5b2028 d9cb313a5f07ab09"
220 "672eadf1624a2ed0 c42d1b08b076f75a"),
221 SHEX("b3d488986c80dea7 c5ebdab4907871c9"
222 "a4b92b13b79afb37 5518b01bfd706a37"
223 "8e44c2d463df4531 165461699edbad03"
224 "30ac8c52697102ae 3b725dba79ceb250"));
226 test_cipher(&nettle_serpent128,
227 SHEX("e87450aa0fd87293fd0371483a459bd2"),
228 SHEX("a78a7a8d392f629d bd13674c8dce6fa2"
229 "930c74dec02a11d8 c80d90b5e5c887a7"
230 "83c92a921b5b2028 d9cb313a5f07ab09"
231 "672eadf1624a2ed0 c42d1b08b076f75a"
232 "7378272aa57ad7c8 803e326689541266"),
233 SHEX("b3d488986c80dea7 c5ebdab4907871c9"
234 "a4b92b13b79afb37 5518b01bfd706a37"
235 "8e44c2d463df4531 165461699edbad03"
236 "30ac8c52697102ae 3b725dba79ceb250"
237 "d308b83478e86dbb 629f18736cca042f"));
239 test_cipher(&nettle_serpent128,
240 SHEX("e87450aa0fd87293fd0371483a459bd2"),
241 SHEX("a78a7a8d392f629d bd13674c8dce6fa2"
242 "930c74dec02a11d8 c80d90b5e5c887a7"
243 "83c92a921b5b2028 d9cb313a5f07ab09"
244 "672eadf1624a2ed0 c42d1b08b076f75a"
245 "7378272aa57ad7c8 803e326689541266"
246 "b7a2efda5721776f 4113d63a702ac3ae"),
247 SHEX("b3d488986c80dea7 c5ebdab4907871c9"
248 "a4b92b13b79afb37 5518b01bfd706a37"
249 "8e44c2d463df4531 165461699edbad03"
250 "30ac8c52697102ae 3b725dba79ceb250"
251 "d308b83478e86dbb 629f18736cca042f"
252 "006b89e494469adf 0ee78c60684dff86"));
254 test_cipher(&nettle_serpent128,
255 SHEX("e87450aa0fd87293fd0371483a459bd2"),
256 SHEX("a78a7a8d392f629d bd13674c8dce6fa2"
257 "930c74dec02a11d8 c80d90b5e5c887a7"
258 "83c92a921b5b2028 d9cb313a5f07ab09"
259 "672eadf1624a2ed0 c42d1b08b076f75a"
260 "7378272aa57ad7c8 803e326689541266"
261 "b7a2efda5721776f 4113d63a702ac3ae"
262 "cd1be7bbfad74819 644617f8656e9e5b"),
263 SHEX("b3d488986c80dea7 c5ebdab4907871c9"
264 "a4b92b13b79afb37 5518b01bfd706a37"
265 "8e44c2d463df4531 165461699edbad03"
266 "30ac8c52697102ae 3b725dba79ceb250"
267 "d308b83478e86dbb 629f18736cca042f"
268 "006b89e494469adf 0ee78c60684dff86"
269 "5f2c99908ee77ffe aea3d30cb78a1ce1"));
271 test_cipher(&nettle_serpent128,
272 SHEX("e87450aa0fd87293fd0371483a459bd2"),
273 SHEX("a78a7a8d392f629d bd13674c8dce6fa2"
274 "930c74dec02a11d8 c80d90b5e5c887a7"
275 "83c92a921b5b2028 d9cb313a5f07ab09"
276 "672eadf1624a2ed0 c42d1b08b076f75a"
277 "7378272aa57ad7c8 803e326689541266"
278 "b7a2efda5721776f 4113d63a702ac3ae"
279 "cd1be7bbfad74819 644617f8656e9e5b"
280 "34d449409c1f850a 4cb6700d6ef3405f"),
281 SHEX("b3d488986c80dea7 c5ebdab4907871c9"
282 "a4b92b13b79afb37 5518b01bfd706a37"
283 "8e44c2d463df4531 165461699edbad03"
284 "30ac8c52697102ae 3b725dba79ceb250"
285 "d308b83478e86dbb 629f18736cca042f"
286 "006b89e494469adf 0ee78c60684dff86"
287 "5f2c99908ee77ffe aea3d30cb78a1ce1"
288 "ebe855dd51532477 4d2d55969e032e6c"));