2 # Copyright 2017-2021 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', '-algorithm', 'DH',
24 '-pkeyopt', 'type:group',
26 "genpkey DH default group");
28 ok(run(app([ 'openssl', 'genpkey', '-algorithm', 'DH',
29 '-pkeyopt', 'type:group',
30 '-pkeyopt', 'group:ffdhe2048',
32 "genpkey DH group ffdhe2048");
34 ok(run(app([ 'openssl', 'genpkey', '-genparam',
36 '-pkeyopt', 'gindex:1',
37 '-pkeyopt', 'type:fips186_4',
38 '-out', 'dhgen.pem' ])),
39 "genpkey DH params fips186_4 PEM");
41 # The seed and counter should be the ones generated from the param generation
42 # Just put some dummy ones in to show it works.
43 ok(run(app([ 'openssl', 'genpkey',
44 '-paramfile', 'dhgen.pem',
45 '-pkeyopt', 'gindex:1',
46 '-pkeyopt', 'hexseed:ed2927f2139eb61495d6641efda1243f93ebe482b5bfc2c755a53825',
47 '-pkeyopt', 'pcounter:25',
49 "genpkey DH fips186_4 with PEM params");
51 ok(!run(app([ 'openssl', 'genpkey',
52 '-algorithm', 'DH'])),
53 "genpkey DH with no params should fail");
55 ok(!run(app([ 'openssl', 'genpkey', '-algorithm', 'DH', '-pkeyopt',
56 'group:ffdhe3072', '-pkeyopt', 'priv_len:255', '-text'])),
57 'genpkey DH with a small private len should fail');
59 ok(!run(app([ 'openssl', 'genpkey', '-algorithm', 'DH', '-pkeyopt',
60 'group:ffdhe3072', '-pkeyopt', 'priv_len:3072', '-text'])),
61 'genpkey DH with a large private len should fail');
63 ok(run(app([ 'openssl', 'genpkey', '-algorithm', 'DH', '-pkeyopt',
64 'group:ffdhe3072', '-pkeyopt', 'priv_len:256', '-text'])),
65 'genpkey DH with a minimum strength private len');
67 ok(run(app([ 'openssl', 'genpkey', '-algorithm', 'DH', '-pkeyopt',
68 'group:ffdhe2048', '-pkeyopt', 'priv_len:224', '-text'])),
69 'genpkey 2048 DH with a minimum strength private len');