20-test_pkeyutl.t 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #! /usr/bin/env perl
  2. # Copyright 2018 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 ok_nofips/;
  12. use OpenSSL::Test::Utils;
  13. setup("test_pkeyutl");
  14. plan tests => 6;
  15. # For the tests below we use the cert itself as the TBS file
  16. SKIP: {
  17. skip "Skipping tests that require EC, SM2 or SM3", 2
  18. if disabled("ec") || disabled("sm2") || disabled("sm3");
  19. # SM2
  20. ok_nofips(run(app(([ 'openssl', 'pkeyutl', '-sign',
  21. '-in', srctop_file('test', 'certs', 'sm2.pem'),
  22. '-inkey', srctop_file('test', 'certs', 'sm2.key'),
  23. '-out', 'signature.dat', '-rawin',
  24. '-digest', 'sm3', '-pkeyopt', 'sm2_id:someid']))),
  25. "Sign a piece of data using SM2");
  26. ok_nofips(run(app(([ 'openssl', 'pkeyutl', '-verify', '-certin',
  27. '-in', srctop_file('test', 'certs', 'sm2.pem'),
  28. '-inkey', srctop_file('test', 'certs', 'sm2.pem'),
  29. '-sigfile', 'signature.dat', '-rawin',
  30. '-digest', 'sm3', '-pkeyopt', 'sm2_id:someid']))),
  31. "Verify an SM2 signature against a piece of data");
  32. }
  33. SKIP: {
  34. skip "Skipping tests that require EC", 4
  35. if disabled("ec");
  36. # Ed25519
  37. ok(run(app(([ 'openssl', 'pkeyutl', '-sign', '-in',
  38. srctop_file('test', 'certs', 'server-ed25519-cert.pem'),
  39. '-inkey', srctop_file('test', 'certs', 'server-ed25519-key.pem'),
  40. '-out', 'signature.dat', '-rawin']))),
  41. "Sign a piece of data using Ed25519");
  42. ok(run(app(([ 'openssl', 'pkeyutl', '-verify', '-certin', '-in',
  43. srctop_file('test', 'certs', 'server-ed25519-cert.pem'),
  44. '-inkey', srctop_file('test', 'certs', 'server-ed25519-cert.pem'),
  45. '-sigfile', 'signature.dat', '-rawin']))),
  46. "Verify an Ed25519 signature against a piece of data");
  47. # Ed448
  48. ok(run(app(([ 'openssl', 'pkeyutl', '-sign', '-in',
  49. srctop_file('test', 'certs', 'server-ed448-cert.pem'),
  50. '-inkey', srctop_file('test', 'certs', 'server-ed448-key.pem'),
  51. '-out', 'signature.dat', '-rawin']))),
  52. "Sign a piece of data using Ed448");
  53. ok(run(app(([ 'openssl', 'pkeyutl', '-verify', '-certin', '-in',
  54. srctop_file('test', 'certs', 'server-ed448-cert.pem'),
  55. '-inkey', srctop_file('test', 'certs', 'server-ed448-cert.pem'),
  56. '-sigfile', 'signature.dat', '-rawin']))),
  57. "Verify an Ed448 signature against a piece of data");
  58. }
  59. unlink 'signature.dat';