summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2019-03-17 18:33:01 +0000
committertb <>2019-03-17 18:33:01 +0000
commit24c04e2def7e2b57a9aaa595d26bb601b5a77505 (patch)
tree52355aa2d8c139bc0289da29c7c07080a7b22830
parent5f84fb3a7b33b109f2765b35d43614016d4b5023 (diff)
downloadopenbsd-24c04e2def7e2b57a9aaa595d26bb601b5a77505.tar.gz
openbsd-24c04e2def7e2b57a9aaa595d26bb601b5a77505.tar.bz2
openbsd-24c04e2def7e2b57a9aaa595d26bb601b5a77505.zip
Add regress tests for the EVP_aes_*_wrap() API. Based on the tests in
OpenSSL 1.0.2r which is still freely licenced with a tweak by jsing.
-rw-r--r--src/regress/lib/libcrypto/evp/evptest.c14
-rw-r--r--src/regress/lib/libcrypto/evp/evptests.txt9
2 files changed, 19 insertions, 4 deletions
diff --git a/src/regress/lib/libcrypto/evp/evptest.c b/src/regress/lib/libcrypto/evp/evptest.c
index 1aa11d7b1e..ac15a55aaa 100644
--- a/src/regress/lib/libcrypto/evp/evptest.c
+++ b/src/regress/lib/libcrypto/evp/evptest.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evptest.c,v 1.7 2018/07/17 17:06:49 tb Exp $ */ 1/* $OpenBSD: evptest.c,v 1.8 2019/03/17 18:33:01 tb Exp $ */
2/* Written by Ben Laurie, 2001 */ 2/* Written by Ben Laurie, 2001 */
3/* 3/*
4 * Copyright (c) 2001 The OpenSSL Project. All rights reserved. 4 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
@@ -144,6 +144,7 @@ test1(const EVP_CIPHER *c, const unsigned char *key, int kn,
144{ 144{
145 EVP_CIPHER_CTX ctx; 145 EVP_CIPHER_CTX ctx;
146 unsigned char out[4096]; 146 unsigned char out[4096];
147 const unsigned char *eiv;
147 int outl, outl2; 148 int outl, outl2;
148 149
149 printf("Testing cipher %s%s\n", EVP_CIPHER_name(c), 150 printf("Testing cipher %s%s\n", EVP_CIPHER_name(c),
@@ -160,8 +161,12 @@ test1(const EVP_CIPHER *c, const unsigned char *key, int kn,
160 test1_exit(5); 161 test1_exit(5);
161 } 162 }
162 EVP_CIPHER_CTX_init(&ctx); 163 EVP_CIPHER_CTX_init(&ctx);
164 EVP_CIPHER_CTX_set_flags(&ctx, EVP_CIPHER_CTX_FLAG_WRAP_ALLOW);
163 if (encdec != 0) { 165 if (encdec != 0) {
164 if (!EVP_EncryptInit_ex(&ctx, c,NULL, key, iv)) { 166 eiv = iv;
167 if (EVP_CIPHER_mode(c) == EVP_CIPH_WRAP_MODE && in == 0)
168 eiv = NULL;
169 if (!EVP_EncryptInit_ex(&ctx, c, NULL, key, eiv)) {
165 fprintf(stderr, "EncryptInit failed\n"); 170 fprintf(stderr, "EncryptInit failed\n");
166 ERR_print_errors_fp(stderr); 171 ERR_print_errors_fp(stderr);
167 test1_exit(10); 172 test1_exit(10);
@@ -194,7 +199,10 @@ test1(const EVP_CIPHER *c, const unsigned char *key, int kn,
194 } 199 }
195 200
196 if (encdec <= 0) { 201 if (encdec <= 0) {
197 if (!EVP_DecryptInit_ex(&ctx, c,NULL, key, iv)) { 202 eiv = iv;
203 if (EVP_CIPHER_mode(c) == EVP_CIPH_WRAP_MODE && in == 0)
204 eiv = NULL;
205 if (!EVP_DecryptInit_ex(&ctx, c,NULL, key, eiv)) {
198 fprintf(stderr, "DecryptInit failed\n"); 206 fprintf(stderr, "DecryptInit failed\n");
199 ERR_print_errors_fp(stderr); 207 ERR_print_errors_fp(stderr);
200 test1_exit(11); 208 test1_exit(11);
diff --git a/src/regress/lib/libcrypto/evp/evptests.txt b/src/regress/lib/libcrypto/evp/evptests.txt
index fd2c6cdfd1..3c133dba9c 100644
--- a/src/regress/lib/libcrypto/evp/evptests.txt
+++ b/src/regress/lib/libcrypto/evp/evptests.txt
@@ -1,4 +1,4 @@
1# $OpenBSD: evptests.txt,v 1.5 2018/07/17 17:06:49 tb Exp $ 1# $OpenBSD: evptests.txt,v 1.6 2019/03/17 18:33:01 tb Exp $
2#cipher:key:iv:plaintext:ciphertext:0/1(decrypt/encrypt) 2#cipher:key:iv:plaintext:ciphertext:0/1(decrypt/encrypt)
3#digest:::input:output 3#digest:::input:output
4 4
@@ -184,6 +184,13 @@ aes-256-ctr:776BEFF2851DB06F4C8A0542C8696F6C6A81AF1EEC96B4D37FC1D689E6C1C104:000
184aes-256-ctr:F6D66D6BD52D59BB0796365879EFF886C66DD51A5B6A99744B50590C87A23884:00FAAC24C1585EF15A43D87500000001:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F:F05E231B3894612C49EE000B804EB2A9B8306B508F839D6A5530831D9344AF1C:1 184aes-256-ctr:F6D66D6BD52D59BB0796365879EFF886C66DD51A5B6A99744B50590C87A23884:00FAAC24C1585EF15A43D87500000001:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F:F05E231B3894612C49EE000B804EB2A9B8306B508F839D6A5530831D9344AF1C:1
185aes-256-ctr:FF7A617CE69148E4F1726E2F43581DE2AA62D9F805532EDFF1EED687FB54153D:001CC5B751A51D70A1C1114800000001:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F20212223:EB6C52821D0BBBF7CE7594462ACA4FAAB407DF866569FD07F48CC0B583D6071F1EC0E6B8:1 185aes-256-ctr:FF7A617CE69148E4F1726E2F43581DE2AA62D9F805532EDFF1EED687FB54153D:001CC5B751A51D70A1C1114800000001:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F20212223:EB6C52821D0BBBF7CE7594462ACA4FAAB407DF866569FD07F48CC0B583D6071F1EC0E6B8:1
186 186
187# AES wrap tests from RFC3394
188id-aes128-wrap:000102030405060708090A0B0C0D0E0F::00112233445566778899AABBCCDDEEFF:1FA68B0A8112B447AEF34BD8FB5A7B829D3E862371D2CFE5
189id-aes192-wrap:000102030405060708090A0B0C0D0E0F1011121314151617::00112233445566778899AABBCCDDEEFF:96778B25AE6CA435F92B5B97C050AED2468AB8A17AD84E5D
190id-aes256-wrap:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F::00112233445566778899AABBCCDDEEFF:64E8C3F9CE0F5BA263E9777905818A2A93C8191E7D6E8AE7
191id-aes192-wrap:000102030405060708090A0B0C0D0E0F1011121314151617::00112233445566778899AABBCCDDEEFF0001020304050607:031D33264E15D33268F24EC260743EDCE1C6C7DDEE725A936BA814915C6762D2
192id-aes256-wrap:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F::00112233445566778899AABBCCDDEEFF0001020304050607:A8F9BC1612C68B3FF6E6F4FBE30E71E4769C8B80A32CB8958CD5D17D6B254DA1
193id-aes256-wrap:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F::00112233445566778899AABBCCDDEEFF000102030405060708090A0B0C0D0E0F:28C9F404C4B810F4CBCCB35CFB87F8263F5786E2D80ED326CBC7F0E71A99F43BFB988B9B7A02DD21
187# DES ECB tests (from destest) 194# DES ECB tests (from destest)
188 195
189DES-ECB:0000000000000000::0000000000000000:8CA64DE9C1B123A7 196DES-ECB:0000000000000000::0000000000000000:8CA64DE9C1B123A7