diff options
author | tb <> | 2022-01-12 09:02:34 +0000 |
---|---|---|
committer | tb <> | 2022-01-12 09:02:34 +0000 |
commit | a9c9dc57789a8445d0103491f394b37aa5f68df5 (patch) | |
tree | 9ddd903ae3be6076ff075c5062a5097d6d2bbc53 /src | |
parent | 72c7c5fb43b3e1245a15a9172c199e07fb003c30 (diff) | |
download | openbsd-a9c9dc57789a8445d0103491f394b37aa5f68df5.tar.gz openbsd-a9c9dc57789a8445d0103491f394b37aa5f68df5.tar.bz2 openbsd-a9c9dc57789a8445d0103491f394b37aa5f68df5.zip |
Rework ecdsatest to build after the bump and link statically for now
Diffstat (limited to 'src')
-rw-r--r-- | src/regress/lib/libcrypto/ecdsa/Makefile | 6 | ||||
-rw-r--r-- | src/regress/lib/libcrypto/ecdsa/ecdsatest.c | 34 |
2 files changed, 26 insertions, 14 deletions
diff --git a/src/regress/lib/libcrypto/ecdsa/Makefile b/src/regress/lib/libcrypto/ecdsa/Makefile index 0c2e26a85e..5cd4c4c87e 100644 --- a/src/regress/lib/libcrypto/ecdsa/Makefile +++ b/src/regress/lib/libcrypto/ecdsa/Makefile | |||
@@ -1,9 +1,9 @@ | |||
1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:52 jsing Exp $ | 1 | # $OpenBSD: Makefile,v 1.4 2022/01/12 09:02:34 tb Exp $ |
2 | 2 | ||
3 | PROG= ecdsatest | 3 | PROG= ecdsatest |
4 | LDADD= -lcrypto | 4 | LDADD= ${CRYPTO_INT} # XXX link dynamically after bump |
5 | DPADD= ${LIBCRYPTO} | 5 | DPADD= ${LIBCRYPTO} |
6 | WARNINGS= Yes | 6 | WARNINGS= Yes |
7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | 7 | CFLAGS+= -DLIBRESSL_INTERNAL -DLIBRESSL_CRYPTO_INTERNAL -Werror |
8 | 8 | ||
9 | .include <bsd.regress.mk> | 9 | .include <bsd.regress.mk> |
diff --git a/src/regress/lib/libcrypto/ecdsa/ecdsatest.c b/src/regress/lib/libcrypto/ecdsa/ecdsatest.c index c73baded43..6d6797ab39 100644 --- a/src/regress/lib/libcrypto/ecdsa/ecdsatest.c +++ b/src/regress/lib/libcrypto/ecdsa/ecdsatest.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ecdsatest.c,v 1.7 2021/11/18 15:12:59 tb Exp $ */ | 1 | /* $OpenBSD: ecdsatest.c,v 1.8 2022/01/12 09:02:34 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Written by Nils Larsch for the OpenSSL project. | 3 | * Written by Nils Larsch for the OpenSSL project. |
4 | */ | 4 | */ |
@@ -103,7 +103,7 @@ x9_62_test_internal(BIO *out, int nid, const char *r_in, const char *s_in) | |||
103 | if ((md_ctx = EVP_MD_CTX_new()) == NULL) | 103 | if ((md_ctx = EVP_MD_CTX_new()) == NULL) |
104 | goto x962_int_err; | 104 | goto x962_int_err; |
105 | /* get the message digest */ | 105 | /* get the message digest */ |
106 | EVP_DigestInit(md_ctx, EVP_ecdsa()); | 106 | EVP_DigestInit(md_ctx, EVP_sha1()); |
107 | EVP_DigestUpdate(md_ctx, (const void*)message, 3); | 107 | EVP_DigestUpdate(md_ctx, (const void*)message, 3); |
108 | EVP_DigestFinal(md_ctx, digest, &dgst_len); | 108 | EVP_DigestFinal(md_ctx, digest, &dgst_len); |
109 | 109 | ||
@@ -127,7 +127,8 @@ x9_62_test_internal(BIO *out, int nid, const char *r_in, const char *s_in) | |||
127 | if (!BN_dec2bn(&r, r_in) || | 127 | if (!BN_dec2bn(&r, r_in) || |
128 | !BN_dec2bn(&s, s_in)) | 128 | !BN_dec2bn(&s, s_in)) |
129 | goto x962_int_err; | 129 | goto x962_int_err; |
130 | if (BN_cmp(signature->r ,r) || BN_cmp(signature->s, s)) | 130 | if (BN_cmp(ECDSA_SIG_get0_r(signature), r) || |
131 | BN_cmp(ECDSA_SIG_get0_s(signature), s)) | ||
131 | goto x962_int_err; | 132 | goto x962_int_err; |
132 | BIO_printf(out, "."); | 133 | BIO_printf(out, "."); |
133 | (void)BIO_flush(out); | 134 | (void)BIO_flush(out); |
@@ -162,6 +163,7 @@ test_builtin(BIO *out) | |||
162 | EC_KEY *eckey = NULL, *wrong_eckey = NULL; | 163 | EC_KEY *eckey = NULL, *wrong_eckey = NULL; |
163 | EC_GROUP *group; | 164 | EC_GROUP *group; |
164 | ECDSA_SIG *ecdsa_sig = NULL; | 165 | ECDSA_SIG *ecdsa_sig = NULL; |
166 | BIGNUM *r = NULL, *s = NULL; | ||
165 | unsigned char digest[20], wrong_digest[20]; | 167 | unsigned char digest[20], wrong_digest[20]; |
166 | unsigned char *signature = NULL; | 168 | unsigned char *signature = NULL; |
167 | const unsigned char *sig_ptr; | 169 | const unsigned char *sig_ptr; |
@@ -301,8 +303,8 @@ test_builtin(BIO *out) | |||
301 | } | 303 | } |
302 | 304 | ||
303 | /* Store the two BIGNUMs in raw_buf. */ | 305 | /* Store the two BIGNUMs in raw_buf. */ |
304 | r_len = BN_num_bytes(ecdsa_sig->r); | 306 | r_len = BN_num_bytes(ECDSA_SIG_get0_r(ecdsa_sig)); |
305 | s_len = BN_num_bytes(ecdsa_sig->s); | 307 | s_len = BN_num_bytes(ECDSA_SIG_get0_s(ecdsa_sig)); |
306 | bn_len = (degree + 7) / 8; | 308 | bn_len = (degree + 7) / 8; |
307 | if ((r_len > bn_len) || (s_len > bn_len)) { | 309 | if ((r_len > bn_len) || (s_len > bn_len)) { |
308 | BIO_printf(out, " failed\n"); | 310 | BIO_printf(out, " failed\n"); |
@@ -311,17 +313,21 @@ test_builtin(BIO *out) | |||
311 | buf_len = 2 * bn_len; | 313 | buf_len = 2 * bn_len; |
312 | if ((raw_buf = calloc(1, buf_len)) == NULL) | 314 | if ((raw_buf = calloc(1, buf_len)) == NULL) |
313 | goto builtin_err; | 315 | goto builtin_err; |
314 | BN_bn2bin(ecdsa_sig->r, raw_buf + bn_len - r_len); | 316 | BN_bn2bin(ECDSA_SIG_get0_r(ecdsa_sig), raw_buf + bn_len - r_len); |
315 | BN_bn2bin(ecdsa_sig->s, raw_buf + buf_len - s_len); | 317 | BN_bn2bin(ECDSA_SIG_get0_s(ecdsa_sig), raw_buf + buf_len - s_len); |
316 | 318 | ||
317 | /* Modify a single byte in the buffer. */ | 319 | /* Modify a single byte in the buffer. */ |
318 | offset = raw_buf[10] % buf_len; | 320 | offset = raw_buf[10] % buf_len; |
319 | dirt = raw_buf[11] ? raw_buf[11] : 1; | 321 | dirt = raw_buf[11] ? raw_buf[11] : 1; |
320 | raw_buf[offset] ^= dirt; | 322 | raw_buf[offset] ^= dirt; |
321 | /* Now read the BIGNUMs back in from raw_buf. */ | 323 | /* Now read the BIGNUMs back in from raw_buf. */ |
322 | if ((BN_bin2bn(raw_buf, bn_len, ecdsa_sig->r) == NULL) || | 324 | if ((r = BN_bin2bn(raw_buf, bn_len, NULL)) == NULL || |
323 | (BN_bin2bn(raw_buf + bn_len, bn_len, ecdsa_sig->s) == NULL)) | 325 | (s = BN_bin2bn(raw_buf + bn_len, bn_len, NULL)) == NULL) |
324 | goto builtin_err; | 326 | goto builtin_err; |
327 | if (!ECDSA_SIG_set0(ecdsa_sig, r, s)) | ||
328 | goto builtin_err; | ||
329 | r = NULL; | ||
330 | s = NULL; | ||
325 | 331 | ||
326 | sig_ptr2 = signature; | 332 | sig_ptr2 = signature; |
327 | sig_len = i2d_ECDSA_SIG(ecdsa_sig, &sig_ptr2); | 333 | sig_len = i2d_ECDSA_SIG(ecdsa_sig, &sig_ptr2); |
@@ -332,9 +338,13 @@ test_builtin(BIO *out) | |||
332 | } | 338 | } |
333 | /* Sanity check: undo the modification and verify signature. */ | 339 | /* Sanity check: undo the modification and verify signature. */ |
334 | raw_buf[offset] ^= dirt; | 340 | raw_buf[offset] ^= dirt; |
335 | if ((BN_bin2bn(raw_buf, bn_len, ecdsa_sig->r) == NULL) || | 341 | if ((r = BN_bin2bn(raw_buf, bn_len, NULL)) == NULL || |
336 | (BN_bin2bn(raw_buf + bn_len, bn_len, ecdsa_sig->s) == NULL)) | 342 | (s = BN_bin2bn(raw_buf + bn_len, bn_len, NULL)) == NULL) |
343 | goto builtin_err; | ||
344 | if (!ECDSA_SIG_set0(ecdsa_sig, r, s)) | ||
337 | goto builtin_err; | 345 | goto builtin_err; |
346 | r = NULL; | ||
347 | s = NULL; | ||
338 | 348 | ||
339 | sig_ptr2 = signature; | 349 | sig_ptr2 = signature; |
340 | sig_len = i2d_ECDSA_SIG(ecdsa_sig, &sig_ptr2); | 350 | sig_len = i2d_ECDSA_SIG(ecdsa_sig, &sig_ptr2); |
@@ -364,6 +374,8 @@ test_builtin(BIO *out) | |||
364 | 374 | ||
365 | ret = 1; | 375 | ret = 1; |
366 | builtin_err: | 376 | builtin_err: |
377 | BN_free(r); | ||
378 | BN_free(s); | ||
367 | EC_KEY_free(eckey); | 379 | EC_KEY_free(eckey); |
368 | EC_KEY_free(wrong_eckey); | 380 | EC_KEY_free(wrong_eckey); |
369 | ECDSA_SIG_free(ecdsa_sig); | 381 | ECDSA_SIG_free(ecdsa_sig); |