2
0

15-test_gendsa.t 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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_gendsa");
  14. plan skip_all => "This test is unsupported in a no-dsa build"
  15. if disabled("dsa");
  16. plan tests => 10;
  17. ok(run(app([ 'openssl', 'genpkey', '-genparam',
  18. '-algorithm', 'DSA',
  19. '-pkeyopt', 'gindex:1',
  20. '-pkeyopt', 'type:fips186_4',
  21. '-text'])),
  22. "genpkey DSA params fips186_4 with verifiable g");
  23. ok(run(app([ 'openssl', 'genpkey', '-genparam',
  24. '-algorithm', 'DSA',
  25. '-pkeyopt', 'type:fips186_4',
  26. '-text'])),
  27. "genpkey DSA params fips186_4 with unverifiable g");
  28. ok(run(app([ 'openssl', 'genpkey', '-genparam',
  29. '-algorithm', 'DSA',
  30. '-pkeyopt', 'type:fips186_2',
  31. '-text'])),
  32. "genpkey DSA params fips186_2");
  33. ok(run(app([ 'openssl', 'genpkey', '-genparam',
  34. '-algorithm', 'DSA',
  35. '-pkeyopt', 'type:fips186_2',
  36. '-pkeyopt', 'dsa_paramgen_bits:1024',
  37. '-out', 'dsagen.legacy.pem'])),
  38. "genpkey DSA params fips186_2 PEM");
  39. ok(!run(app([ 'openssl', 'genpkey', '-algorithm', 'DSA',
  40. '-pkeyopt', 'type:group',
  41. '-text'])),
  42. "genpkey DSA does not support groups");
  43. ok(run(app([ 'openssl', 'genpkey', '-genparam',
  44. '-algorithm', 'DSA',
  45. '-pkeyopt', 'gindex:1',
  46. '-pkeyopt', 'type:fips186_4',
  47. '-out', 'dsagen.pem'])),
  48. "genpkey DSA params fips186_4 PEM");
  49. ok(run(app([ 'openssl', 'genpkey', '-genparam',
  50. '-algorithm', 'DSA',
  51. '-pkeyopt', 'gindex:1',
  52. '-pkeyopt', 'pbits:2048',
  53. '-pkeyopt', 'qbits:256',
  54. '-pkeyopt', 'type:fips186_4',
  55. '-outform', 'DER',
  56. '-out', 'dsagen.der'])),
  57. "genpkey DSA params fips186_4 DER");
  58. ok(run(app([ 'openssl', 'genpkey',
  59. '-paramfile', 'dsagen.legacy.pem',
  60. '-pkeyopt', 'type:fips186_2',
  61. '-text'])),
  62. "genpkey DSA fips186_2 with PEM params");
  63. # The seed and counter should be the ones generated from the param generation
  64. # Just put some dummy ones in to show it works.
  65. ok(run(app([ 'openssl', 'genpkey',
  66. '-paramfile', 'dsagen.der',
  67. '-pkeyopt', 'gindex:1',
  68. '-pkeyopt', 'hexseed:0102030405060708090A0B0C0D0E0F1011121314',
  69. '-pkeyopt', 'pcounter:25',
  70. '-text'])),
  71. "genpkey DSA fips186_4 with DER params");
  72. ok(!run(app([ 'openssl', 'genpkey',
  73. '-algorithm', 'DSA'])),
  74. "genpkey DSA with no params should fail");