summaryrefslogtreecommitdiffstats
path: root/test/recipes/20-test_pkeyutl.t
blob: a0511388e322563144e8ecae5a85e88150403dd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#! /usr/bin/env perl
# Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the Apache License 2.0 (the "License").  You may not use
# this file except in compliance with the License.  You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html

use strict;
use warnings;

use File::Spec;
use OpenSSL::Test qw/:DEFAULT srctop_file/;
use OpenSSL::Test::Utils;

setup("test_pkeyutl");

plan tests => 2;

sub sign
{
    # Utilize the sm2.crt as the TBS file
    return run(app(([ 'openssl', 'pkeyutl', '-sign',
                      '-in', srctop_file('test', 'certs', 'sm2.crt'),
                      '-inkey', srctop_file('test', 'certs', 'sm2.key'),
                      '-out', 'signature.sm2', '-rawin',
                      '-digest', 'sm3', '-pkeyopt', 'sm2_id:someid'])));
}

sub verify
{
    # Utilize the sm2.crt as the TBS file
    return run(app(([ 'openssl', 'pkeyutl', '-verify', '-certin',
                      '-in', srctop_file('test', 'certs', 'sm2.crt'),
                      '-inkey', srctop_file('test', 'certs', 'sm2.crt'),
                      '-sigfile', 'signature.sm2', '-rawin',
                      '-digest', 'sm3', '-pkeyopt', 'sm2_id:someid'])));
}

ok(sign, "Sign a piece of data using SM2");
ok(verify, "Verify an SM2 signature against a piece of data");

unlink 'signature.sm2';