Blame SOURCES/0015-FIPS-decoded-from-explicit.patch

22d461
diff --git a/crypto/ec/ec_backend.c b/crypto/ec/ec_backend.c
22d461
index bea01fb38f66..48721369ae8f 100644
22d461
--- a/crypto/ec/ec_backend.c
22d461
+++ b/crypto/ec/ec_backend.c
22d461
@@ -318,6 +318,11 @@ int ossl_ec_group_todata(const EC_GROUP *group, OSSL_PARAM_BLD *tmpl,
22d461
         return 0;
22d461
     }
22d461
 
22d461
+    if (!ossl_param_build_set_int(tmpl, params,
22d461
+                                  OSSL_PKEY_PARAM_EC_DECODED_FROM_EXPLICIT_PARAMS,
22d461
+                                  group->decoded_from_explicit_params))
22d461
+        return 0;
22d461
+
22d461
     curve_nid = EC_GROUP_get_curve_name(group);
22d461
 
22d461
     /*
22d461
diff --git a/crypto/ec/ec_lib.c b/crypto/ec/ec_lib.c
22d461
index 6b0591c6c8c7..b1696d93bd6d 100644
22d461
--- a/crypto/ec/ec_lib.c
22d461
+++ b/crypto/ec/ec_lib.c
22d461
@@ -1556,13 +1556,23 @@ EC_GROUP *EC_GROUP_new_from_params(const OSSL_PARAM params[],
22d461
     /* This is the simple named group case */
22d461
     ptmp = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_GROUP_NAME);
22d461
     if (ptmp != NULL) {
22d461
-        group = group_new_from_name(ptmp, libctx, propq);
22d461
-        if (group != NULL) {
22d461
-            if (!ossl_ec_group_set_params(group, params)) {
22d461
-                EC_GROUP_free(group);
22d461
-                group = NULL;
22d461
-            }
22d461
+        int decoded = 0;
22d461
+
22d461
+        if ((group = group_new_from_name(ptmp, libctx, propq)) == NULL)
22d461
+            return NULL;
22d461
+        if (!ossl_ec_group_set_params(group, params)) {
22d461
+            EC_GROUP_free(group);
22d461
+            return NULL;
22d461
+        }
22d461
+
22d461
+        ptmp = OSSL_PARAM_locate_const(params,
22d461
+                                       OSSL_PKEY_PARAM_EC_DECODED_FROM_EXPLICIT_PARAMS);
22d461
+        if (ptmp != NULL && !OSSL_PARAM_get_int(ptmp, &decoded)) {
22d461
+            ERR_raise(ERR_LIB_EC, EC_R_WRONG_CURVE_PARAMETERS);
22d461
+            EC_GROUP_free(group);
22d461
+            return NULL;
22d461
         }
22d461
+        group->decoded_from_explicit_params = decoded > 0;
22d461
         return group;
22d461
     }
22d461
 #ifdef FIPS_MODULE
22d461
@@ -1733,6 +1743,8 @@ EC_GROUP *EC_GROUP_new_from_params(const OSSL_PARAM params[],
22d461
         EC_GROUP_free(group);
22d461
         group = named_group;
22d461
     }
22d461
+    /* We've imported the group from explicit parameters, set it so. */
22d461
+    group->decoded_from_explicit_params = 1;
22d461
     ok = 1;
22d461
  err:
22d461
     if (!ok) {
22d461
diff --git a/doc/man7/EVP_PKEY-EC.pod b/doc/man7/EVP_PKEY-EC.pod
22d461
index eed83237c3b2..ee66a074f889 100644
22d461
--- a/doc/man7/EVP_PKEY-EC.pod
22d461
+++ b/doc/man7/EVP_PKEY-EC.pod
22d461
@@ -70,8 +70,8 @@ I<order> multiplied by the I<cofactor> gives the number of points on the curve.
22d461
 
22d461
 =item  "decoded-from-explicit" (B<OSSL_PKEY_PARAM_EC_DECODED_FROM_EXPLICIT_PARAMS>) <integer>
22d461
 
22d461
-Gets a flag indicating wether the key or parameters were decoded from explicit
22d461
-curve parameters. Set to 1 if so or 0 if a named curve was used.
22d461
+Sets or gets a flag indicating whether the key or parameters were decoded from
22d461
+explicit curve parameters. Set to 1 if so or 0 if a named curve was used.
22d461
 
22d461
 =item "use-cofactor-flag" (B<OSSL_PKEY_PARAM_USE_COFACTOR_ECDH>) <integer>
22d461
 
22d461
diff --git a/providers/implementations/keymgmt/ec_kmgmt.c b/providers/implementations/keymgmt/ec_kmgmt.c
22d461
index 9260d4bf3635..7aed057cac89 100644
22d461
--- a/providers/implementations/keymgmt/ec_kmgmt.c
22d461
+++ b/providers/implementations/keymgmt/ec_kmgmt.c
22d461
@@ -525,7 +525,8 @@ int ec_export(void *keydata, int selection, OSSL_CALLBACK *param_cb,
22d461
     OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_EC_GENERATOR, NULL, 0),            \
22d461
     OSSL_PARAM_BN(OSSL_PKEY_PARAM_EC_ORDER, NULL, 0),                          \
22d461
     OSSL_PARAM_BN(OSSL_PKEY_PARAM_EC_COFACTOR, NULL, 0),                       \
22d461
-    OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_EC_SEED, NULL, 0)
22d461
+    OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_EC_SEED, NULL, 0),                 \
22d461
+    OSSL_PARAM_int(OSSL_PKEY_PARAM_EC_DECODED_FROM_EXPLICIT_PARAMS, NULL)
22d461
 
22d461
 # define EC_IMEXPORTABLE_PUBLIC_KEY                                            \
22d461
     OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_PUB_KEY, NULL, 0)
22d461
diff --git a/test/recipes/25-test_verify.t b/test/recipes/25-test_verify.t
22d461
index 700bbd849c95..ede14864d5ac 100644
22d461
--- a/test/recipes/25-test_verify.t
22d461
+++ b/test/recipes/25-test_verify.t
22d461
@@ -12,7 +12,7 @@ use warnings;
22d461
 
22d461
 use File::Spec::Functions qw/canonpath/;
22d461
 use File::Copy;
22d461
-use OpenSSL::Test qw/:DEFAULT srctop_file ok_nofips with/;
22d461
+use OpenSSL::Test qw/:DEFAULT srctop_file bldtop_dir ok_nofips with/;
22d461
 use OpenSSL::Test::Utils;
22d461
 
22d461
 setup("test_verify");
22d461
@@ -29,7 +29,7 @@ sub verify {
22d461
     run(app([@args]));
22d461
 }
22d461
 
22d461
-plan tests => 160;
22d461
+plan tests => 163;
22d461
 
22d461
 # Canonical success
22d461
 ok(verify("ee-cert", "sslserver", ["root-cert"], ["ca-cert"]),
22d461
@@ -309,6 +309,29 @@ SKIP: {
22d461
               ["ca-cert-ec-named"]),
22d461
         "accept named curve leaf with named curve intermediate");
22d461
 }
22d461
+# Same as above but with base provider used for decoding
22d461
+SKIP: {
22d461
+    my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
22d461
+    skip "EC is not supported or FIPS is disabled", 3
22d461
+        if disabled("ec") || $no_fips;
22d461
+
22d461
+    my $provconf = srctop_file("test", "fips-and-base.cnf");
22d461
+    my $provpath = bldtop_dir("providers");
22d461
+    my @prov = ("-provider-path", $provpath);
22d461
+    $ENV{OPENSSL_CONF} = $provconf;
22d461
+
22d461
+    ok(!verify("ee-cert-ec-explicit", "", ["root-cert"],
22d461
+               ["ca-cert-ec-named"], @prov),
22d461
+        "reject explicit curve leaf with named curve intermediate w/fips");
22d461
+    ok(!verify("ee-cert-ec-named-explicit", "", ["root-cert"],
22d461
+               ["ca-cert-ec-explicit"], @prov),
22d461
+        "reject named curve leaf with explicit curve intermediate w/fips");
22d461
+    ok(verify("ee-cert-ec-named-named", "", ["root-cert"],
22d461
+              ["ca-cert-ec-named"], @prov),
22d461
+        "accept named curve leaf with named curve intermediate w/fips");
22d461
+
22d461
+    delete $ENV{OPENSSL_CONF};
22d461
+}
22d461
 
22d461
 # Depth tests, note the depth limit bounds the number of CA certificates
22d461
 # between the trust-anchor and the leaf, so, for example, with a root->ca->leaf