diff options
Diffstat (limited to 'src/regress')
-rw-r--r-- | src/regress/lib/libcrypto/aead/aeadtest.c | 11 | ||||
-rw-r--r-- | src/regress/lib/libcrypto/aead/aeadtests.txt | 11 | ||||
-rw-r--r-- | src/regress/lib/libcrypto/chacha/chachatest.c | 172 |
3 files changed, 191 insertions, 3 deletions
diff --git a/src/regress/lib/libcrypto/aead/aeadtest.c b/src/regress/lib/libcrypto/aead/aeadtest.c index 4f0ab9fa3a..1b144c2615 100644 --- a/src/regress/lib/libcrypto/aead/aeadtest.c +++ b/src/regress/lib/libcrypto/aead/aeadtest.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: aeadtest.c,v 1.11 2018/07/17 17:06:49 tb Exp $ */ | 1 | /* $OpenBSD: aeadtest.c,v 1.12 2019/01/22 00:59:21 dlg Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 2011-2013 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 2011-2013 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
@@ -52,8 +52,11 @@ | |||
52 | #include <stdlib.h> | 52 | #include <stdlib.h> |
53 | #include <string.h> | 53 | #include <string.h> |
54 | #include <stdint.h> | 54 | #include <stdint.h> |
55 | #include <unistd.h> | ||
56 | #include <ctype.h> | ||
55 | 57 | ||
56 | #include <openssl/evp.h> | 58 | #include <openssl/evp.h> |
59 | #include <openssl/err.h> | ||
57 | 60 | ||
58 | /* This program tests an AEAD against a series of test vectors from a file. The | 61 | /* This program tests an AEAD against a series of test vectors from a file. The |
59 | * test vector file consists of key-value lines where the key and value are | 62 | * test vector file consists of key-value lines where the key and value are |
@@ -135,6 +138,12 @@ aead_from_name(const EVP_AEAD **aead, const char *name) | |||
135 | #else | 138 | #else |
136 | fprintf(stderr, "No chacha20-poly1305 support.\n"); | 139 | fprintf(stderr, "No chacha20-poly1305 support.\n"); |
137 | #endif | 140 | #endif |
141 | } else if (strcmp(name, "xchacha20-poly1305") == 0) { | ||
142 | #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305) | ||
143 | *aead = EVP_aead_xchacha20_poly1305(); | ||
144 | #else | ||
145 | fprintf(stderr, "No xchacha20-poly1305 support.\n"); | ||
146 | #endif | ||
138 | } else { | 147 | } else { |
139 | fprintf(stderr, "Unknown AEAD: %s\n", name); | 148 | fprintf(stderr, "Unknown AEAD: %s\n", name); |
140 | return -1; | 149 | return -1; |
diff --git a/src/regress/lib/libcrypto/aead/aeadtests.txt b/src/regress/lib/libcrypto/aead/aeadtests.txt index 18cee7e579..4ca47303b2 100644 --- a/src/regress/lib/libcrypto/aead/aeadtests.txt +++ b/src/regress/lib/libcrypto/aead/aeadtests.txt | |||
@@ -1,4 +1,4 @@ | |||
1 | # $OpenBSD: aeadtests.txt,v 1.7 2018/07/17 17:06:49 tb Exp $ | 1 | # $OpenBSD: aeadtests.txt,v 1.8 2019/01/22 00:59:21 dlg Exp $ |
2 | # | 2 | # |
3 | # MACsec GCM-AES Test Vectors (bn-randall-test-vectors-0511-v1.pdf) | 3 | # MACsec GCM-AES Test Vectors (bn-randall-test-vectors-0511-v1.pdf) |
4 | # | 4 | # |
@@ -75,3 +75,12 @@ AD: c0c1c2c3c4c5c6c7d0d1d2d3d4d5d6d72e202500000000090000004529000029 | |||
75 | CT: 610394701f8d017f7c12924889 | 75 | CT: 610394701f8d017f7c12924889 |
76 | TAG: 6b71bfe25236efd7cdc67066906315b2 | 76 | TAG: 6b71bfe25236efd7cdc67066906315b2 |
77 | 77 | ||
78 | # Test vector from draft-arciszewski-xchacha-02 | ||
79 | AEAD: xchacha20-poly1305 | ||
80 | KEY: 808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f | ||
81 | NONCE: 404142434445464748494a4b4c4d4e4f5051525354555657 | ||
82 | IN: 4c616469657320616e642047656e746c656d656e206f662074686520636c617373206f66202739393a204966204920636f756c64206f6666657220796f75206f6e6c79206f6e652074697020666f7220746865206675747572652c2073756e73637265656e20776f756c642062652069742e | ||
83 | AD: 50515253c0c1c2c3c4c5c6c7 | ||
84 | CT: bd6d179d3e83d43b9576579493c0e939572a1700252bfaccbed2902c21396cbb731c7f1b0b4aa6440bf3a82f4eda7e39ae64c6708c54c216cb96b72e1213b4522f8c9ba40db5d945b11b69b982c1bb9e3f3fac2bc369488f76b2383565d3fff921f9664c97637da9768812f615c68b13b52e | ||
85 | TAG: c0875924c1c7987947deafd8780acf49 | ||
86 | |||
diff --git a/src/regress/lib/libcrypto/chacha/chachatest.c b/src/regress/lib/libcrypto/chacha/chachatest.c index fe4cc40952..4e15974617 100644 --- a/src/regress/lib/libcrypto/chacha/chachatest.c +++ b/src/regress/lib/libcrypto/chacha/chachatest.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: chachatest.c,v 1.5 2018/07/17 17:06:49 tb Exp $ */ | 1 | /* $OpenBSD: chachatest.c,v 1.6 2019/01/22 00:59:21 dlg Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -292,6 +292,170 @@ struct chacha_test_function chacha_test_functions[] = { | |||
292 | 292 | ||
293 | #define N_FUNCS (sizeof(chacha_test_functions) / sizeof(*chacha_test_functions)) | 293 | #define N_FUNCS (sizeof(chacha_test_functions) / sizeof(*chacha_test_functions)) |
294 | 294 | ||
295 | /* draft-arciszewski-xchacha-02 test vectors */ | ||
296 | static int | ||
297 | crypto_hchacha_20_test(void) | ||
298 | { | ||
299 | static const unsigned char key[32] = { | ||
300 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
301 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | ||
302 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, | ||
303 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f | ||
304 | }; | ||
305 | static const unsigned char nonce[16] = { | ||
306 | 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x4a, | ||
307 | 0x00, 0x00, 0x00, 0x00, 0x31, 0x41, 0x59, 0x27, | ||
308 | }; | ||
309 | static const unsigned char result[32] = { | ||
310 | 0x82, 0x41, 0x3b, 0x42, 0x27, 0xb2, 0x7b, 0xfe, | ||
311 | 0xd3, 0x0e, 0x42, 0x50, 0x8a, 0x87, 0x7d, 0x73, | ||
312 | 0xa0, 0xf9, 0xe4, 0xd5, 0x8a, 0x74, 0xa8, 0x53, | ||
313 | 0xc1, 0x2e, 0xc4, 0x13, 0x26, 0xd3, 0xec, 0xdc, | ||
314 | }; | ||
315 | unsigned char out[32]; | ||
316 | int failed = 0; | ||
317 | size_t k; | ||
318 | |||
319 | CRYPTO_hchacha_20(out, key, nonce); | ||
320 | |||
321 | if (memcmp(out, result, sizeof(out)) != 0) { | ||
322 | printf("HChaCha20 failed!\n"); | ||
323 | |||
324 | printf("Got:\t"); | ||
325 | for (k = 0; k < sizeof(out); k++) | ||
326 | printf("%2.2x", out[k]); | ||
327 | printf("\n"); | ||
328 | |||
329 | printf("Want:\t"); | ||
330 | for (k = 0; k < sizeof(result); k++) | ||
331 | printf("%2.2x", result[k]); | ||
332 | printf("\n"); | ||
333 | |||
334 | failed = 1; | ||
335 | } | ||
336 | |||
337 | return (failed); | ||
338 | } | ||
339 | |||
340 | static int | ||
341 | crypto_xchacha_20_test(void) | ||
342 | { | ||
343 | static const unsigned char key[32] = { | ||
344 | 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, | ||
345 | 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, | ||
346 | 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, | ||
347 | 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, | ||
348 | }; | ||
349 | static const unsigned char iv[24] = { | ||
350 | 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, | ||
351 | 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, | ||
352 | 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x58 | ||
353 | }; | ||
354 | static const unsigned char plain[] = { | ||
355 | 0x54, 0x68, 0x65, 0x20, 0x64, 0x68, 0x6f, 0x6c, | ||
356 | 0x65, 0x20, 0x28, 0x70, 0x72, 0x6f, 0x6e, 0x6f, | ||
357 | 0x75, 0x6e, 0x63, 0x65, 0x64, 0x20, 0x22, 0x64, | ||
358 | 0x6f, 0x6c, 0x65, 0x22, 0x29, 0x20, 0x69, 0x73, | ||
359 | 0x20, 0x61, 0x6c, 0x73, 0x6f, 0x20, 0x6b, 0x6e, | ||
360 | 0x6f, 0x77, 0x6e, 0x20, 0x61, 0x73, 0x20, 0x74, | ||
361 | 0x68, 0x65, 0x20, 0x41, 0x73, 0x69, 0x61, 0x74, | ||
362 | 0x69, 0x63, 0x20, 0x77, 0x69, 0x6c, 0x64, 0x20, | ||
363 | 0x64, 0x6f, 0x67, 0x2c, 0x20, 0x72, 0x65, 0x64, | ||
364 | 0x20, 0x64, 0x6f, 0x67, 0x2c, 0x20, 0x61, 0x6e, | ||
365 | 0x64, 0x20, 0x77, 0x68, 0x69, 0x73, 0x74, 0x6c, | ||
366 | 0x69, 0x6e, 0x67, 0x20, 0x64, 0x6f, 0x67, 0x2e, | ||
367 | 0x20, 0x49, 0x74, 0x20, 0x69, 0x73, 0x20, 0x61, | ||
368 | 0x62, 0x6f, 0x75, 0x74, 0x20, 0x74, 0x68, 0x65, | ||
369 | 0x20, 0x73, 0x69, 0x7a, 0x65, 0x20, 0x6f, 0x66, | ||
370 | 0x20, 0x61, 0x20, 0x47, 0x65, 0x72, 0x6d, 0x61, | ||
371 | 0x6e, 0x20, 0x73, 0x68, 0x65, 0x70, 0x68, 0x65, | ||
372 | 0x72, 0x64, 0x20, 0x62, 0x75, 0x74, 0x20, 0x6c, | ||
373 | 0x6f, 0x6f, 0x6b, 0x73, 0x20, 0x6d, 0x6f, 0x72, | ||
374 | 0x65, 0x20, 0x6c, 0x69, 0x6b, 0x65, 0x20, 0x61, | ||
375 | 0x20, 0x6c, 0x6f, 0x6e, 0x67, 0x2d, 0x6c, 0x65, | ||
376 | 0x67, 0x67, 0x65, 0x64, 0x20, 0x66, 0x6f, 0x78, | ||
377 | 0x2e, 0x20, 0x54, 0x68, 0x69, 0x73, 0x20, 0x68, | ||
378 | 0x69, 0x67, 0x68, 0x6c, 0x79, 0x20, 0x65, 0x6c, | ||
379 | 0x75, 0x73, 0x69, 0x76, 0x65, 0x20, 0x61, 0x6e, | ||
380 | 0x64, 0x20, 0x73, 0x6b, 0x69, 0x6c, 0x6c, 0x65, | ||
381 | 0x64, 0x20, 0x6a, 0x75, 0x6d, 0x70, 0x65, 0x72, | ||
382 | 0x20, 0x69, 0x73, 0x20, 0x63, 0x6c, 0x61, 0x73, | ||
383 | 0x73, 0x69, 0x66, 0x69, 0x65, 0x64, 0x20, 0x77, | ||
384 | 0x69, 0x74, 0x68, 0x20, 0x77, 0x6f, 0x6c, 0x76, | ||
385 | 0x65, 0x73, 0x2c, 0x20, 0x63, 0x6f, 0x79, 0x6f, | ||
386 | 0x74, 0x65, 0x73, 0x2c, 0x20, 0x6a, 0x61, 0x63, | ||
387 | 0x6b, 0x61, 0x6c, 0x73, 0x2c, 0x20, 0x61, 0x6e, | ||
388 | 0x64, 0x20, 0x66, 0x6f, 0x78, 0x65, 0x73, 0x20, | ||
389 | 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, | ||
390 | 0x61, 0x78, 0x6f, 0x6e, 0x6f, 0x6d, 0x69, 0x63, | ||
391 | 0x20, 0x66, 0x61, 0x6d, 0x69, 0x6c, 0x79, 0x20, | ||
392 | 0x43, 0x61, 0x6e, 0x69, 0x64, 0x61, 0x65, 0x2e, | ||
393 | }; | ||
394 | static const unsigned char cipher[] = { | ||
395 | 0x45, 0x59, 0xab, 0xba, 0x4e, 0x48, 0xc1, 0x61, | ||
396 | 0x02, 0xe8, 0xbb, 0x2c, 0x05, 0xe6, 0x94, 0x7f, | ||
397 | 0x50, 0xa7, 0x86, 0xde, 0x16, 0x2f, 0x9b, 0x0b, | ||
398 | 0x7e, 0x59, 0x2a, 0x9b, 0x53, 0xd0, 0xd4, 0xe9, | ||
399 | 0x8d, 0x8d, 0x64, 0x10, 0xd5, 0x40, 0xa1, 0xa6, | ||
400 | 0x37, 0x5b, 0x26, 0xd8, 0x0d, 0xac, 0xe4, 0xfa, | ||
401 | 0xb5, 0x23, 0x84, 0xc7, 0x31, 0xac, 0xbf, 0x16, | ||
402 | 0xa5, 0x92, 0x3c, 0x0c, 0x48, 0xd3, 0x57, 0x5d, | ||
403 | 0x4d, 0x0d, 0x2c, 0x67, 0x3b, 0x66, 0x6f, 0xaa, | ||
404 | 0x73, 0x10, 0x61, 0x27, 0x77, 0x01, 0x09, 0x3a, | ||
405 | 0x6b, 0xf7, 0xa1, 0x58, 0xa8, 0x86, 0x42, 0x92, | ||
406 | 0xa4, 0x1c, 0x48, 0xe3, 0xa9, 0xb4, 0xc0, 0xda, | ||
407 | 0xec, 0xe0, 0xf8, 0xd9, 0x8d, 0x0d, 0x7e, 0x05, | ||
408 | 0xb3, 0x7a, 0x30, 0x7b, 0xbb, 0x66, 0x33, 0x31, | ||
409 | 0x64, 0xec, 0x9e, 0x1b, 0x24, 0xea, 0x0d, 0x6c, | ||
410 | 0x3f, 0xfd, 0xdc, 0xec, 0x4f, 0x68, 0xe7, 0x44, | ||
411 | 0x30, 0x56, 0x19, 0x3a, 0x03, 0xc8, 0x10, 0xe1, | ||
412 | 0x13, 0x44, 0xca, 0x06, 0xd8, 0xed, 0x8a, 0x2b, | ||
413 | 0xfb, 0x1e, 0x8d, 0x48, 0xcf, 0xa6, 0xbc, 0x0e, | ||
414 | 0xb4, 0xe2, 0x46, 0x4b, 0x74, 0x81, 0x42, 0x40, | ||
415 | 0x7c, 0x9f, 0x43, 0x1a, 0xee, 0x76, 0x99, 0x60, | ||
416 | 0xe1, 0x5b, 0xa8, 0xb9, 0x68, 0x90, 0x46, 0x6e, | ||
417 | 0xf2, 0x45, 0x75, 0x99, 0x85, 0x23, 0x85, 0xc6, | ||
418 | 0x61, 0xf7, 0x52, 0xce, 0x20, 0xf9, 0xda, 0x0c, | ||
419 | 0x09, 0xab, 0x6b, 0x19, 0xdf, 0x74, 0xe7, 0x6a, | ||
420 | 0x95, 0x96, 0x74, 0x46, 0xf8, 0xd0, 0xfd, 0x41, | ||
421 | 0x5e, 0x7b, 0xee, 0x2a, 0x12, 0xa1, 0x14, 0xc2, | ||
422 | 0x0e, 0xb5, 0x29, 0x2a, 0xe7, 0xa3, 0x49, 0xae, | ||
423 | 0x57, 0x78, 0x20, 0xd5, 0x52, 0x0a, 0x1f, 0x3f, | ||
424 | 0xb6, 0x2a, 0x17, 0xce, 0x6a, 0x7e, 0x68, 0xfa, | ||
425 | 0x7c, 0x79, 0x11, 0x1d, 0x88, 0x60, 0x92, 0x0b, | ||
426 | 0xc0, 0x48, 0xef, 0x43, 0xfe, 0x84, 0x48, 0x6c, | ||
427 | 0xcb, 0x87, 0xc2, 0x5f, 0x0a, 0xe0, 0x45, 0xf0, | ||
428 | 0xcc, 0xe1, 0xe7, 0x98, 0x9a, 0x9a, 0xa2, 0x20, | ||
429 | 0xa2, 0x8b, 0xdd, 0x48, 0x27, 0xe7, 0x51, 0xa2, | ||
430 | 0x4a, 0x6d, 0x5c, 0x62, 0xd7, 0x90, 0xa6, 0x63, | ||
431 | 0x93, 0xb9, 0x31, 0x11, 0xc1, 0xa5, 0x5d, 0xd7, | ||
432 | 0x42, 0x1a, 0x10, 0x18, 0x49, 0x74, 0xc7, 0xc5, | ||
433 | }; | ||
434 | unsigned char out[sizeof(cipher)]; | ||
435 | int failed = 0; | ||
436 | size_t k; | ||
437 | |||
438 | CRYPTO_xchacha_20(out, plain, sizeof(out), key, iv); | ||
439 | |||
440 | if (memcmp(out, cipher, sizeof(out)) != 0) { | ||
441 | printf("XChaCha20 failed!\n"); | ||
442 | |||
443 | printf("Got:\t"); | ||
444 | for (k = 0; k < sizeof(out); k++) | ||
445 | printf("%2.2x", out[k]); | ||
446 | printf("\n"); | ||
447 | |||
448 | printf("Want:\t"); | ||
449 | for (k = 0; k < sizeof(cipher); k++) | ||
450 | printf("%2.2x", cipher[k]); | ||
451 | printf("\n"); | ||
452 | |||
453 | failed = 1; | ||
454 | } | ||
455 | |||
456 | return (failed); | ||
457 | } | ||
458 | |||
295 | int | 459 | int |
296 | main(int argc, char **argv) | 460 | main(int argc, char **argv) |
297 | { | 461 | { |
@@ -335,5 +499,11 @@ main(int argc, char **argv) | |||
335 | } | 499 | } |
336 | } | 500 | } |
337 | 501 | ||
502 | if (crypto_hchacha_20_test() != 0) | ||
503 | failed = 1; | ||
504 | |||
505 | if (crypto_xchacha_20_test() != 0) | ||
506 | failed = 1; | ||
507 | |||
338 | return failed; | 508 | return failed; |
339 | } | 509 | } |