2 # Copyright 2015-2021 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;
19 plan skip_all => 'EC is not supported in this build' if disabled('ec');
23 my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
25 require_ok(srctop_file('test','recipes','tconversion.pl'));
27 ok(run(test(["ectest"])), "running ectest");
29 # TODO: remove these when the 'ec' app is removed.
30 # Also consider moving this to the 20-25 test section because it is testing
31 # the command line tool in addition to the algorithm.
32 subtest 'EC conversions -- private key' => sub {
33 tconversion( -type => 'ec', -prefix => 'ec-priv',
34 -in => srctop_file("test","testec-p256.pem") );
36 subtest 'EC conversions -- private key PKCS#8' => sub {
37 tconversion( -type => 'ec', -prefix => 'ec-pkcs8',
38 -in => srctop_file("test","testec-p256.pem"),
41 subtest 'EC conversions -- public key' => sub {
42 tconversion( -type => 'ec', -prefix => 'ec-pub',
43 -in => srctop_file("test","testecpub-p256.pem"),
44 -args => [ "ec", "-pubin", "-pubout" ] );
47 subtest 'PKEY conversions -- private key' => sub {
48 tconversion( -type => 'pkey', -prefix => 'ec-pkey-priv',
49 -in => srctop_file("test","testec-p256.pem") );
51 subtest 'PKEY conversions -- private key PKCS#8' => sub {
52 tconversion( -type => 'pkey', -prefix => 'ec-pkey-pkcs8',
53 -in => srctop_file("test","testec-p256.pem"),
56 subtest 'PKEY conversions -- public key' => sub {
57 tconversion( -type => 'pkey', -prefix => 'ec-pkey-pub',
58 -in => srctop_file("test","testecpub-p256.pem"),
59 -args => [ "pkey", "-pubin", "-pubout" ] );
62 subtest 'Ed25519 conversions -- private key' => sub {
63 tconversion( -type => "pkey", -prefix => "ed25519-pkey-priv",
64 -in => srctop_file("test", "tested25519.pem") );
66 subtest 'Ed25519 conversions -- private key PKCS#8' => sub {
67 tconversion( -type => "pkey", -prefix => "ed25519-pkey-pkcs8",
68 -in => srctop_file("test", "tested25519.pem"),
71 subtest 'Ed25519 conversions -- public key' => sub {
72 tconversion( -type => "pkey", -prefix => "ed25519-pkey-pub",
73 -in => srctop_file("test", "tested25519pub.pem"),
74 -args => ["pkey", "-pubin", "-pubout"] );
76 subtest 'Ed448 conversions -- private key' => sub {
77 tconversion( -type => "pkey", -prefix => "ed448-pkey-priv",
78 -in => srctop_file("test", "tested448.pem") );
80 subtest 'Ed448 conversions -- private key PKCS#8' => sub {
81 tconversion( -type => "pkey", -prefix => "ed448-pkey-pkcs8",
82 -in => srctop_file("test", "tested448.pem"),
85 subtest 'Ed448 conversions -- public key' => sub {
86 tconversion( -type => "pkey", -prefix => "ed448-pkey-pub",
87 -in => srctop_file("test", "tested448pub.pem"),
88 -args => ["pkey", "-pubin", "-pubout"] );
91 subtest 'Check loading of fips and non-fips keys' => sub {
92 plan skip_all => "FIPS is disabled"
97 my $fipsconf = srctop_file("test", "fips-and-base.cnf");
98 $ENV{OPENSSL_CONF} = $fipsconf;
100 ok(!run(app(['openssl', 'pkey',
101 '-check', '-in', srctop_file("test", "testec-p112r1.pem")])),
102 "Checking non-fips curve key fails in FIPS provider");
104 ok(run(app(['openssl', 'pkey',
105 '-provider', 'default',
106 '-propquery', '?fips!=yes',
107 '-check', '-in', srctop_file("test", "testec-p112r1.pem")])),
108 "Checking non-fips curve key succeeds with non-fips property query");
110 delete $ENV{OPENSSL_CONF};