2020-04-15 23:14:00 +08:00
|
|
|
#! /usr/bin/env perl
|
2020-04-23 20:55:52 +08:00
|
|
|
# Copyright 2017-2020 The OpenSSL Project Authors. All Rights Reserved.
|
2020-04-15 23:14:00 +08:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License 2.0 (the "License"). You may not use
|
|
|
|
# this file except in compliance with the License. You can obtain a copy
|
|
|
|
# in the file LICENSE in the source distribution or at
|
|
|
|
# https://www.openssl.org/source/license.html
|
|
|
|
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use File::Spec;
|
|
|
|
use OpenSSL::Test qw/:DEFAULT srctop_file/;
|
|
|
|
use OpenSSL::Test::Utils;
|
|
|
|
|
|
|
|
setup("test_gendh");
|
|
|
|
|
|
|
|
plan skip_all => "This test is unsupported in a no-dh build" if disabled("dh");
|
|
|
|
|
2021-04-15 16:25:17 +08:00
|
|
|
plan tests => 9;
|
2020-04-15 23:14:00 +08:00
|
|
|
|
|
|
|
ok(run(app([ 'openssl', 'genpkey', '-algorithm', 'DH',
|
|
|
|
'-pkeyopt', 'type:group',
|
|
|
|
'-text'])),
|
|
|
|
"genpkey DH default group");
|
|
|
|
|
|
|
|
ok(run(app([ 'openssl', 'genpkey', '-algorithm', 'DH',
|
|
|
|
'-pkeyopt', 'type:group',
|
|
|
|
'-pkeyopt', 'group:ffdhe2048',
|
|
|
|
'-text'])),
|
|
|
|
"genpkey DH group ffdhe2048");
|
|
|
|
|
|
|
|
ok(run(app([ 'openssl', 'genpkey', '-genparam',
|
2021-04-15 16:25:17 +08:00
|
|
|
'-algorithm', 'DHX',
|
2020-04-15 23:14:00 +08:00
|
|
|
'-pkeyopt', 'gindex:1',
|
|
|
|
'-pkeyopt', 'type:fips186_4',
|
2020-10-29 02:15:40 +08:00
|
|
|
'-out', 'dhgen.pem' ])),
|
2020-04-15 23:14:00 +08:00
|
|
|
"genpkey DH params fips186_4 PEM");
|
|
|
|
|
|
|
|
# The seed and counter should be the ones generated from the param generation
|
|
|
|
# Just put some dummy ones in to show it works.
|
|
|
|
ok(run(app([ 'openssl', 'genpkey',
|
2020-10-29 02:15:40 +08:00
|
|
|
'-paramfile', 'dhgen.pem',
|
2020-04-15 23:14:00 +08:00
|
|
|
'-pkeyopt', 'gindex:1',
|
2021-04-15 16:25:17 +08:00
|
|
|
'-pkeyopt', 'hexseed:ed2927f2139eb61495d6641efda1243f93ebe482b5bfc2c755a53825',
|
2020-04-15 23:14:00 +08:00
|
|
|
'-pkeyopt', 'pcounter:25',
|
2020-10-29 02:15:40 +08:00
|
|
|
'-text' ])),
|
|
|
|
"genpkey DH fips186_4 with PEM params");
|
2020-04-15 23:14:00 +08:00
|
|
|
|
|
|
|
ok(!run(app([ 'openssl', 'genpkey',
|
|
|
|
'-algorithm', 'DH'])),
|
|
|
|
"genpkey DH with no params should fail");
|
2020-04-20 09:07:38 +08:00
|
|
|
|
|
|
|
ok(!run(app([ 'openssl', 'genpkey', '-algorithm', 'DH', '-pkeyopt',
|
|
|
|
'group:ffdhe3072', '-pkeyopt', 'priv_len:255', '-text'])),
|
|
|
|
'genpkey DH with a small private len should fail');
|
|
|
|
|
|
|
|
ok(!run(app([ 'openssl', 'genpkey', '-algorithm', 'DH', '-pkeyopt',
|
|
|
|
'group:ffdhe3072', '-pkeyopt', 'priv_len:3072', '-text'])),
|
|
|
|
'genpkey DH with a large private len should fail');
|
|
|
|
|
|
|
|
ok(run(app([ 'openssl', 'genpkey', '-algorithm', 'DH', '-pkeyopt',
|
|
|
|
'group:ffdhe3072', '-pkeyopt', 'priv_len:256', '-text'])),
|
|
|
|
'genpkey DH with a minimum strength private len');
|
|
|
|
|
|
|
|
ok(run(app([ 'openssl', 'genpkey', '-algorithm', 'DH', '-pkeyopt',
|
|
|
|
'group:ffdhe2048', '-pkeyopt', 'priv_len:224', '-text'])),
|
|
|
|
'genpkey 2048 DH with a minimum strength private len');
|