threads_pthread.c: change inline to ossl_inline
[openssl.git] / test / recipes / 30-test_evp.t
1 #! /usr/bin/env perl
2 # Copyright 2015-2020 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 use platform;
23
24 my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
25 my $no_legacy = disabled('legacy') || ($ENV{NO_LEGACY} // 0);
26 my $no_dh = disabled("dh");
27 my $no_dsa = disabled("dsa");
28 my $no_ec = disabled("ec");
29 my $no_gost = disabled("gost");
30 my $no_sm2 = disabled("sm2");
31
32 # Default config depends on if the legacy module is built or not
33 my $defaultcnf = $no_legacy ? 'default.cnf' : 'default-and-legacy.cnf';
34
35 my @configs = ( $defaultcnf );
36 # Only add the FIPS config if the FIPS module has been built
37 push @configs, 'fips-and-base.cnf' unless $no_fips;
38
39 # A list of tests that run with both the default and fips provider.
40 my @files = qw(
41                 evpciph_aes_ccm_cavs.txt
42                 evpciph_aes_common.txt
43                 evpciph_aes_cts.txt
44                 evpciph_aes_wrap.txt
45                 evpciph_des3_common.txt
46                 evpkdf_hkdf.txt
47                 evpkdf_pbkdf2.txt
48                 evpkdf_ss.txt
49                 evpkdf_ssh.txt
50                 evpkdf_tls12_prf.txt
51                 evpkdf_x942.txt
52                 evpkdf_x963.txt
53                 evpmac_common.txt
54                 evpmd_sha.txt
55                 evppbe_pbkdf2.txt
56                 evppkey_kdf_hkdf.txt
57                 evppkey_rsa_common.txt
58                 evprand.txt
59               );
60 push @files, qw(evppkey_ffdhe.txt) unless $no_dh;
61 push @files, qw(evppkey_dsa.txt) unless $no_dsa;
62 push @files, qw(evppkey_ecx.txt) unless $no_ec;
63 push @files, qw(
64                 evppkey_ecc.txt
65                 evppkey_ecdh.txt
66                 evppkey_ecdsa.txt
67                 evppkey_kas.txt
68                 evppkey_mismatch.txt
69               ) unless $no_ec || $no_gost;
70
71 # A list of tests that only run with the default provider
72 # (i.e. The algorithms are not present in the fips provider)
73 my @defltfiles = qw(
74                      evpciph_aes_ocb.txt
75                      evpciph_aes_siv.txt
76                      evpciph_aria.txt 
77                      evpciph_bf.txt
78                      evpciph_camellia.txt
79                      evpciph_cast5.txt
80                      evpciph_chacha.txt
81                      evpciph_des.txt
82                      evpciph_idea.txt
83                      evpciph_rc2.txt
84                      evpciph_rc4.txt
85                      evpciph_rc5.txt
86                      evpciph_seed.txt
87                      evpciph_sm4.txt
88                      evpencod.txt
89                      evpkdf_krb5.txt
90                      evpkdf_scrypt.txt
91                      evpkdf_tls11_prf.txt
92                      evpmac_blake.txt
93                      evpmac_poly1305.txt
94                      evpmac_siphash.txt
95                      evpmd_blake.txt
96                      evpmd_md.txt
97                      evpmd_mdc2.txt
98                      evpmd_ripemd.txt
99                      evpmd_sm3.txt
100                      evpmd_whirlpool.txt
101                      evppbe_scrypt.txt
102                      evppbe_pkcs12.txt
103                      evppkey_kdf_scrypt.txt
104                      evppkey_kdf_tls1_prf.txt
105                      evppkey_rsa.txt
106                     );
107 push @defltfiles, qw(evppkey_brainpool.txt) unless $no_ec;
108 push @defltfiles, qw(evppkey_sm2.txt) unless $no_sm2;
109
110 plan tests =>
111     ($no_fips ? 0 : 1)          # FIPS install test
112     + (scalar(@configs) * scalar(@files))
113     + scalar(@defltfiles)
114     + 3; # error output tests
115
116 unless ($no_fips) {
117     my $infile = bldtop_file('providers', platform->dso('fips'));
118
119     ok(run(app(['openssl', 'fipsinstall',
120                 '-out', bldtop_file('providers', 'fipsmodule.cnf'),
121                 '-module', $infile])),
122        "fipsinstall");
123 }
124
125 foreach (@configs) {
126     my $conf = srctop_file("test", $_);
127
128     foreach my $f ( @files ) {
129         ok(run(test(["evp_test",
130                      "-config", $conf,
131                      data_file("$f")])),
132            "running evp_test -config $conf $f");
133     }
134 }
135
136 my $conf = srctop_file("test", $defaultcnf);
137 foreach my $f ( @defltfiles ) {
138     ok(run(test(["evp_test",
139                  "-config", $conf,
140                  data_file("$f")])),
141        "running evp_test -config $conf $f");
142 }
143
144 sub test_errors { # actually tests diagnostics of OSSL_STORE
145     my ($expected, $key, @opts) = @_;
146     my $infile = srctop_file('test', 'certs', $key);
147     my @args = qw(openssl pkey -in);
148     push(@args, $infile, @opts);
149     my $tmpfile = 'out.txt';
150     my $res = !run(app([@args], stderr => $tmpfile));
151     my $found = 0;
152     open(my $in, '<', $tmpfile) or die "Could not open file $tmpfile";
153     while(<$in>) {
154         print; # this may help debugging
155         $res &&= !m/asn1 encoding/; # output must not include ASN.1 parse errors
156         $found = 1 if m/$expected/; # output must include $expected
157     }
158     close $in;
159     # $tmpfile is kept to help with investigation in case of failure
160     return $res && $found;
161 }
162
163 SKIP: {
164     skip "DSA not disabled", 2 if !disabled("dsa");
165
166     ok(test_errors("unsupported algorithm", "server-dsa-key.pem"),
167        "error loading unsupported dsa private key");
168     ok(test_errors("unsupported algorithm", "server-dsa-pubkey.pem", "-pubin"),
169        "error loading unsupported dsa public key");
170 }
171
172 SKIP: {
173     skip "sm2 not disabled", 1 if !disabled("sm2");
174
175     ok(test_errors("unknown group|unsupported algorithm", "sm2.key"),
176        "error loading unsupported sm2 private key");
177 }