]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Add libctx to x931 keygen.
authorslontis <shane.lontis@oracle.com>
Tue, 15 Nov 2022 02:38:31 +0000 (12:38 +1000)
committerHugo Landau <hlandau@openssl.org>
Fri, 5 May 2023 16:11:16 +0000 (17:11 +0100)
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)

crypto/rsa/rsa_x931g.c
test/build.info
test/recipes/15-test_rsa.t
test/rsa_x931_test.c [new file with mode: 0644]

index 5a309a98c347292c4882a380686635e0923e9e63..86b4e72f5c3b29deefb84d4be48cc8dcd7dfba7a 100644 (file)
@@ -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;
 
index 4de1c19d4df457e9db61734e738e5591beddb370..996825c07551291f4012cc3ea41fada894e18edf 100644 (file)
@@ -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
index 420a57f8c10d56dbab3a75317bcf9cd406cd8240..c3c0bc34d6de897f97a0972704dca0fbd4cfdedb 100644 (file)
@@ -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'));
 
@@ -32,6 +32,11 @@ sub run_rsa_tests {
     ok(run(app([ 'openssl', $cmd, '-check', '-in', srctop_file('test', 'testrsa.pem'), '-noout'])),
            "$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 (file)
index 0000000..5f3396a
--- /dev/null
@@ -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);
+}