Fix typos found by codespell
[openssl.git] / test / ffc_internal_test.c
index 051a31eac0f4af124c31238c04d2796825c91d45..58064f6dc261ec429c6341d1037167d730f5991c 100644 (file)
@@ -297,7 +297,7 @@ static int ffc_params_validate_pq_test(void)
                                                        &res, NULL)))
         goto err;
 
-    /* Provided seed doesnt produce a valid prime q */
+    /* Provided seed doesn't produce a valid prime q */
     ossl_ffc_params_set_validate_params(&params, dsa_2048_224_sha224_bad_seed,
                                         sizeof(dsa_2048_224_sha224_bad_seed),
                                         dsa_2048_224_sha224_counter);
@@ -510,6 +510,27 @@ static int ffc_public_validate_test(void)
     if (!TEST_true(ossl_ffc_validate_public_key(params, pub, &res)))
         goto err;
 
+    /* Fail if params is NULL */
+    if (!TEST_false(ossl_ffc_validate_public_key(NULL, pub, &res)))
+        goto err;
+    if (!TEST_int_eq(FFC_ERROR_PASSED_NULL_PARAM, res))
+        goto err;
+    res = -1;
+    /* Fail if pubkey is NULL */
+    if (!TEST_false(ossl_ffc_validate_public_key(params, NULL, &res)))
+        goto err;
+    if (!TEST_int_eq(FFC_ERROR_PASSED_NULL_PARAM, res))
+        goto err;
+    res = -1;
+
+    BN_free(params->p);
+    params->p = NULL;
+    /* Fail if params->p is NULL */
+    if (!TEST_false(ossl_ffc_validate_public_key(params, pub, &res)))
+        goto err;
+    if (!TEST_int_eq(FFC_ERROR_PASSED_NULL_PARAM, res))
+        goto err;
+
     ret = 1;
 err:
     DH_free(dh);
@@ -567,6 +588,16 @@ static int ffc_private_validate_test(void)
     if (!TEST_true(ossl_ffc_validate_private_key(params->q, priv, &res)))
         goto err;
 
+    if (!TEST_false(ossl_ffc_validate_private_key(NULL, priv, &res)))
+        goto err;
+    if (!TEST_int_eq(FFC_ERROR_PASSED_NULL_PARAM, res))
+        goto err;
+    res = -1;
+    if (!TEST_false(ossl_ffc_validate_private_key(params->q, NULL, &res)))
+        goto err;
+    if (!TEST_int_eq(FFC_ERROR_PASSED_NULL_PARAM, res))
+        goto err;
+
     ret = 1;
 err:
     DH_free(dh);
@@ -618,6 +649,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 +661,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 +707,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;
 }