]> git.ipfire.org Git - thirdparty/openssl.git/blob - test/recipes/15-test_rsax931.t
Add Tests for RSA signatures using X931 padding.
[thirdparty/openssl.git] / test / recipes / 15-test_rsax931.t
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
9 use strict;
10 use warnings;
11
12 use OpenSSL::Test qw(:DEFAULT srctop_file);
13 use OpenSSL::Test::Utils;
14
15 BEGIN {
16 setup("test_rsax931");
17 }
18
19 plan tests => 6;
20
21 my $infile = srctop_file("test", "certs", "sm2.key");
22 my $inkey = srctop_file("test", "testrsa2048.pem");
23
24 ok(run(app(['openssl', 'pkeyutl', '-in', $infile, '-rawin', '-inkey', $inkey,
25 '-digest', 'SHA256',
26 '-pkeyopt', 'pad-mode:x931',
27 '-sign',
28 '-out', 'sigx931.txt'])),
29 "RSA Sign with x931 padding using SHA256");
30
31 ok(run(app(['openssl', 'pkeyutl', '-in', $infile, '-rawin', '-inkey', $inkey,
32 '-digest', 'SHA256',
33 '-pkeyopt', 'pad-mode:x931',
34 '-verify',
35 '-sigfile', 'sigx931.txt'])),
36 "RSA Verify with x931 padding using SHA256");
37
38 ok(!run(app(['openssl', 'pkeyutl', '-in', $infile, '-rawin', '-inkey', $inkey,
39 '-digest', 'SHA512',
40 '-pkeyopt', 'pad-mode:x931',
41 '-verify',
42 '-sigfile', 'sigx931.txt'])),
43 "RSA Verify with x931 padding fails if digest is different");
44
45 ok(!run(app(['openssl', 'pkeyutl', '-in', $infile, '-rawin', '-inkey', $inkey,
46 '-digest', 'SHA512-256',
47 '-pkeyopt', 'pad-mode:x931',
48 '-sign'])),
49 "RSA Sign with x931 padding using unsupported digest should fail");
50
51 ok(run(app(['openssl', 'pkeyutl', '-in', $infile, '-rawin', '-inkey', $inkey,
52 '-digest', 'SHA256',
53 '-pkeyopt', 'pad-mode:oaep',
54 '-sign',
55 '-out', 'sigoaep.txt'])),
56 "RSA Sign with oaep padding using SHA256");
57
58 ok(!run(app(['openssl', 'pkeyutl', '-in', $infile, '-rawin', '-inkey', $inkey,
59 '-digest', 'SHA256',
60 '-pkeyopt', 'pad-mode:x931',
61 '-verify',
62 '-sigfile', 'sigoaep.txt'])),
63 "RSA Verify with x931 padding using data signed with oaep padding should fail");