15-test_rsax931.t 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #! /usr/bin/env perl
  2. # Copyright 2023 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 OpenSSL::Test qw(:DEFAULT srctop_file);
  11. use OpenSSL::Test::Utils;
  12. BEGIN {
  13. setup("test_rsax931");
  14. }
  15. plan tests => 6;
  16. my $infile = srctop_file("test", "certs", "sm2.key");
  17. my $inkey = srctop_file("test", "testrsa2048.pem");
  18. ok(run(app(['openssl', 'pkeyutl', '-in', $infile, '-rawin', '-inkey', $inkey,
  19. '-digest', 'SHA256',
  20. '-pkeyopt', 'pad-mode:x931',
  21. '-sign',
  22. '-out', 'sigx931.txt'])),
  23. "RSA Sign with x931 padding using SHA256");
  24. ok(run(app(['openssl', 'pkeyutl', '-in', $infile, '-rawin', '-inkey', $inkey,
  25. '-digest', 'SHA256',
  26. '-pkeyopt', 'pad-mode:x931',
  27. '-verify',
  28. '-sigfile', 'sigx931.txt'])),
  29. "RSA Verify with x931 padding using SHA256");
  30. ok(!run(app(['openssl', 'pkeyutl', '-in', $infile, '-rawin', '-inkey', $inkey,
  31. '-digest', 'SHA512',
  32. '-pkeyopt', 'pad-mode:x931',
  33. '-verify',
  34. '-sigfile', 'sigx931.txt'])),
  35. "RSA Verify with x931 padding fails if digest is different");
  36. ok(!run(app(['openssl', 'pkeyutl', '-in', $infile, '-rawin', '-inkey', $inkey,
  37. '-digest', 'SHA512-256',
  38. '-pkeyopt', 'pad-mode:x931',
  39. '-sign'])),
  40. "RSA Sign with x931 padding using unsupported digest should fail");
  41. ok(run(app(['openssl', 'pkeyutl', '-in', $infile, '-rawin', '-inkey', $inkey,
  42. '-digest', 'SHA256',
  43. '-pkeyopt', 'pad-mode:oaep',
  44. '-sign',
  45. '-out', 'sigoaep.txt'])),
  46. "RSA Sign with oaep padding using SHA256");
  47. ok(!run(app(['openssl', 'pkeyutl', '-in', $infile, '-rawin', '-inkey', $inkey,
  48. '-digest', 'SHA256',
  49. '-pkeyopt', 'pad-mode:x931',
  50. '-verify',
  51. '-sigfile', 'sigoaep.txt'])),
  52. "RSA Verify with x931 padding using data signed with oaep padding should fail");