]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
ossl_ffc_params_copy: Copy the keylength too
authorTomas Mraz <tomas@openssl.org>
Thu, 14 Jul 2022 10:32:03 +0000 (12:32 +0200)
committerHugo Landau <hlandau@openssl.org>
Mon, 18 Jul 2022 07:06:17 +0000 (08:06 +0100)
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18480)

crypto/ffc/ffc_params.c
test/ffc_internal_test.c

index 073f661c7c4667831ca24ca148fea11809f5b2d2..fb558f8221f6c81517f5d0430435f40a192e5928 100644 (file)
@@ -196,6 +196,7 @@ int ossl_ffc_params_copy(FFC_PARAMS *dst, const FFC_PARAMS *src)
     dst->h = src->h;
     dst->gindex = src->gindex;
     dst->flags = src->flags;
+    dst->keylength = src->keylength;
     return 1;
 }
 
index 051a31eac0f4af124c31238c04d2796825c91d45..f3df4ab4fdb7c8cec5ba5d494394a3afb42699c4 100644 (file)
@@ -618,6 +618,8 @@ static int ffc_private_gen_test(int index)
                                                  ossl_ifc_ffc_compute_security_bits(BN_num_bits(params->p)),
                                                  priv)))
         goto err;
+    if (!TEST_int_le(BN_num_bits(priv), 225))
+        goto err;
     if (!TEST_true(ossl_ffc_validate_private_key(params->q, priv, &res)))
         goto err;
 
@@ -628,6 +630,37 @@ err:
     BN_CTX_free(ctx);
     return ret;
 }
+
+static int ffc_params_copy_test(void)
+{
+    int ret = 0;
+    DH *dh = NULL;
+    FFC_PARAMS *params, copy;
+
+    ossl_ffc_params_init(&copy);
+
+    if (!TEST_ptr(dh = DH_new_by_nid(NID_ffdhe3072)))
+        goto err;
+    params = ossl_dh_get0_params(dh);
+
+    if (!TEST_int_eq(params->keylength, 275))
+        goto err;
+
+    if (!TEST_true(ossl_ffc_params_copy(&copy, params)))
+        goto err;
+
+    if (!TEST_int_eq(copy.keylength, 275))
+        goto err;
+
+    if (!TEST_true(ossl_ffc_params_cmp(&copy, params, 0)))
+        goto err;
+
+    ret = 1;
+err:
+    ossl_ffc_params_cleanup(&copy);
+    DH_free(dh);
+    return ret;
+}
 #endif /* OPENSSL_NO_DH */
 
 int setup_tests(void)
@@ -643,6 +676,7 @@ int setup_tests(void)
     ADD_TEST(ffc_public_validate_test);
     ADD_TEST(ffc_private_validate_test);
     ADD_ALL_TESTS(ffc_private_gen_test, 10);
+    ADD_TEST(ffc_params_copy_test);
 #endif /* OPENSSL_NO_DH */
     return 1;
 }