]> git.ipfire.org Git - thirdparty/openssl.git/blob - test/recipes/30-test_evp.t
providers: add Argon2 KDF
[thirdparty/openssl.git] / test / recipes / 30-test_evp.t
1 #! /usr/bin/env perl
2 # Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.
3 #
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
8
9
10 use strict;
11 use warnings;
12
13 use OpenSSL::Test qw(:DEFAULT data_file bldtop_dir srctop_file srctop_dir bldtop_file);
14 use OpenSSL::Test::Utils;
15
16 BEGIN {
17 setup("test_evp");
18 }
19
20 use lib srctop_dir('Configurations');
21 use lib bldtop_dir('.');
22
23 my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
24 my $no_legacy = disabled('legacy') || ($ENV{NO_LEGACY} // 0);
25 my $no_des = disabled("des");
26 my $no_dh = disabled("dh");
27 my $no_dsa = disabled("dsa");
28 my $no_ec = disabled("ec");
29 my $no_ec2m = disabled("ec2m");
30 my $no_sm2 = disabled("sm2");
31 my $no_siv = disabled("siv");
32 my $no_argon2 = disabled("argon2");
33
34 # Default config depends on if the legacy module is built or not
35 my $defaultcnf = $no_legacy ? 'default.cnf' : 'default-and-legacy.cnf';
36
37 my @configs = ( $defaultcnf );
38 # Only add the FIPS config if the FIPS module has been built
39 push @configs, 'fips-and-base.cnf' unless $no_fips;
40
41 # A list of tests that run with both the default and fips provider.
42 my @files = qw(
43 evpciph_aes_ccm_cavs.txt
44 evpciph_aes_common.txt
45 evpciph_aes_cts.txt
46 evpciph_aes_wrap.txt
47 evpciph_aes_stitched.txt
48 evpciph_des3_common.txt
49 evpkdf_hkdf.txt
50 evpkdf_kbkdf_counter.txt
51 evpkdf_kbkdf_kmac.txt
52 evpkdf_pbkdf1.txt
53 evpkdf_pbkdf2.txt
54 evpkdf_ss.txt
55 evpkdf_ssh.txt
56 evpkdf_tls12_prf.txt
57 evpkdf_tls13_kdf.txt
58 evpkdf_x942.txt
59 evpkdf_x963.txt
60 evpmac_common.txt
61 evpmd_sha.txt
62 evppbe_pbkdf2.txt
63 evppkey_kdf_hkdf.txt
64 evppkey_rsa_common.txt
65 evprand.txt
66 );
67 push @files, qw(
68 evppkey_ffdhe.txt
69 evppkey_dh.txt
70 ) unless $no_dh;
71 push @files, qw(
72 evpkdf_x942_des.txt
73 evpmac_cmac_des.txt
74 ) unless $no_des;
75 push @files, qw(evppkey_dsa.txt) unless $no_dsa;
76 push @files, qw(evppkey_ecx.txt) unless $no_ec;
77 push @files, qw(
78 evppkey_ecc.txt
79 evppkey_ecdh.txt
80 evppkey_ecdsa.txt
81 evppkey_kas.txt
82 evppkey_mismatch.txt
83 ) unless $no_ec;
84
85 # A list of tests that only run with the default provider
86 # (i.e. The algorithms are not present in the fips provider)
87 my @defltfiles = qw(
88 evpciph_aes_ocb.txt
89 evpciph_aria.txt
90 evpciph_bf.txt
91 evpciph_camellia.txt
92 evpciph_camellia_cts.txt
93 evpciph_cast5.txt
94 evpciph_chacha.txt
95 evpciph_des.txt
96 evpciph_idea.txt
97 evpciph_rc2.txt
98 evpciph_rc4.txt
99 evpciph_rc4_stitched.txt
100 evpciph_rc5.txt
101 evpciph_seed.txt
102 evpciph_sm4.txt
103 evpencod.txt
104 evpkdf_krb5.txt
105 evpkdf_scrypt.txt
106 evpkdf_tls11_prf.txt
107 evpkdf_hmac_drbg.txt
108 evpmac_blake.txt
109 evpmac_poly1305.txt
110 evpmac_siphash.txt
111 evpmac_sm3.txt
112 evpmd_blake.txt
113 evpmd_md.txt
114 evpmd_mdc2.txt
115 evpmd_ripemd.txt
116 evpmd_sm3.txt
117 evpmd_whirlpool.txt
118 evppbe_scrypt.txt
119 evppbe_pkcs12.txt
120 evppkey_kdf_scrypt.txt
121 evppkey_kdf_tls1_prf.txt
122 evppkey_rsa.txt
123 );
124 push @defltfiles, qw(evppkey_brainpool.txt) unless $no_ec;
125 push @defltfiles, qw(evppkey_ecdsa_rfc6979.txt) unless $no_ec;
126 push @defltfiles, qw(evppkey_dsa_rfc6979.txt) unless $no_dsa;
127 push @defltfiles, qw(evppkey_sm2.txt) unless $no_sm2;
128 push @defltfiles, qw(evpciph_aes_gcm_siv.txt) unless $no_siv;
129 push @defltfiles, qw(evpciph_aes_siv.txt) unless $no_siv;
130 push @defltfiles, qw(evpkdf_argon2.txt) unless $no_argon2;
131
132 plan tests =>
133 + (scalar(@configs) * scalar(@files))
134 + scalar(@defltfiles)
135 + 3; # error output tests
136
137 foreach (@configs) {
138 my $conf = srctop_file("test", $_);
139
140 foreach my $f ( @files ) {
141 ok(run(test(["evp_test",
142 "-config", $conf,
143 data_file("$f")])),
144 "running evp_test -config $conf $f");
145 }
146 }
147
148 my $conf = srctop_file("test", $defaultcnf);
149 foreach my $f ( @defltfiles ) {
150 ok(run(test(["evp_test",
151 "-config", $conf,
152 data_file("$f")])),
153 "running evp_test -config $conf $f");
154 }
155
156 # test_errors OPTIONS
157 #
158 # OPTIONS may include:
159 #
160 # key => "filename" # expected to be found in $SRCDIR/test/certs
161 # out => "filename" # file to write error strings to
162 # args => [ ... extra openssl pkey args ... ]
163 # expected => regexps to match error lines against
164 sub test_errors { # actually tests diagnostics of OSSL_STORE
165 my %opts = @_;
166 my $infile = srctop_file('test', 'certs', $opts{key});
167 my @args = ( qw(openssl pkey -in), $infile, @{$opts{args} // []} );
168 my $res = !run(app([@args], stderr => $opts{out}));
169 my $found = !exists $opts{expected};
170 open(my $in, '<', $opts{out}) or die "Could not open file $opts{out}";
171 while(my $errline = <$in>) {
172 print $errline; # this may help debugging
173
174 # output must not include ASN.1 parse errors
175 $res &&= $errline !~ m/asn1 encoding/;
176 # output must include what is expressed in $opts{$expected}
177 $found = 1
178 if exists $opts{expected} && $errline =~ m/$opts{expected}/;
179 }
180 close $in;
181 # $tmpfile is kept to help with investigation in case of failure
182 return $res && $found;
183 }
184
185 SKIP: {
186 skip "DSA not disabled", 2 if !disabled("dsa");
187
188 ok(test_errors(key => 'server-dsa-key.pem',
189 out => 'server-dsa-key.err'),
190 "expected error loading unsupported dsa private key");
191 ok(test_errors(key => 'server-dsa-pubkey.pem',
192 out => 'server-dsa-pubkey.err',
193 args => [ '-pubin' ],
194 expected => 'unsupported'),
195 "expected error loading unsupported dsa public key");
196 }
197
198 SKIP: {
199 skip "SM2 not disabled", 1 if !disabled("sm2");
200
201 ok(test_errors(key => 'sm2.key', out => 'sm2.err'),
202 "expected error loading unsupported sm2 private key");
203 }