Add DH keygen to providers
[openssl.git] / test / recipes / 15-test_gendh.t
1 #! /usr/bin/env perl
2 # Copyright 2017-2018 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 => 9;
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', 'type:fips186_2',
39              '-text'])),
40    "genpkey DH params fips186_2");
41
42 ok(run(app([ 'openssl', 'genpkey', '-algorithm', 'DH',
43              '-pkeyopt', 'type:group',
44              '-text'])),
45    "genpkey DH default group");
46
47 ok(run(app([ 'openssl', 'genpkey', '-algorithm', 'DH',
48              '-pkeyopt', 'type:group',
49              '-pkeyopt', 'group:ffdhe2048',
50              '-text'])),
51    "genpkey DH group ffdhe2048");
52
53 ok(run(app([ 'openssl', 'genpkey', '-genparam',
54              '-algorithm', 'DH',
55              '-pkeyopt', 'gindex:1',
56              '-pkeyopt', 'type:fips186_4',
57              '-out', 'dhgen.pem'])),
58    "genpkey DH params fips186_4 PEM");
59
60 ok(run(app([ 'openssl', 'genpkey', '-genparam',
61              '-algorithm', 'DH',
62              '-pkeyopt', 'gindex:1',
63              '-pkeyopt', 'pbits:2048',
64              '-pkeyopt', 'qbits:256',
65              '-pkeyopt', 'type:fips186_4',
66              '-outform', 'DER',
67              '-out', 'dhgen.der'])),
68    "genpkey DH params fips186_4 DER");
69
70 # The seed and counter should be the ones generated from the param generation
71 # Just put some dummy ones in to show it works.
72 ok(run(app([ 'openssl', 'genpkey',
73              '-paramfile', 'dhgen.der',
74              '-pkeyopt', 'gindex:1',
75              '-pkeyopt', 'hexseed:0102030405060708090A0B0C0D0E0F1011121314',
76              '-pkeyopt', 'pcounter:25',
77              '-text'])),
78    "genpkey DH fips186_4 with DER params");
79
80  ok(!run(app([ 'openssl', 'genpkey',
81               '-algorithm', 'DH'])),
82    "genpkey DH with no params should fail");
83