2
0

15-test_gendh.t 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #! /usr/bin/env perl
  2. # Copyright 2017-2021 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. use strict;
  9. use warnings;
  10. use File::Spec;
  11. use OpenSSL::Test qw/:DEFAULT srctop_file/;
  12. use OpenSSL::Test::Utils;
  13. setup("test_gendh");
  14. plan skip_all => "This test is unsupported in a no-dh build" if disabled("dh");
  15. plan tests => 9;
  16. ok(run(app([ 'openssl', 'genpkey', '-algorithm', 'DH',
  17. '-pkeyopt', 'type:group',
  18. '-text'])),
  19. "genpkey DH default group");
  20. ok(run(app([ 'openssl', 'genpkey', '-algorithm', 'DH',
  21. '-pkeyopt', 'type:group',
  22. '-pkeyopt', 'group:ffdhe2048',
  23. '-text'])),
  24. "genpkey DH group ffdhe2048");
  25. ok(run(app([ 'openssl', 'genpkey', '-genparam',
  26. '-algorithm', 'DHX',
  27. '-pkeyopt', 'gindex:1',
  28. '-pkeyopt', 'type:fips186_4',
  29. '-out', 'dhgen.pem' ])),
  30. "genpkey DH params fips186_4 PEM");
  31. # The seed and counter should be the ones generated from the param generation
  32. # Just put some dummy ones in to show it works.
  33. ok(run(app([ 'openssl', 'genpkey',
  34. '-paramfile', 'dhgen.pem',
  35. '-pkeyopt', 'gindex:1',
  36. '-pkeyopt', 'hexseed:ed2927f2139eb61495d6641efda1243f93ebe482b5bfc2c755a53825',
  37. '-pkeyopt', 'pcounter:25',
  38. '-text' ])),
  39. "genpkey DH fips186_4 with PEM params");
  40. ok(!run(app([ 'openssl', 'genpkey',
  41. '-algorithm', 'DH'])),
  42. "genpkey DH with no params should fail");
  43. ok(!run(app([ 'openssl', 'genpkey', '-algorithm', 'DH', '-pkeyopt',
  44. 'group:ffdhe3072', '-pkeyopt', 'priv_len:255', '-text'])),
  45. 'genpkey DH with a small private len should fail');
  46. ok(!run(app([ 'openssl', 'genpkey', '-algorithm', 'DH', '-pkeyopt',
  47. 'group:ffdhe3072', '-pkeyopt', 'priv_len:3072', '-text'])),
  48. 'genpkey DH with a large private len should fail');
  49. ok(run(app([ 'openssl', 'genpkey', '-algorithm', 'DH', '-pkeyopt',
  50. 'group:ffdhe3072', '-pkeyopt', 'priv_len:256', '-text'])),
  51. 'genpkey DH with a minimum strength private len');
  52. ok(run(app([ 'openssl', 'genpkey', '-algorithm', 'DH', '-pkeyopt',
  53. 'group:ffdhe2048', '-pkeyopt', 'priv_len:224', '-text'])),
  54. 'genpkey 2048 DH with a minimum strength private len');