]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
apps: test ec app -param_enc option
authorJakub Zelenka <jakub.zelenka@openssl.foundation>
Tue, 30 Jun 2026 17:14:23 +0000 (19:14 +0200)
committerTomas Mraz <tomas@openssl.foundation>
Mon, 13 Jul 2026 15:00:15 +0000 (17:00 +0200)
Exercise the previously untested -param_enc option of the ec app,
covering named_curve and explicit parameter encodings (compared
against checked-in reference encodings) as well as rejection of an
invalid value.

Assisted-by: Claude:claude-opus-4-8
Reviewed-by: Matt Caswell <matt@openssl.foundation>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.foundation>
MergeDate: Mon Jul 13 15:00:25 2026
(Merged from https://github.com/openssl/openssl/pull/31799)

test/recipes/15-test_ec.t
test/recipes/15-test_ec_data/ec-param-explicit.der [new file with mode: 0644]
test/recipes/15-test_ec_data/ec-param-named.der [new file with mode: 0644]

index 5ae3943cb647bd0fb248489b4695192b288725c2..5b0a69f0cab524af49e4547c71e68d210fdba3fd 100644 (file)
@@ -19,7 +19,7 @@ setup("test_ec");
 
 plan skip_all => 'EC is not supported in this build' if disabled('ec');
 
-plan tests => 17;
+plan tests => 18;
 
 my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
 
@@ -128,6 +128,30 @@ subtest 'EC point conversion form (-conv_form)' => sub {
        "an invalid conversion form is rejected");
 };
 
+subtest 'EC parameter encoding (-param_enc)' => sub {
+    plan tests => 6;
+
+    my $key = srctop_file("test", "testec-p256.pem");
+
+    ok(run(app(['openssl', 'ec', '-in', $key, '-pubout', '-param_enc',
+                'named_curve', '-outform', 'DER', '-out', 'ec-param-named.der'])),
+       "writing public key with named_curve parameter encoding");
+    ok(run(app(['openssl', 'ec', '-in', $key, '-pubout', '-param_enc',
+                'explicit', '-outform', 'DER', '-out', 'ec-param-explicit.der'])),
+       "writing public key with explicit parameter encoding");
+    ok((-s 'ec-param-named.der') < (-s 'ec-param-explicit.der'),
+       "named_curve encoding is smaller than explicit");
+    # The encodings are deterministic for a fixed key, so compare them
+    # against the checked-in reference files.
+    is(compare('ec-param-named.der', data_file('ec-param-named.der')), 0,
+       "named_curve encoding matches the reference file");
+    is(compare('ec-param-explicit.der', data_file('ec-param-explicit.der')), 0,
+       "explicit encoding matches the reference file");
+    ok(!run(app(['openssl', 'ec', '-in', $key, '-noout',
+                 '-param_enc', 'bogus'])),
+       "an invalid parameter encoding is rejected");
+};
+
 subtest 'Check loading of fips and non-fips keys' => sub {
     plan skip_all => "FIPS is disabled"
         if $no_fips;
diff --git a/test/recipes/15-test_ec_data/ec-param-explicit.der b/test/recipes/15-test_ec_data/ec-param-explicit.der
new file mode 100644 (file)
index 0000000..e29a3a7
Binary files /dev/null and b/test/recipes/15-test_ec_data/ec-param-explicit.der differ
diff --git a/test/recipes/15-test_ec_data/ec-param-named.der b/test/recipes/15-test_ec_data/ec-param-named.der
new file mode 100644 (file)
index 0000000..7a75bb5
Binary files /dev/null and b/test/recipes/15-test_ec_data/ec-param-named.der differ