]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
apps: test ecparam app -param_enc option
authorJakub Zelenka <jakub.zelenka@openssl.foundation>
Tue, 30 Jun 2026 17:21:26 +0000 (19:21 +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 ecparam app
by round-tripping the secp384r1 fixtures between named_curve and
explicit encodings (compared byte for byte against the reference
files), and check that an invalid value is rejected.

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:27 2026
(Merged from https://github.com/openssl/openssl/pull/31799)

test/recipes/15-test_ecparam.t

index 0d7215474515fef6f75764d6297adbf9a85df25b..571c62cf1a0dfd310e193fa0b780fd8542d2d28a 100644 (file)
@@ -30,7 +30,7 @@ if (disabled("sm2")) {
     @valid = grep { !/sm2-.*\.pem/} @valid;
 }
 
-plan tests => 14;
+plan tests => 15;
 
 sub checkload {
     my $files = shift; # List of files
@@ -199,4 +199,29 @@ subtest "Check loading of fips and non-fips params" => sub {
     $ENV{OPENSSL_CONF} = $defaultconf;
 };
 
+subtest "Check ecparam -param_enc converts between named and explicit" => sub {
+    plan tests => 3;
+
+    my $named = data_file('valid', 'secp384r1-named.pem');
+    my $explicit = data_file('valid', 'secp384r1-explicit.pem');
+
+    # The encodings are canonical, so re-encoding a named curve as explicit
+    # (and vice versa) must reproduce the matching reference file byte for byte.
+    my $to_explicit = 'param-explicit.tst';
+    ok(run(app(['openssl', 'ecparam', '-in', $named, '-param_enc', 'explicit',
+                '-out', $to_explicit]))
+       && !compare($to_explicit, $explicit),
+       "named_curve params re-encoded as explicit match the reference file");
+
+    my $to_named = 'param-named.tst';
+    ok(run(app(['openssl', 'ecparam', '-in', $explicit, '-param_enc',
+                'named_curve', '-out', $to_named]))
+       && !compare($to_named, $named),
+       "explicit params re-encoded as named_curve match the reference file");
+
+    ok(!run(app(['openssl', 'ecparam', '-in', $named, '-noout',
+                 '-param_enc', 'bogus'])),
+       "an invalid parameter encoding is rejected");
+};
+
 ok(run(app(['openssl', 'ecparam', '-list_curves'])), "Test -list_curves");