2 # Copyright 2017-2020 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the Apache License 2.0 (the "License"). You may not use
5 # this file except in compliance with the License. You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
14 use OpenSSL::Test qw/:DEFAULT srctop_file/;
15 use OpenSSL::Test::Utils;
17 # 'supported' and 'unsupported' reflect the current state of things. In
18 # Test::More terms, 'supported' works exactly like ok(run(whatever)), while
19 # 'unsupported' wraps that in a TODO: { } block.
21 # The first argument is the test name (this becomes the last argument to
23 # The remaining argument are passed unchecked to 'run'.
25 # 1: the result of app() or similar, i.e. something you can pass to
35 local $TODO = "Currently not supported";
44 plan skip_all => "This test is unsupported in a no-ec build"
47 my @prime_curves = qw(
68 wap-wsg-idm-ecid-wtls6
69 wap-wsg-idm-ecid-wtls7
70 wap-wsg-idm-ecid-wtls8
71 wap-wsg-idm-ecid-wtls9
72 wap-wsg-idm-ecid-wtls12
89 my @binary_curves = qw(
124 wap-wsg-idm-ecid-wtls1
125 wap-wsg-idm-ecid-wtls3
126 wap-wsg-idm-ecid-wtls4
127 wap-wsg-idm-ecid-wtls5
128 wap-wsg-idm-ecid-wtls10
129 wap-wsg-idm-ecid-wtls11
134 my @other_curves = ();
135 push(@other_curves, 'SM2')
138 my @curve_aliases = qw(
145 push(@curve_aliases, qw(
156 )) if !disabled("ec2m");
159 push(@curve_list, @prime_curves);
160 push(@curve_list, @binary_curves)
161 if !disabled("ec2m");
162 push(@curve_list, @other_curves);
163 push(@curve_list, @curve_aliases);
165 my %params_encodings =
167 'named_curve' => \&supported,
168 'explicit' => \&unsupported
171 my @output_formats = ('PEM', 'DER');
173 plan tests => scalar(@curve_list) * scalar(keys %params_encodings)
174 * (1 + scalar(@output_formats)) # Try listed @output_formats and text output
175 + 1 # Checking that with no curve it fails
176 + 1 # Checking that with unknown curve it fails
179 foreach my $curvename (@curve_list) {
180 foreach my $paramenc (sort keys %params_encodings) {
181 my $fn = $params_encodings{$paramenc};
182 $fn->("genpkey EC params ${curvename} with ec_param_enc:'${paramenc}' (text)",
183 app([ 'openssl', 'genpkey',
185 '-pkeyopt', 'ec_paramgen_curve:'.$curvename,
186 '-pkeyopt', 'ec_param_enc:'.$paramenc,
189 foreach my $outform (@output_formats) {
190 my $outfile = "ecgen.${curvename}.${paramenc}." . lc $outform;
191 $fn->("genpkey EC params ${curvename} with ec_param_enc:'${paramenc}' (${outform})",
192 app([ 'openssl', 'genpkey', '-genparam',
194 '-pkeyopt', 'ec_paramgen_curve:'.$curvename,
195 '-pkeyopt', 'ec_param_enc:'.$paramenc,
196 '-outform', $outform,
202 ok(!run(app([ 'openssl', 'genpkey',
203 '-algorithm', 'EC'])),
204 "genpkey EC with no params should fail");
206 ok(!run(app([ 'openssl', 'genpkey',
208 '-pkeyopt', 'ec_paramgen_curve:bogus_foobar_curve'])),
209 "genpkey EC with unknown curve name should fail");