VMS: Redefine _XOPEN_SOURCE_EXTENDED with the value 1
[openssl.git] / test / recipes / 15-test_gendh.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/;
15 use OpenSSL::Test::Utils;
16
17 setup("test_gendh");
18
19 plan skip_all => "This test is unsupported in a no-dh build" if disabled("dh");
20
21 plan tests => 13;
22
23 ok(run(app([ 'openssl', 'genpkey', '-genparam',
24              '-algorithm', 'DH',
25              '-pkeyopt', 'gindex:1',
26              '-pkeyopt', 'type:fips186_4',
27              '-text'])),
28    "genpkey DH params fips186_4 with verifiable g");
29
30 ok(run(app([ 'openssl', 'genpkey', '-genparam',
31              '-algorithm', 'DH',
32              '-pkeyopt', 'type:fips186_4',
33              '-text'])),
34    "genpkey DH params fips186_4 with unverifiable g");
35
36 ok(run(app([ 'openssl', 'genpkey', '-genparam',
37              '-algorithm', 'DH',
38              '-pkeyopt', 'pbits:2048',
39              '-pkeyopt', 'qbits:224',
40              '-pkeyopt', 'digest:SHA512-224',
41              '-pkeyopt', 'type:fips186_4'])),
42    "genpkey DH params fips186_4 with truncated SHA");
43
44 ok(run(app([ 'openssl', 'genpkey', '-genparam',
45              '-algorithm', 'DH',
46              '-pkeyopt', 'type:fips186_2',
47              '-text'])),
48    "genpkey DH params fips186_2");
49
50 ok(run(app([ 'openssl', 'genpkey', '-algorithm', 'DH',
51              '-pkeyopt', 'type:group',
52              '-text'])),
53    "genpkey DH default group");
54
55 ok(run(app([ 'openssl', 'genpkey', '-algorithm', 'DH',
56              '-pkeyopt', 'type:group',
57              '-pkeyopt', 'group:ffdhe2048',
58              '-text'])),
59    "genpkey DH group ffdhe2048");
60
61 ok(run(app([ 'openssl', 'genpkey', '-genparam',
62              '-algorithm', 'DH',
63              '-pkeyopt', 'gindex:1',
64              '-pkeyopt', 'type:fips186_4',
65              '-out', 'dhgen.pem' ])),
66    "genpkey DH params fips186_4 PEM");
67
68 # The seed and counter should be the ones generated from the param generation
69 # Just put some dummy ones in to show it works.
70 ok(run(app([ 'openssl', 'genpkey',
71              '-paramfile', 'dhgen.pem',
72              '-pkeyopt', 'gindex:1',
73              '-pkeyopt', 'hexseed:0102030405060708090A0B0C0D0E0F1011121314',
74              '-pkeyopt', 'pcounter:25',
75              '-text' ])),
76    "genpkey DH fips186_4 with PEM params");
77
78  ok(!run(app([ 'openssl', 'genpkey',
79               '-algorithm', 'DH'])),
80    "genpkey DH with no params should fail");
81
82  ok(!run(app([ 'openssl', 'genpkey', '-algorithm', 'DH', '-pkeyopt',
83                'group:ffdhe3072', '-pkeyopt', 'priv_len:255', '-text'])),
84     'genpkey DH with a small private len should fail');
85
86  ok(!run(app([ 'openssl', 'genpkey', '-algorithm', 'DH', '-pkeyopt',
87                'group:ffdhe3072', '-pkeyopt', 'priv_len:3072', '-text'])),
88     'genpkey DH with a large private len should fail');
89
90  ok(run(app([ 'openssl', 'genpkey', '-algorithm', 'DH', '-pkeyopt',
91               'group:ffdhe3072', '-pkeyopt', 'priv_len:256', '-text'])),
92     'genpkey DH with a minimum strength private len');
93
94  ok(run(app([ 'openssl', 'genpkey', '-algorithm', 'DH', '-pkeyopt',
95               'group:ffdhe2048', '-pkeyopt', 'priv_len:224', '-text'])),
96     'genpkey 2048 DH with a minimum strength private len');