14575301fac87b5cc49e0ea726e44e796b254a45
[oweals/openssl.git] / test / recipes / 20-test_pkeyutl.t
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
9 use strict;
10 use warnings;
11
12 use File::Spec;
13 use OpenSSL::Test qw/:DEFAULT srctop_file/;
14 use OpenSSL::Test::Utils;
15
16 setup("test_pkeyutl");
17
18 plan tests => 2;
19
20 sub sign
21 {
22     # Utilize the sm2.crt as the TBS file
23     return run(app(([ 'openssl', 'pkeyutl', '-sign',
24                       '-in', srctop_file('test', 'certs', 'sm2.crt'),
25                       '-inkey', srctop_file('test', 'certs', 'sm2.key'),
26                       '-out', 'signature.sm2', '-rawin',
27                       '-digest', 'sm3', '-pkeyopt', 'sm2_id:someid'])));
28 }
29
30 sub verify
31 {
32     # Utilize the sm2.crt as the TBS file
33     return run(app(([ 'openssl', 'pkeyutl', '-verify', '-certin',
34                       '-in', srctop_file('test', 'certs', 'sm2.crt'),
35                       '-inkey', srctop_file('test', 'certs', 'sm2.crt'),
36                       '-sigfile', 'signature.sm2', '-rawin',
37                       '-digest', 'sm3', '-pkeyopt', 'sm2_id:someid'])));
38 }
39
40 SKIP: {
41     skip "Skipping tests that require EC, SM2 or SM3", 2
42         if disabled("ec") || disabled("sm2") || disabled("sm3");
43
44     ok(sign, "Sign a piece of data using SM2");
45     ok(verify, "Verify an SM2 signature against a piece of data");
46 }
47
48 unlink 'signature.sm2';