15-test_gendsa.t 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 => 8;
  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', '-algorithm', 'DSA',
  34. '-pkeyopt', 'type:group',
  35. '-text'])),
  36. "genpkey DSA does not support groups");
  37. ok(run(app([ 'openssl', 'genpkey', '-genparam',
  38. '-algorithm', 'DSA',
  39. '-pkeyopt', 'gindex:1',
  40. '-pkeyopt', 'type:fips186_4',
  41. '-out', 'dsagen.pem'])),
  42. "genpkey DSA params fips186_4 PEM");
  43. ok(run(app([ 'openssl', 'genpkey', '-genparam',
  44. '-algorithm', 'DSA',
  45. '-pkeyopt', 'gindex:1',
  46. '-pkeyopt', 'pbits:2048',
  47. '-pkeyopt', 'qbits:256',
  48. '-pkeyopt', 'type:fips186_4',
  49. '-outform', 'DER',
  50. '-out', 'dsagen.der'])),
  51. "genpkey DSA params fips186_4 DER");
  52. # The seed and counter should be the ones generated from the param generation
  53. # Just put some dummy ones in to show it works.
  54. ok(run(app([ 'openssl', 'genpkey',
  55. '-paramfile', 'dsagen.der',
  56. '-pkeyopt', 'gindex:1',
  57. '-pkeyopt', 'hexseed:0102030405060708090A0B0C0D0E0F1011121314',
  58. '-pkeyopt', 'pcounter:25',
  59. '-text'])),
  60. "genpkey DSA fips186_4 with DER params");
  61. ok(!run(app([ 'openssl', 'genpkey',
  62. '-algorithm', 'DSA'])),
  63. "genpkey DSA with no params should fail");