diff options
author | tb <> | 2021-11-18 15:15:31 +0000 |
---|---|---|
committer | tb <> | 2021-11-18 15:15:31 +0000 |
commit | 297740a3ae90ca9e6d3ad4a42ffe8fe3c2859975 (patch) | |
tree | 22f28cc8afc0657be944578b8f5a724106d7b50d /src/regress/lib | |
parent | fcbeafde2ed65c70ea275419a1355e2163c3644e (diff) | |
download | openbsd-297740a3ae90ca9e6d3ad4a42ffe8fe3c2859975.tar.gz openbsd-297740a3ae90ca9e6d3ad4a42ffe8fe3c2859975.tar.bz2 openbsd-297740a3ae90ca9e6d3ad4a42ffe8fe3c2859975.zip |
evptest: fix compilation with opaque EVP_{CIPHER,MD}_CTX. Uses a
workaround for excessive malloc inspired by mariadb (just kidding).
Diffstat (limited to 'src/regress/lib')
-rw-r--r-- | src/regress/lib/libcrypto/evp/evptest.c | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/src/regress/lib/libcrypto/evp/evptest.c b/src/regress/lib/libcrypto/evp/evptest.c index 8dc9fc0bbe..bb9564377c 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.9 2020/01/26 02:46:26 tb Exp $ */ | 1 | /* $OpenBSD: evptest.c,v 1.10 2021/11/18 15:15:31 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. |
@@ -142,7 +142,7 @@ test1(const EVP_CIPHER *c, const unsigned char *key, int kn, | |||
142 | const unsigned char *iv, int in, const unsigned char *plaintext, int pn, | 142 | const unsigned char *iv, int in, const unsigned char *plaintext, int pn, |
143 | const unsigned char *ciphertext, int cn, int encdec) | 143 | const unsigned char *ciphertext, int cn, int encdec) |
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 | const unsigned char *eiv; |
148 | int outl, outl2; | 148 | int outl, outl2; |
@@ -155,30 +155,34 @@ test1(const EVP_CIPHER *c, const unsigned char *key, int kn, | |||
155 | hexdump(stdout, "Plaintext",plaintext,pn); | 155 | hexdump(stdout, "Plaintext",plaintext,pn); |
156 | hexdump(stdout, "Ciphertext",ciphertext,cn); | 156 | hexdump(stdout, "Ciphertext",ciphertext,cn); |
157 | 157 | ||
158 | if (kn != c->key_len) { | 158 | if (kn != EVP_CIPHER_key_length(c)) { |
159 | fprintf(stderr, "Key length doesn't match, got %d expected %lu\n",kn, | 159 | fprintf(stderr, "Key length doesn't match, got %d expected %lu\n",kn, |
160 | (unsigned long)c->key_len); | 160 | (unsigned long)EVP_CIPHER_key_length(c)); |
161 | test1_exit(5); | 161 | test1_exit(5); |
162 | } | 162 | } |
163 | EVP_CIPHER_CTX_init(&ctx); | 163 | if ((ctx = EVP_CIPHER_CTX_new()) == NULL) { |
164 | EVP_CIPHER_CTX_set_flags(&ctx, EVP_CIPHER_CTX_FLAG_WRAP_ALLOW); | 164 | fprintf(stderr, "EVP_CIPHER_CTX_new failed\n"); |
165 | ERR_print_errors_fp(stderr); | ||
166 | test1_exit(12); | ||
167 | } | ||
168 | EVP_CIPHER_CTX_set_flags(ctx, EVP_CIPHER_CTX_FLAG_WRAP_ALLOW); | ||
165 | if (encdec != 0) { | 169 | if (encdec != 0) { |
166 | eiv = iv; | 170 | eiv = iv; |
167 | if (EVP_CIPHER_mode(c) == EVP_CIPH_WRAP_MODE && in == 0) | 171 | if (EVP_CIPHER_mode(c) == EVP_CIPH_WRAP_MODE && in == 0) |
168 | eiv = NULL; | 172 | eiv = NULL; |
169 | if (!EVP_EncryptInit_ex(&ctx, c, NULL, key, eiv)) { | 173 | if (!EVP_EncryptInit_ex(ctx, c, NULL, key, eiv)) { |
170 | fprintf(stderr, "EncryptInit failed\n"); | 174 | fprintf(stderr, "EncryptInit failed\n"); |
171 | ERR_print_errors_fp(stderr); | 175 | ERR_print_errors_fp(stderr); |
172 | test1_exit(10); | 176 | test1_exit(10); |
173 | } | 177 | } |
174 | EVP_CIPHER_CTX_set_padding(&ctx, 0); | 178 | EVP_CIPHER_CTX_set_padding(ctx, 0); |
175 | 179 | ||
176 | if (!EVP_EncryptUpdate(&ctx, out, &outl, plaintext, pn)) { | 180 | if (!EVP_EncryptUpdate(ctx, out, &outl, plaintext, pn)) { |
177 | fprintf(stderr, "Encrypt failed\n"); | 181 | fprintf(stderr, "Encrypt failed\n"); |
178 | ERR_print_errors_fp(stderr); | 182 | ERR_print_errors_fp(stderr); |
179 | test1_exit(6); | 183 | test1_exit(6); |
180 | } | 184 | } |
181 | if (!EVP_EncryptFinal_ex(&ctx, out + outl, &outl2)) { | 185 | if (!EVP_EncryptFinal_ex(ctx, out + outl, &outl2)) { |
182 | fprintf(stderr, "EncryptFinal failed\n"); | 186 | fprintf(stderr, "EncryptFinal failed\n"); |
183 | ERR_print_errors_fp(stderr); | 187 | ERR_print_errors_fp(stderr); |
184 | test1_exit(7); | 188 | test1_exit(7); |
@@ -202,19 +206,19 @@ test1(const EVP_CIPHER *c, const unsigned char *key, int kn, | |||
202 | eiv = iv; | 206 | eiv = iv; |
203 | if (EVP_CIPHER_mode(c) == EVP_CIPH_WRAP_MODE && in == 0) | 207 | if (EVP_CIPHER_mode(c) == EVP_CIPH_WRAP_MODE && in == 0) |
204 | eiv = NULL; | 208 | eiv = NULL; |
205 | if (!EVP_DecryptInit_ex(&ctx, c,NULL, key, eiv)) { | 209 | if (!EVP_DecryptInit_ex(ctx, c,NULL, key, eiv)) { |
206 | fprintf(stderr, "DecryptInit failed\n"); | 210 | fprintf(stderr, "DecryptInit failed\n"); |
207 | ERR_print_errors_fp(stderr); | 211 | ERR_print_errors_fp(stderr); |
208 | test1_exit(11); | 212 | test1_exit(11); |
209 | } | 213 | } |
210 | EVP_CIPHER_CTX_set_padding(&ctx, 0); | 214 | EVP_CIPHER_CTX_set_padding(ctx, 0); |
211 | 215 | ||
212 | if (!EVP_DecryptUpdate(&ctx, out, &outl, ciphertext, cn)) { | 216 | if (!EVP_DecryptUpdate(ctx, out, &outl, ciphertext, cn)) { |
213 | fprintf(stderr, "Decrypt failed\n"); | 217 | fprintf(stderr, "Decrypt failed\n"); |
214 | ERR_print_errors_fp(stderr); | 218 | ERR_print_errors_fp(stderr); |
215 | test1_exit(6); | 219 | test1_exit(6); |
216 | } | 220 | } |
217 | if (!EVP_DecryptFinal_ex(&ctx, out + outl, &outl2)) { | 221 | if (!EVP_DecryptFinal_ex(ctx, out + outl, &outl2)) { |
218 | fprintf(stderr, "DecryptFinal failed\n"); | 222 | fprintf(stderr, "DecryptFinal failed\n"); |
219 | ERR_print_errors_fp(stderr); | 223 | ERR_print_errors_fp(stderr); |
220 | test1_exit(7); | 224 | test1_exit(7); |
@@ -234,7 +238,7 @@ test1(const EVP_CIPHER *c, const unsigned char *key, int kn, | |||
234 | } | 238 | } |
235 | } | 239 | } |
236 | 240 | ||
237 | EVP_CIPHER_CTX_cleanup(&ctx); | 241 | EVP_CIPHER_CTX_free(ctx); |
238 | 242 | ||
239 | printf("\n"); | 243 | printf("\n"); |
240 | } | 244 | } |
@@ -260,7 +264,7 @@ test_digest(const char *digest, const unsigned char *plaintext, int pn, | |||
260 | const unsigned char *ciphertext, unsigned int cn) | 264 | const unsigned char *ciphertext, unsigned int cn) |
261 | { | 265 | { |
262 | const EVP_MD *d; | 266 | const EVP_MD *d; |
263 | EVP_MD_CTX ctx; | 267 | EVP_MD_CTX *ctx; |
264 | unsigned char md[EVP_MAX_MD_SIZE]; | 268 | unsigned char md[EVP_MAX_MD_SIZE]; |
265 | unsigned int mdn; | 269 | unsigned int mdn; |
266 | 270 | ||
@@ -272,23 +276,27 @@ test_digest(const char *digest, const unsigned char *plaintext, int pn, | |||
272 | hexdump(stdout, "Plaintext",plaintext,pn); | 276 | hexdump(stdout, "Plaintext",plaintext,pn); |
273 | hexdump(stdout, "Digest",ciphertext,cn); | 277 | hexdump(stdout, "Digest",ciphertext,cn); |
274 | 278 | ||
275 | EVP_MD_CTX_init(&ctx); | 279 | if ((ctx = EVP_MD_CTX_new()) == NULL) { |
276 | if (!EVP_DigestInit_ex(&ctx, d, NULL)) { | 280 | fprintf(stderr, "EVP_CIPHER_CTX_new failed\n"); |
281 | ERR_print_errors_fp(stderr); | ||
282 | test1_exit(104); | ||
283 | } | ||
284 | if (!EVP_DigestInit_ex(ctx, d, NULL)) { | ||
277 | fprintf(stderr, "DigestInit failed\n"); | 285 | fprintf(stderr, "DigestInit failed\n"); |
278 | ERR_print_errors_fp(stderr); | 286 | ERR_print_errors_fp(stderr); |
279 | exit(100); | 287 | exit(100); |
280 | } | 288 | } |
281 | if (!EVP_DigestUpdate(&ctx, plaintext, pn)) { | 289 | if (!EVP_DigestUpdate(ctx, plaintext, pn)) { |
282 | fprintf(stderr, "DigestUpdate failed\n"); | 290 | fprintf(stderr, "DigestUpdate failed\n"); |
283 | ERR_print_errors_fp(stderr); | 291 | ERR_print_errors_fp(stderr); |
284 | exit(101); | 292 | exit(101); |
285 | } | 293 | } |
286 | if (!EVP_DigestFinal_ex(&ctx, md, &mdn)) { | 294 | if (!EVP_DigestFinal_ex(ctx, md, &mdn)) { |
287 | fprintf(stderr, "DigestFinal failed\n"); | 295 | fprintf(stderr, "DigestFinal failed\n"); |
288 | ERR_print_errors_fp(stderr); | 296 | ERR_print_errors_fp(stderr); |
289 | exit(101); | 297 | exit(101); |
290 | } | 298 | } |
291 | EVP_MD_CTX_cleanup(&ctx); | 299 | EVP_MD_CTX_cleanup(ctx); |
292 | 300 | ||
293 | if (mdn != cn) { | 301 | if (mdn != cn) { |
294 | fprintf(stderr, "Digest length mismatch, got %d expected %d\n",mdn,cn); | 302 | fprintf(stderr, "Digest length mismatch, got %d expected %d\n",mdn,cn); |
@@ -304,7 +312,7 @@ test_digest(const char *digest, const unsigned char *plaintext, int pn, | |||
304 | 312 | ||
305 | printf("\n"); | 313 | printf("\n"); |
306 | 314 | ||
307 | EVP_MD_CTX_cleanup(&ctx); | 315 | EVP_MD_CTX_free(ctx); |
308 | 316 | ||
309 | return 1; | 317 | return 1; |
310 | } | 318 | } |