15-test_gendh.t 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #! /usr/bin/env perl
  2. # Copyright 2017-2020 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 => 12;
  16. ok(run(app([ 'openssl', 'genpkey', '-genparam',
  17. '-algorithm', 'DH',
  18. '-pkeyopt', 'gindex:1',
  19. '-pkeyopt', 'type:fips186_4',
  20. '-text'])),
  21. "genpkey DH params fips186_4 with verifiable g");
  22. ok(run(app([ 'openssl', 'genpkey', '-genparam',
  23. '-algorithm', 'DH',
  24. '-pkeyopt', 'type:fips186_4',
  25. '-text'])),
  26. "genpkey DH params fips186_4 with unverifiable g");
  27. ok(run(app([ 'openssl', 'genpkey', '-genparam',
  28. '-algorithm', 'DH',
  29. '-pkeyopt', 'type:fips186_2',
  30. '-text'])),
  31. "genpkey DH params fips186_2");
  32. ok(run(app([ 'openssl', 'genpkey', '-algorithm', 'DH',
  33. '-pkeyopt', 'type:group',
  34. '-text'])),
  35. "genpkey DH default group");
  36. ok(run(app([ 'openssl', 'genpkey', '-algorithm', 'DH',
  37. '-pkeyopt', 'type:group',
  38. '-pkeyopt', 'group:ffdhe2048',
  39. '-text'])),
  40. "genpkey DH group ffdhe2048");
  41. ok(run(app([ 'openssl', 'genpkey', '-genparam',
  42. '-algorithm', 'DH',
  43. '-pkeyopt', 'gindex:1',
  44. '-pkeyopt', 'type:fips186_4',
  45. '-out', 'dhgen.pem' ])),
  46. "genpkey DH params fips186_4 PEM");
  47. # The seed and counter should be the ones generated from the param generation
  48. # Just put some dummy ones in to show it works.
  49. ok(run(app([ 'openssl', 'genpkey',
  50. '-paramfile', 'dhgen.pem',
  51. '-pkeyopt', 'gindex:1',
  52. '-pkeyopt', 'hexseed:0102030405060708090A0B0C0D0E0F1011121314',
  53. '-pkeyopt', 'pcounter:25',
  54. '-text' ])),
  55. "genpkey DH fips186_4 with PEM params");
  56. ok(!run(app([ 'openssl', 'genpkey',
  57. '-algorithm', 'DH'])),
  58. "genpkey DH with no params should fail");
  59. ok(!run(app([ 'openssl', 'genpkey', '-algorithm', 'DH', '-pkeyopt',
  60. 'group:ffdhe3072', '-pkeyopt', 'priv_len:255', '-text'])),
  61. 'genpkey DH with a small private len should fail');
  62. ok(!run(app([ 'openssl', 'genpkey', '-algorithm', 'DH', '-pkeyopt',
  63. 'group:ffdhe3072', '-pkeyopt', 'priv_len:3072', '-text'])),
  64. 'genpkey DH with a large private len should fail');
  65. ok(run(app([ 'openssl', 'genpkey', '-algorithm', 'DH', '-pkeyopt',
  66. 'group:ffdhe3072', '-pkeyopt', 'priv_len:256', '-text'])),
  67. 'genpkey DH with a minimum strength private len');
  68. ok(run(app([ 'openssl', 'genpkey', '-algorithm', 'DH', '-pkeyopt',
  69. 'group:ffdhe2048', '-pkeyopt', 'priv_len:224', '-text'])),
  70. 'genpkey 2048 DH with a minimum strength private len');