diff options
author | slontis <shane.lontis@oracle.com> | 2022-11-15 03:38:31 +0100 |
---|---|---|
committer | Hugo Landau <hlandau@openssl.org> | 2023-05-05 18:11:16 +0200 |
commit | bcd94b6335e37304a170d89977a2382fae370a97 (patch) | |
tree | c3e676015643d7aa82cdf9c6bac1381b0012abda | |
parent | Extend the min/max protocol testing (diff) | |
download | openssl-bcd94b6335e37304a170d89977a2382fae370a97.tar.xz openssl-bcd94b6335e37304a170d89977a2382fae370a97.zip |
Add libctx to x931 keygen.
Added coverage test that failed without the change.
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Todd Short <todd.short@me.com>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/19677)
-rw-r--r-- | crypto/rsa/rsa_x931g.c | 7 | ||||
-rw-r--r-- | test/build.info | 7 | ||||
-rw-r--r-- | test/recipes/15-test_rsa.t | 9 | ||||
-rw-r--r-- | test/rsa_x931_test.c | 48 |
4 files changed, 65 insertions, 6 deletions
diff --git a/crypto/rsa/rsa_x931g.c b/crypto/rsa/rsa_x931g.c index 5a309a98c3..86b4e72f5c 100644 --- a/crypto/rsa/rsa_x931g.c +++ b/crypto/rsa/rsa_x931g.c @@ -31,10 +31,10 @@ int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1, BN_CTX *ctx = NULL, *ctx2 = NULL; int ret = 0; - if (!rsa) + if (rsa == NULL) goto err; - ctx = BN_CTX_new(); + ctx = BN_CTX_new_ex(rsa->libctx); if (ctx == NULL) goto err; BN_CTX_start(ctx); @@ -145,7 +145,6 @@ int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1, BN_CTX_free(ctx2); return ret; - } int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e, @@ -155,7 +154,7 @@ int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e, BIGNUM *Xp = NULL, *Xq = NULL; BN_CTX *ctx = NULL; - ctx = BN_CTX_new(); + ctx = BN_CTX_new_ex(rsa->libctx); if (ctx == NULL) goto error; diff --git a/test/build.info b/test/build.info index 4de1c19d4d..996825c075 100644 --- a/test/build.info +++ b/test/build.info @@ -890,6 +890,13 @@ IF[{- !$disabled{tests} -}] INCLUDE[rsa_sp800_56b_test]=.. ../include ../crypto/rsa ../apps/include DEPEND[rsa_sp800_56b_test]=../libcrypto.a libtestutil.a + IF[{- !$disabled{'deprecated-3.0'} -}] + PROGRAMS{noinst}=rsa_x931_test + SOURCE[rsa_x931_test]=rsa_x931_test.c + INCLUDE[rsa_x931_test]=.. ../include ../apps/include + DEPEND[rsa_x931_test]=../libcrypto.a libtestutil.a + ENDIF + SOURCE[bn_internal_test]=bn_internal_test.c INCLUDE[bn_internal_test]=.. ../include ../crypto/bn ../apps/include DEPEND[bn_internal_test]=../libcrypto.a libtestutil.a diff --git a/test/recipes/15-test_rsa.t b/test/recipes/15-test_rsa.t index 420a57f8c1..c3c0bc34d6 100644 --- a/test/recipes/15-test_rsa.t +++ b/test/recipes/15-test_rsa.t @@ -1,5 +1,5 @@ #! /usr/bin/env perl -# Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 2015-2022 The OpenSSL Project Authors. All Rights Reserved. # # Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy @@ -16,7 +16,7 @@ use OpenSSL::Test::Utils; setup("test_rsa"); -plan tests => 12; +plan tests => 14; require_ok(srctop_file('test', 'recipes', 'tconversion.pl')); @@ -33,6 +33,11 @@ sub run_rsa_tests { "$cmd -check" ); SKIP: { + skip "Skipping Deprecated rsa_x931_test", 1 if disabled("deprecated-3.0"); + ok(run(test(['rsa_x931_test'])), "RSA X931 test"); + }; + + SKIP: { skip "Skipping $cmd conversion test", 3 if disabled("rsa"); diff --git a/test/rsa_x931_test.c b/test/rsa_x931_test.c new file mode 100644 index 0000000000..5f3396a3a0 --- /dev/null +++ b/test/rsa_x931_test.c @@ -0,0 +1,48 @@ +/* + * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include "internal/deprecated.h" + +#include <openssl/rsa.h> +#include <openssl/bn.h> +#include "crypto/rsa.h" +#include "testutil.h" + +static OSSL_PROVIDER *prov_null = NULL; +static OSSL_LIB_CTX *libctx = NULL; + +static int test_rsa_x931_keygen(void) +{ + int ret = 0; + BIGNUM *e = NULL; + RSA *rsa = NULL; + + ret = TEST_ptr(rsa = ossl_rsa_new_with_ctx(libctx)) + && TEST_ptr(e = BN_new()) + && TEST_int_eq(BN_set_word(e, RSA_F4), 1) + && TEST_int_eq(RSA_X931_generate_key_ex(rsa, 1024, e, NULL), 1); + BN_free(e); + RSA_free(rsa); + return ret; +} + +int setup_tests(void) +{ + if (!test_get_libctx(&libctx, &prov_null, NULL, NULL, NULL)) + return 0; + + ADD_TEST(test_rsa_x931_keygen); + return 1; +} + +void cleanup_tests(void) +{ + OSSL_PROVIDER_unload(prov_null); + OSSL_LIB_CTX_free(libctx); +} |