summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2022-09-12 13:11:36 +0000
committertb <>2022-09-12 13:11:36 +0000
commitefa6d2fe42f5eb1296915dcd7b56cac3045e92bc (patch)
treee0b366395ac66afeb26e72998b8594fe3490071b /src
parent46fd4dcd31c01d9915dc163de60f0b1e13211bbe (diff)
downloadopenbsd-efa6d2fe42f5eb1296915dcd7b56cac3045e92bc.tar.gz
openbsd-efa6d2fe42f5eb1296915dcd7b56cac3045e92bc.tar.bz2
openbsd-efa6d2fe42f5eb1296915dcd7b56cac3045e92bc.zip
Add CBC, CFB64 and OFB64 test coverage for RC2
From Joshua Sing
Diffstat (limited to 'src')
-rw-r--r--src/regress/lib/libcrypto/rc2/rc2_test.c497
1 files changed, 463 insertions, 34 deletions
diff --git a/src/regress/lib/libcrypto/rc2/rc2_test.c b/src/regress/lib/libcrypto/rc2/rc2_test.c
index 08a7daea46..ab95e587f8 100644
--- a/src/regress/lib/libcrypto/rc2/rc2_test.c
+++ b/src/regress/lib/libcrypto/rc2/rc2_test.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rc2_test.c,v 1.4 2022/09/12 13:09:01 tb Exp $ */ 1/* $OpenBSD: rc2_test.c,v 1.5 2022/09/12 13:11:36 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2022 Joshua Sing <joshua@hypera.dev> 3 * Copyright (c) 2022 Joshua Sing <joshua@hypera.dev>
4 * 4 *
@@ -26,9 +26,13 @@ struct rc2_test {
26 const uint8_t key[64]; 26 const uint8_t key[64];
27 const int key_len; 27 const int key_len;
28 const int key_bits; 28 const int key_bits;
29 const int len; 29 const uint8_t iv[64];
30 const uint8_t in[8]; 30 const int iv_len;
31 const uint8_t out[8]; 31 const uint8_t in[64];
32 const int in_len;
33 const uint8_t out[64];
34 const int out_len;
35 const int padding;
32}; 36};
33 37
34static const struct rc2_test rc2_tests[] = { 38static const struct rc2_test rc2_tests[] = {
@@ -40,13 +44,14 @@ static const struct rc2_test rc2_tests[] = {
40 }, 44 },
41 .key_len = 8, 45 .key_len = 8,
42 .key_bits = 63, 46 .key_bits = 63,
43 .len = 8,
44 .in = { 47 .in = {
45 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 48 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
46 }, 49 },
50 .in_len = 8,
47 .out = { 51 .out = {
48 0xeb, 0xb7, 0x73, 0xf9, 0x93, 0x27, 0x8e, 0xff, 52 0xeb, 0xb7, 0x73, 0xf9, 0x93, 0x27, 0x8e, 0xff,
49 }, 53 },
54 .out_len = 8,
50 }, 55 },
51 { 56 {
52 .mode = NID_rc2_ecb, 57 .mode = NID_rc2_ecb,
@@ -55,13 +60,14 @@ static const struct rc2_test rc2_tests[] = {
55 }, 60 },
56 .key_len = 8, 61 .key_len = 8,
57 .key_bits = 64, 62 .key_bits = 64,
58 .len = 8,
59 .in = { 63 .in = {
60 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 64 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
61 }, 65 },
66 .in_len = 8,
62 .out = { 67 .out = {
63 0x27, 0x8b, 0x27, 0xe4, 0x2e, 0x2f, 0x0d, 0x49, 68 0x27, 0x8b, 0x27, 0xe4, 0x2e, 0x2f, 0x0d, 0x49,
64 }, 69 },
70 .out_len = 8,
65 }, 71 },
66 { 72 {
67 .mode = NID_rc2_ecb, 73 .mode = NID_rc2_ecb,
@@ -70,13 +76,14 @@ static const struct rc2_test rc2_tests[] = {
70 }, 76 },
71 .key_len = 8, 77 .key_len = 8,
72 .key_bits = 64, 78 .key_bits = 64,
73 .len = 8,
74 .in = { 79 .in = {
75 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 80 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
76 }, 81 },
82 .in_len = 8,
77 .out = { 83 .out = {
78 0x30, 0x64, 0x9e, 0xdf, 0x9b, 0xe7, 0xd2, 0xc2, 84 0x30, 0x64, 0x9e, 0xdf, 0x9b, 0xe7, 0xd2, 0xc2,
79 }, 85 },
86 .out_len = 8,
80 }, 87 },
81 { 88 {
82 .mode = NID_rc2_ecb, 89 .mode = NID_rc2_ecb,
@@ -85,13 +92,14 @@ static const struct rc2_test rc2_tests[] = {
85 }, 92 },
86 .key_len = 1, 93 .key_len = 1,
87 .key_bits = 64, 94 .key_bits = 64,
88 .len = 8,
89 .in = { 95 .in = {
90 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 96 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
91 }, 97 },
98 .in_len = 8,
92 .out = { 99 .out = {
93 0x61, 0xa8, 0xa2, 0x44, 0xad, 0xac, 0xcc, 0xf0, 100 0x61, 0xa8, 0xa2, 0x44, 0xad, 0xac, 0xcc, 0xf0,
94 }, 101 },
102 .out_len = 8,
95 }, 103 },
96 { 104 {
97 .mode = NID_rc2_ecb, 105 .mode = NID_rc2_ecb,
@@ -100,13 +108,14 @@ static const struct rc2_test rc2_tests[] = {
100 }, 108 },
101 .key_len = 7, 109 .key_len = 7,
102 .key_bits = 64, 110 .key_bits = 64,
103 .len = 8,
104 .in = { 111 .in = {
105 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 112 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
106 }, 113 },
114 .in_len = 8,
107 .out = { 115 .out = {
108 0x6c, 0xcf, 0x43, 0x08, 0x97, 0x4c, 0x26, 0x7f, 116 0x6c, 0xcf, 0x43, 0x08, 0x97, 0x4c, 0x26, 0x7f,
109 }, 117 },
118 .out_len = 8,
110 }, 119 },
111 { 120 {
112 .mode = NID_rc2_ecb, 121 .mode = NID_rc2_ecb,
@@ -116,13 +125,14 @@ static const struct rc2_test rc2_tests[] = {
116 }, 125 },
117 .key_len = 16, 126 .key_len = 16,
118 .key_bits = 64, 127 .key_bits = 64,
119 .len = 8,
120 .in = { 128 .in = {
121 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 129 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
122 }, 130 },
131 .in_len = 8,
123 .out = { 132 .out = {
124 0x1a, 0x80, 0x7d, 0x27, 0x2b, 0xbe, 0x5d, 0xb1, 133 0x1a, 0x80, 0x7d, 0x27, 0x2b, 0xbe, 0x5d, 0xb1,
125 }, 134 },
135 .out_len = 8,
126 }, 136 },
127 { 137 {
128 .mode = NID_rc2_ecb, 138 .mode = NID_rc2_ecb,
@@ -132,13 +142,14 @@ static const struct rc2_test rc2_tests[] = {
132 }, 142 },
133 .key_len = 16, 143 .key_len = 16,
134 .key_bits = 128, 144 .key_bits = 128,
135 .len = 8,
136 .in = { 145 .in = {
137 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 146 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
138 }, 147 },
148 .in_len = 8,
139 .out = { 149 .out = {
140 0x22, 0x69, 0x55, 0x2a, 0xb0, 0xf8, 0x5c, 0xa6, 150 0x22, 0x69, 0x55, 0x2a, 0xb0, 0xf8, 0x5c, 0xa6,
141 }, 151 },
152 .out_len = 8,
142 }, 153 },
143 { 154 {
144 .mode = NID_rc2_ecb, 155 .mode = NID_rc2_ecb,
@@ -151,13 +162,14 @@ static const struct rc2_test rc2_tests[] = {
151 }, 162 },
152 .key_len = 33, 163 .key_len = 33,
153 .key_bits = 129, 164 .key_bits = 129,
154 .len = 8,
155 .in = { 165 .in = {
156 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 166 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
157 }, 167 },
168 .in_len = 8,
158 .out = { 169 .out = {
159 0x5b, 0x78, 0xd3, 0xa4, 0x3d, 0xff, 0xf1, 0xf1, 170 0x5b, 0x78, 0xd3, 0xa4, 0x3d, 0xff, 0xf1, 0xf1,
160 }, 171 },
172 .out_len = 8,
161 }, 173 },
162 174
163 /* ECB (Test vectors from http://websites.umich.edu/~x509/ssleay/rrc2.html) */ 175 /* ECB (Test vectors from http://websites.umich.edu/~x509/ssleay/rrc2.html) */
@@ -169,13 +181,14 @@ static const struct rc2_test rc2_tests[] = {
169 }, 181 },
170 .key_len = 16, 182 .key_len = 16,
171 .key_bits = 1024, 183 .key_bits = 1024,
172 .len = 8,
173 .in = { 184 .in = {
174 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 185 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
175 }, 186 },
187 .in_len = 8,
176 .out = { 188 .out = {
177 0x1c, 0x19, 0x8a, 0x83, 0x8d, 0xf0, 0x28, 0xb7, 189 0x1c, 0x19, 0x8a, 0x83, 0x8d, 0xf0, 0x28, 0xb7,
178 }, 190 },
191 .out_len = 8,
179 }, 192 },
180 { 193 {
181 .mode = NID_rc2_ecb, 194 .mode = NID_rc2_ecb,
@@ -185,13 +198,14 @@ static const struct rc2_test rc2_tests[] = {
185 }, 198 },
186 .key_len = 16, 199 .key_len = 16,
187 .key_bits = 1024, 200 .key_bits = 1024,
188 .len = 8,
189 .in = { 201 .in = {
190 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 202 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
191 }, 203 },
204 .in_len = 8,
192 .out = { 205 .out = {
193 0x21, 0x82, 0x9C, 0x78, 0xA9, 0xF9, 0xC0, 0x74, 206 0x21, 0x82, 0x9C, 0x78, 0xA9, 0xF9, 0xC0, 0x74,
194 }, 207 },
208 .out_len = 8,
195 }, 209 },
196 { 210 {
197 .mode = NID_rc2_ecb, 211 .mode = NID_rc2_ecb,
@@ -201,13 +215,14 @@ static const struct rc2_test rc2_tests[] = {
201 }, 215 },
202 .key_len = 16, 216 .key_len = 16,
203 .key_bits = 1024, 217 .key_bits = 1024,
204 .len = 8,
205 .in = { 218 .in = {
206 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 219 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
207 }, 220 },
221 .in_len = 8,
208 .out = { 222 .out = {
209 0x13, 0xdb, 0x35, 0x17, 0xd3, 0x21, 0x86, 0x9e, 223 0x13, 0xdb, 0x35, 0x17, 0xd3, 0x21, 0x86, 0x9e,
210 }, 224 },
225 .out_len = 8,
211 }, 226 },
212 { 227 {
213 .mode = NID_rc2_ecb, 228 .mode = NID_rc2_ecb,
@@ -217,13 +232,305 @@ static const struct rc2_test rc2_tests[] = {
217 }, 232 },
218 .key_len = 16, 233 .key_len = 16,
219 .key_bits = 1024, 234 .key_bits = 1024,
220 .len = 8,
221 .in = { 235 .in = {
222 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 236 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
223 }, 237 },
238 .in_len = 8,
224 .out = { 239 .out = {
225 0x50, 0xdc, 0x01, 0x62, 0xbd, 0x75, 0x7f, 0x31, 240 0x50, 0xdc, 0x01, 0x62, 0xbd, 0x75, 0x7f, 0x31,
226 }, 241 },
242 .out_len = 8,
243 },
244
245 /* CBC (generated using https://github.com/joshuasing/libressl-test-gen) */
246 {
247 .mode = NID_rc2_cbc,
248 .key = {
249 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
250 },
251 .key_len = 8,
252 .key_bits = 64,
253 .iv = {
254 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
255 },
256 .iv_len = 8,
257 .in = {
258 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
259 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
260 },
261 .in_len = 16,
262 .out = {
263 0xeb, 0xb7, 0x73, 0xf9, 0x93, 0x27, 0x8e, 0xff,
264 0xf0, 0x51, 0x77, 0x8b, 0x65, 0xdb, 0x13, 0x57,
265 },
266 .out_len = 16,
267 },
268 {
269 .mode = NID_rc2_cbc,
270 .key = {
271 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
272 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
273 },
274 .key_len = 16,
275 .key_bits = 128,
276 .iv = {
277 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
278 },
279 .iv_len = 8,
280 .in = {
281 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
282 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
283 },
284 .in_len = 16,
285 .out = {
286 0x9c, 0x4b, 0xfe, 0x6d, 0xfe, 0x73, 0x9c, 0x2b,
287 0x52, 0x8f, 0xc8, 0x47, 0x2b, 0x66, 0xf9, 0x70,
288 },
289 .out_len = 16,
290 },
291 {
292 .mode = NID_rc2_cbc,
293 .key = {
294 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
295 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
296 },
297 .key_len = 16,
298 .key_bits = 128,
299 .iv = {
300 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
301 },
302 .iv_len = 8,
303 .in = {
304 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
305 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
306 },
307 .in_len = 16,
308 .out = {
309 0x8b, 0x11, 0x08, 0x1c, 0xf0, 0xa0, 0x86, 0xe9,
310 0x60, 0x57, 0x69, 0x5d, 0xdd, 0x42, 0x38, 0xe3,
311 },
312 .out_len = 16,
313 },
314 {
315 .mode = NID_rc2_cbc,
316 .key = {
317 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
318 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
319 },
320 .key_len = 16,
321 .key_bits = 128,
322 .iv = {
323 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
324 },
325 .iv_len = 8,
326 .in = {
327 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
328 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
329 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
330 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
331 },
332 .in_len = 32,
333 .out = {
334 0x9c, 0x4b, 0xfe, 0x6d, 0xfe, 0x73, 0x9c, 0x2b,
335 0x29, 0xf1, 0x7a, 0xd2, 0x16, 0xa0, 0xb2, 0xc6,
336 0xd1, 0xa2, 0x31, 0xbe, 0xa3, 0x94, 0xc6, 0xb0,
337 0x81, 0x22, 0x27, 0x17, 0x5b, 0xd4, 0x6d, 0x29,
338 },
339 .out_len = 32,
340 },
341
342 /* CFB64 (generated using https://github.com/joshuasing/libressl-test-gen) */
343 {
344 .mode = NID_rc2_cfb64,
345 .key = {
346 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
347 },
348 .key_len = 8,
349 .key_bits = 64,
350 .iv = {
351 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
352 },
353 .iv_len = 8,
354 .in = {
355 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
356 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
357 },
358 .in_len = 16,
359 .out = {
360 0xeb, 0xb7, 0x73, 0xf9, 0x93, 0x27, 0x8e, 0xff,
361 0xf0, 0x51, 0x77, 0x8b, 0x65, 0xdb, 0x13, 0x57,
362 },
363 .out_len = 16,
364 },
365 {
366 .mode = NID_rc2_cfb64,
367 .key = {
368 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
369 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
370 },
371 .key_len = 16,
372 .key_bits = 128,
373 .iv = {
374 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
375 },
376 .iv_len = 8,
377 .in = {
378 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
379 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
380 },
381 .in_len = 16,
382 .out = {
383 0x9c, 0x4b, 0xfe, 0x6d, 0xfe, 0x73, 0x9c, 0x2b,
384 0x52, 0x8f, 0xc8, 0x47, 0x2b, 0x66, 0xf9, 0x70,
385 },
386 .out_len = 16,
387 },
388 {
389 .mode = NID_rc2_cfb64,
390 .key = {
391 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
392 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
393 },
394 .key_len = 16,
395 .key_bits = 128,
396 .iv = {
397 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
398 },
399 .iv_len = 8,
400 .in = {
401 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
402 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
403 },
404 .in_len = 16,
405 .out = {
406 0x9c, 0x4a, 0xfc, 0x6e, 0xfa, 0x76, 0x9a, 0x2c,
407 0xeb, 0xdf, 0x25, 0xb0, 0x15, 0x8b, 0x6a, 0x2a,
408 },
409 .out_len = 16,
410 },
411 {
412 .mode = NID_rc2_cfb64,
413 .key = {
414 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
415 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
416 },
417 .key_len = 16,
418 .key_bits = 128,
419 .iv = {
420 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
421 },
422 .iv_len = 8,
423 .in = {
424 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
425 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
426 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
427 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
428 },
429 .in_len = 32,
430 .out = {
431 0x8b, 0x10, 0x0a, 0x1f, 0xf4, 0xa5, 0x80, 0xee,
432 0x94, 0x4d, 0xc3, 0xcd, 0x26, 0x79, 0x81, 0xc0,
433 0xe9, 0x3e, 0x20, 0x85, 0x11, 0x71, 0x61, 0x2a,
434 0x1d, 0x4c, 0x8a, 0xe2, 0xb7, 0x0a, 0xa8, 0xcf,
435 },
436 .out_len = 32,
437 },
438
439 /* OFB64 (generated using https://github.com/joshuasing/libressl-test-gen) */
440 {
441 .mode = NID_rc2_ofb64,
442 .key = {
443 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
444 },
445 .key_len = 8,
446 .key_bits = 64,
447 .iv = {
448 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
449 },
450 .iv_len = 8,
451 .in = {
452 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
453 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
454 },
455 .in_len = 16,
456 .out = {
457 0xeb, 0xb7, 0x73, 0xf9, 0x93, 0x27, 0x8e, 0xff,
458 0xf0, 0x51, 0x77, 0x8b, 0x65, 0xdb, 0x13, 0x57,
459 },
460 .out_len = 16,
461 },
462 {
463 .mode = NID_rc2_ofb64,
464 .key = {
465 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
466 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
467 },
468 .key_len = 16,
469 .key_bits = 128,
470 .iv = {
471 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
472 },
473 .iv_len = 8,
474 .in = {
475 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
476 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
477 },
478 .in_len = 16,
479 .out = {
480 0x9c, 0x4b, 0xfe, 0x6d, 0xfe, 0x73, 0x9c, 0x2b,
481 0x52, 0x8f, 0xc8, 0x47, 0x2b, 0x66, 0xf9, 0x70,
482 },
483 .out_len = 16,
484 },
485 {
486 .mode = NID_rc2_ofb64,
487 .key = {
488 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
489 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
490 },
491 .key_len = 16,
492 .key_bits = 128,
493 .iv = {
494 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
495 },
496 .iv_len = 8,
497 .in = {
498 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
499 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
500 },
501 .in_len = 16,
502 .out = {
503 0x9c, 0x4a, 0xfc, 0x6e, 0xfa, 0x76, 0x9a, 0x2c,
504 0x5a, 0x86, 0xc2, 0x4c, 0x27, 0x6b, 0xf7, 0x7f,
505 },
506 .out_len = 16,
507 },
508 {
509 .mode = NID_rc2_ofb64,
510 .key = {
511 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
512 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
513 },
514 .key_len = 16,
515 .key_bits = 128,
516 .iv = {
517 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
518 },
519 .iv_len = 8,
520 .in = {
521 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
522 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
523 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
524 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
525 },
526 .in_len = 32,
527 .out = {
528 0x8b, 0x10, 0x0a, 0x1f, 0xf4, 0xa5, 0x80, 0xee,
529 0xfa, 0x1d, 0x1a, 0x7c, 0xb2, 0x93, 0x00, 0x9d,
530 0x36, 0xa1, 0xff, 0x3a, 0x77, 0x1d, 0x00, 0x9b,
531 0x20, 0xde, 0x5f, 0x93, 0xcc, 0x3e, 0x51, 0xaa,
532 },
533 .out_len = 32,
227 }, 534 },
228}; 535};
229 536
@@ -240,7 +547,7 @@ rc2_ecb_test(size_t test_number, const struct rc2_test *rt)
240 RC2_set_key(&key, rt->key_len, rt->key, rt->key_bits); 547 RC2_set_key(&key, rt->key_len, rt->key, rt->key_bits);
241 RC2_ecb_encrypt(rt->in, out, &key, 1); 548 RC2_ecb_encrypt(rt->in, out, &key, 1);
242 549
243 if (memcmp(rt->out, out, rt->len) != 0) { 550 if (memcmp(rt->out, out, rt->out_len) != 0) {
244 fprintf(stderr, "FAIL (%s:%zu): encryption mismatch\n", 551 fprintf(stderr, "FAIL (%s:%zu): encryption mismatch\n",
245 SN_rc2_ecb, test_number); 552 SN_rc2_ecb, test_number);
246 return 0; 553 return 0;
@@ -251,7 +558,7 @@ rc2_ecb_test(size_t test_number, const struct rc2_test *rt)
251 RC2_set_key(&key, rt->key_len, rt->key, rt->key_bits); 558 RC2_set_key(&key, rt->key_len, rt->key, rt->key_bits);
252 RC2_ecb_encrypt(rt->out, out, &key, 0); 559 RC2_ecb_encrypt(rt->out, out, &key, 0);
253 560
254 if (memcmp(rt->in, out, rt->len) != 0) { 561 if (memcmp(rt->in, out, rt->in_len) != 0) {
255 fprintf(stderr, "FAIL (%s:%zu): decryption mismatch\n", 562 fprintf(stderr, "FAIL (%s:%zu): decryption mismatch\n",
256 SN_rc2_ecb, test_number); 563 SN_rc2_ecb, test_number);
257 return 0; 564 return 0;
@@ -261,6 +568,110 @@ rc2_ecb_test(size_t test_number, const struct rc2_test *rt)
261} 568}
262 569
263static int 570static int
571rc2_cbc_test(size_t test_number, const struct rc2_test *rt)
572{
573 RC2_KEY key;
574 uint8_t out[512];
575 uint8_t iv[64];
576
577 /* Encryption */
578 memset(out, 0, sizeof(out));
579 memcpy(iv, rt->iv, rt->iv_len);
580 RC2_set_key(&key, rt->key_len, rt->key, rt->key_bits);
581 RC2_cbc_encrypt(rt->in, out, rt->in_len, &key, iv, 1);
582
583 if (memcmp(rt->out, out, rt->out_len) != 0) {
584 fprintf(stderr, "FAIL (%s:%zu): encryption mismatch\n",
585 SN_rc2_cbc, test_number);
586 return 0;
587 }
588
589 /* Decryption */
590 memset(out, 0, sizeof(out));
591 memcpy(iv, rt->iv, rt->iv_len);
592 RC2_set_key(&key, rt->key_len, rt->key, rt->key_bits);
593 RC2_cbc_encrypt(rt->out, out, rt->out_len, &key, iv, 0);
594
595 if (memcmp(rt->in, out, rt->in_len) != 0) {
596 fprintf(stderr, "FAIL (%s:%zu): decryption mismatch\n",
597 SN_rc2_cbc, test_number);
598 return 0;
599 }
600
601 return 1;
602}
603
604static int
605rc2_cfb64_test(size_t test_number, const struct rc2_test *rt)
606{
607 RC2_KEY key;
608 uint8_t out[512];
609 uint8_t iv[64];
610 int remainder = 0;
611
612 /* Encryption */
613 memset(out, 0, sizeof(out));
614 memcpy(iv, rt->iv, rt->iv_len);
615 RC2_set_key(&key, rt->key_len, rt->key, rt->key_bits);
616 RC2_cfb64_encrypt(rt->in, out, rt->in_len * 8, &key, iv, &remainder, 1);
617
618 if (memcmp(rt->out, out, rt->out_len) != 0) {
619 fprintf(stderr, "FAIL (%s:%zu): encryption mismatch\n",
620 SN_rc2_cbc, test_number);
621 return 0;
622 }
623
624 /* Decryption */
625 memset(out, 0, sizeof(out));
626 memcpy(iv, rt->iv, rt->iv_len);
627 RC2_set_key(&key, rt->key_len, rt->key, rt->key_bits);
628 RC2_cfb64_encrypt(rt->out, out, rt->out_len, &key, iv, &remainder, 0);
629
630 if (memcmp(rt->in, out, rt->in_len) != 0) {
631 fprintf(stderr, "FAIL (%s:%zu): decryption mismatch\n",
632 SN_rc2_cbc, test_number);
633 return 0;
634 }
635
636 return 1;
637}
638
639static int
640rc2_ofb64_test(size_t test_number, const struct rc2_test *rt)
641{
642 RC2_KEY key;
643 uint8_t out[512];
644 uint8_t iv[64];
645 int remainder = 0;
646
647 /* Encryption */
648 memset(out, 0, sizeof(out));
649 memcpy(iv, rt->iv, rt->iv_len);
650 RC2_set_key(&key, rt->key_len, rt->key, rt->key_bits);
651 RC2_ofb64_encrypt(rt->in, out, rt->in_len, &key, iv, &remainder);
652
653 if (memcmp(rt->out, out, rt->out_len) != 0) {
654 fprintf(stderr, "FAIL (%s:%zu): encryption mismatch\n",
655 SN_rc2_cbc, test_number);
656 return 0;
657 }
658
659 /* Decryption */
660 memset(out, 0, sizeof(out));
661 memcpy(iv, rt->iv, rt->iv_len);
662 RC2_set_key(&key, rt->key_len, rt->key, rt->key_bits);
663 RC2_ofb64_encrypt(rt->out, out, rt->out_len, &key, iv, &remainder);
664
665 if (memcmp(rt->in, out, rt->in_len) != 0) {
666 fprintf(stderr, "FAIL (%s:%zu): decryption mismatch\n",
667 SN_rc2_cbc, test_number);
668 return 0;
669 }
670
671 return 1;
672}
673
674static int
264rc2_evp_test(size_t test_number, const struct rc2_test *rt, const char *label, 675rc2_evp_test(size_t test_number, const struct rc2_test *rt, const char *label,
265 const EVP_CIPHER *cipher) 676 const EVP_CIPHER *cipher)
266{ 677{
@@ -299,23 +710,23 @@ rc2_evp_test(size_t test_number, const struct rc2_test *rt, const char *label,
299 goto failed; 710 goto failed;
300 } 711 }
301 712
302 if (!EVP_CIPHER_CTX_set_padding(ctx, 0)) { 713 if (!EVP_CIPHER_CTX_set_padding(ctx, rt->padding)) {
303 fprintf(stderr, 714 fprintf(stderr,
304 "FAIL (%s:%zu): EVP_CIPHER_CTX_set_padding failed\n", 715 "FAIL (%s:%zu): EVP_CIPHER_CTX_set_padding failed\n",
305 label, test_number); 716 label, test_number);
306 goto failed; 717 goto failed;
307 } 718 }
308 719
309 if (!EVP_EncryptInit(ctx, NULL, rt->key, NULL)) { 720 if (!EVP_EncryptInit(ctx, NULL, rt->key, rt->iv)) {
310 fprintf(stderr, "FAIL (%s:%zu): EVP_EncryptInit failed\n", 721 fprintf(stderr, "FAIL (%s:%zu): EVP_EncryptInit failed\n",
311 label, test_number); 722 label, test_number);
312 goto failed; 723 goto failed;
313 } 724 }
314 725
315 for (i = 0; i < rt->len;) { 726 for (i = 0; i < rt->in_len;) {
316 in_len = arc4random_uniform(sizeof(rt->len) / 2); 727 in_len = arc4random_uniform(sizeof(rt->in_len) / 2);
317 if (in_len > rt->len - i) 728 if (in_len > rt->in_len - i)
318 in_len = rt->len - i; 729 in_len = rt->in_len - i;
319 730
320 if (!EVP_EncryptUpdate(ctx, out + total_len, &out_len, 731 if (!EVP_EncryptUpdate(ctx, out + total_len, &out_len,
321 rt->in + i, in_len)) { 732 rt->in + i, in_len)) {
@@ -343,14 +754,14 @@ rc2_evp_test(size_t test_number, const struct rc2_test *rt, const char *label,
343 goto failed; 754 goto failed;
344 } 755 }
345 756
346 if (total_len != rt->len) { 757 if (total_len != rt->out_len) {
347 fprintf(stderr, 758 fprintf(stderr,
348 "FAIL (%s:%zu): EVP encryption length mismatch\n", 759 "FAIL (%s:%zu): EVP encryption length mismatch\n",
349 label, test_number); 760 label, test_number);
350 goto failed; 761 goto failed;
351 } 762 }
352 763
353 if (memcmp(rt->out, out, rt->len) != 0) { 764 if (memcmp(rt->out, out, rt->out_len) != 0) {
354 fprintf(stderr, "FAIL (%s:%zu): EVP encryption mismatch\n", 765 fprintf(stderr, "FAIL (%s:%zu): EVP encryption mismatch\n",
355 label, test_number); 766 label, test_number);
356 goto failed; 767 goto failed;
@@ -379,23 +790,23 @@ rc2_evp_test(size_t test_number, const struct rc2_test *rt, const char *label,
379 goto failed; 790 goto failed;
380 } 791 }
381 792
382 if (!EVP_CIPHER_CTX_set_padding(ctx, 0)) { 793 if (!EVP_CIPHER_CTX_set_padding(ctx, rt->padding)) {
383 fprintf(stderr, 794 fprintf(stderr,
384 "FAIL (%s:%zu): EVP_CIPHER_CTX_set_padding failed\n", 795 "FAIL (%s:%zu): EVP_CIPHER_CTX_set_padding failed\n",
385 label, test_number); 796 label, test_number);
386 goto failed; 797 goto failed;
387 } 798 }
388 799
389 if (!EVP_DecryptInit(ctx, NULL, rt->key, NULL)) { 800 if (!EVP_DecryptInit(ctx, NULL, rt->key, rt->iv)) {
390 fprintf(stderr, "FAIL (%s:%zu): EVP_DecryptInit failed\n", 801 fprintf(stderr, "FAIL (%s:%zu): EVP_DecryptInit failed\n",
391 label, test_number); 802 label, test_number);
392 goto failed; 803 goto failed;
393 } 804 }
394 805
395 for (i = 0; i < rt->len;) { 806 for (i = 0; i < rt->out_len;) {
396 in_len = arc4random_uniform(sizeof(rt->len) / 2); 807 in_len = arc4random_uniform(sizeof(rt->out_len) / 2);
397 if (in_len > rt->len - i) 808 if (in_len > rt->out_len - i)
398 in_len = rt->len - i; 809 in_len = rt->out_len - i;
399 810
400 if (!EVP_DecryptUpdate(ctx, out + total_len, &out_len, 811 if (!EVP_DecryptUpdate(ctx, out + total_len, &out_len,
401 rt->out + i, in_len)) { 812 rt->out + i, in_len)) {
@@ -423,14 +834,14 @@ rc2_evp_test(size_t test_number, const struct rc2_test *rt, const char *label,
423 goto failed; 834 goto failed;
424 } 835 }
425 836
426 if (total_len != rt->len) { 837 if (total_len != rt->in_len) {
427 fprintf(stderr, 838 fprintf(stderr,
428 "FAIL (%s:%zu): EVP decryption length mismatch\n", 839 "FAIL (%s:%zu): EVP decryption length mismatch\n",
429 label, test_number); 840 label, test_number);
430 goto failed; 841 goto failed;
431 } 842 }
432 843
433 if (memcmp(rt->in, out, rt->len) != 0) { 844 if (memcmp(rt->in, out, rt->in_len) != 0) {
434 fprintf(stderr, "FAIL (%s:%zu): EVP decryption mismatch\n", 845 fprintf(stderr, "FAIL (%s:%zu): EVP decryption mismatch\n",
435 label, test_number); 846 label, test_number);
436 goto failed; 847 goto failed;
@@ -461,6 +872,24 @@ rc2_test(void)
461 if (!rc2_ecb_test(i, rt)) 872 if (!rc2_ecb_test(i, rt))
462 goto failed; 873 goto failed;
463 break; 874 break;
875 case NID_rc2_cbc:
876 label = SN_rc2_cbc;
877 cipher = EVP_rc2_cbc();
878 if (!rc2_cbc_test(i, rt))
879 goto failed;
880 break;
881 case NID_rc2_cfb64:
882 label = SN_rc2_cfb64;
883 cipher = EVP_rc2_cfb64();
884 if (!rc2_cfb64_test(i, rt))
885 goto failed;
886 break;
887 case NID_rc2_ofb64:
888 label = SN_rc2_ofb64;
889 cipher = EVP_rc2_ofb();
890 if (!rc2_ofb64_test(i, rt))
891 goto failed;
892 break;
464 default: 893 default:
465 fprintf(stderr, "FAIL: unknown mode (%d)\n", 894 fprintf(stderr, "FAIL: unknown mode (%d)\n",
466 rt->mode); 895 rt->mode);