2 # Copyright 2017-2020 The OpenSSL Project Authors. All Rights Reserved.
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
14 use OpenSSL::Test qw/:DEFAULT srctop_file/;
15 use OpenSSL::Test::Utils;
19 plan skip_all => "This test is unsupported in a no-dh build" if disabled("dh");
23 ok(run(app([ 'openssl', 'genpkey', '-genparam',
25 '-pkeyopt', 'gindex:1',
26 '-pkeyopt', 'type:fips186_4',
28 "genpkey DH params fips186_4 with verifiable g");
30 ok(run(app([ 'openssl', 'genpkey', '-genparam',
32 '-pkeyopt', 'type:fips186_4',
34 "genpkey DH params fips186_4 with unverifiable g");
36 ok(run(app([ 'openssl', 'genpkey', '-genparam',
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");
44 ok(run(app([ 'openssl', 'genpkey', '-genparam',
46 '-pkeyopt', 'type:fips186_2',
48 "genpkey DH params fips186_2");
50 ok(run(app([ 'openssl', 'genpkey', '-algorithm', 'DH',
51 '-pkeyopt', 'type:group',
53 "genpkey DH default group");
55 ok(run(app([ 'openssl', 'genpkey', '-algorithm', 'DH',
56 '-pkeyopt', 'type:group',
57 '-pkeyopt', 'group:ffdhe2048',
59 "genpkey DH group ffdhe2048");
61 ok(run(app([ 'openssl', 'genpkey', '-genparam',
63 '-pkeyopt', 'gindex:1',
64 '-pkeyopt', 'type:fips186_4',
65 '-out', 'dhgen.pem' ])),
66 "genpkey DH params fips186_4 PEM");
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',
76 "genpkey DH fips186_4 with PEM params");
78 ok(!run(app([ 'openssl', 'genpkey',
79 '-algorithm', 'DH'])),
80 "genpkey DH with no params should fail");
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');
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');
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');
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');