threads_pthread.c: change inline to ossl_inline
[openssl.git] / test / recipes / 15-test_gendsa.t
1 #! /usr/bin/env perl
2 # Copyright 2017-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 File::Spec;
14 use OpenSSL::Test qw/:DEFAULT srctop_file srctop_dir bldtop_dir bldtop_file/;
15 use OpenSSL::Test::Utils;
16
17 BEGIN {
18     setup("test_gendsa");
19 }
20
21 use lib srctop_dir('Configurations');
22 use lib bldtop_dir('.');
23 use platform;
24
25 plan skip_all => "This test is unsupported in a no-dsa build"
26     if disabled("dsa");
27
28 my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
29
30 plan tests =>
31     ($no_fips ? 0 : 3)          # FIPS install test + fips related tests
32     + 11;
33
34 ok(run(app([ 'openssl', 'genpkey', '-genparam',
35              '-algorithm', 'DSA',
36              '-pkeyopt', 'gindex:1',
37              '-pkeyopt', 'type:fips186_4',
38              '-text'])),
39    "genpkey DSA params fips186_4 with verifiable g");
40
41 ok(run(app([ 'openssl', 'genpkey', '-genparam',
42              '-algorithm', 'DSA',
43              '-pkeyopt', 'type:fips186_4',
44              '-text'])),
45    "genpkey DSA params fips186_4 with unverifiable g");
46
47 ok(run(app([ 'openssl', 'genpkey', '-genparam',
48              '-algorithm', 'DSA',
49              '-pkeyopt', 'pbits:2048',
50              '-pkeyopt', 'qbits:224',
51              '-pkeyopt', 'digest:SHA512-256',
52              '-pkeyopt', 'type:fips186_4'])),
53    "genpkey DSA params fips186_4 with truncated SHA");
54
55 ok(run(app([ 'openssl', 'genpkey', '-genparam',
56              '-algorithm', 'DSA',
57              '-pkeyopt', 'type:fips186_2',
58              '-text'])),
59    "genpkey DSA params fips186_2");
60
61 ok(run(app([ 'openssl', 'genpkey', '-genparam',
62              '-algorithm', 'DSA',
63              '-pkeyopt', 'type:fips186_2',
64              '-pkeyopt', 'dsa_paramgen_bits:1024',
65              '-out', 'dsagen.legacy.pem'])),
66    "genpkey DSA params fips186_2 PEM");
67
68 ok(!run(app([ 'openssl', 'genpkey', '-algorithm', 'DSA',
69              '-pkeyopt', 'type:group',
70              '-text'])),
71    "genpkey DSA does not support groups");
72
73 ok(run(app([ 'openssl', 'genpkey', '-genparam',
74              '-algorithm', 'DSA',
75              '-pkeyopt', 'gindex:1',
76              '-pkeyopt', 'type:fips186_4',
77              '-out', 'dsagen.pem'])),
78    "genpkey DSA params fips186_4 PEM");
79
80 ok(run(app([ 'openssl', 'genpkey', '-genparam',
81              '-algorithm', 'DSA',
82              '-pkeyopt', 'gindex:1',
83              '-pkeyopt', 'pbits:2048',
84              '-pkeyopt', 'qbits:256',
85              '-pkeyopt', 'type:fips186_4',
86              '-outform', 'DER',
87              '-out', 'dsagen.der'])),
88    "genpkey DSA params fips186_4 DER");
89
90 ok(run(app([ 'openssl', 'genpkey',
91              '-paramfile', 'dsagen.legacy.pem',
92              '-pkeyopt', 'type:fips186_2',
93              '-text'])),
94    "genpkey DSA fips186_2 with PEM params");
95
96 # The seed and counter should be the ones generated from the param generation
97 # Just put some dummy ones in to show it works.
98 ok(run(app([ 'openssl', 'genpkey',
99              '-paramfile', 'dsagen.der',
100              '-pkeyopt', 'type:fips186_4',
101              '-pkeyopt', 'gindex:1',
102              '-pkeyopt', 'hexseed:0102030405060708090A0B0C0D0E0F1011121314',
103              '-pkeyopt', 'pcounter:25',
104              '-text'])),
105    "genpkey DSA fips186_4 with DER params");
106
107 ok(!run(app([ 'openssl', 'genpkey',
108               '-algorithm', 'DSA'])),
109    "genpkey DSA with no params should fail");
110
111 unless ($no_fips) {
112     my $provconf = srctop_file("test", "fips-and-base.cnf");
113     my $provpath = bldtop_dir("providers");
114     my @prov = ( "-provider-path", $provpath,
115                  "-config", $provconf);
116     my $infile = bldtop_file('providers', platform->dso('fips'));
117
118     ok(run(app(['openssl', 'fipsinstall',
119                 '-out', bldtop_file('providers', 'fipsmodule.cnf'),
120                 '-module', $infile,
121                 '-provider_name', 'fips', '-mac_name', 'HMAC',
122                 '-section_name', 'fips_sect'])),
123        "fipsinstall");
124
125     $ENV{OPENSSL_TEST_LIBCTX} = "1";
126
127     # Generate params
128     ok(run(app(['openssl', 'genpkey',
129                 @prov,
130                '-genparam',
131                '-algorithm', 'DSA',
132                '-pkeyopt', 'pbits:3072',
133                '-pkeyopt', 'qbits:256',
134                '-out', 'gendsatest3072params.pem'])),
135        "Generating 3072-bit DSA params");
136
137     # Generate keypair
138     ok(run(app(['openssl', 'genpkey',
139                 @prov,
140                '-paramfile', 'gendsatest3072params.pem',
141                '-text',
142                '-out', 'gendsatest3072.pem'])),
143        "Generating 3072-bit DSA keypair");
144
145 }