]> git.ipfire.org Git - thirdparty/openssl.git/blame - test/recipes/15-test_rsapss.t
Obtain PSS salt length from provider
[thirdparty/openssl.git] / test / recipes / 15-test_rsapss.t
CommitLineData
5e047ebf 1#! /usr/bin/env perl
fecb3aae 2# Copyright 2017-2022 The OpenSSL Project Authors. All Rights Reserved.
5e047ebf 3#
909f1a2e 4# Licensed under the Apache License 2.0 (the "License"). You may not use
5e047ebf
BE
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
10use strict;
11use warnings;
12
13use File::Spec;
48320997 14use OpenSSL::Test qw/:DEFAULT with srctop_file data_file/;
5e047ebf
BE
15use OpenSSL::Test::Utils;
16
17setup("test_rsapss");
18
5a3bbe17 19plan tests => 11;
5e047ebf
BE
20
21#using test/testrsa.pem which happens to be a 512 bit RSA
22ok(run(app(['openssl', 'dgst', '-sign', srctop_file('test', 'testrsa.pem'), '-sha1',
d49be019
RL
23 '-sigopt', 'rsa_padding_mode:pss',
24 '-sigopt', 'rsa_pss_saltlen:max',
25 '-sigopt', 'rsa_mgf1_md:sha512',
26 '-out', 'testrsapss-restricted.sig',
d8f9213a 27 srctop_file('test', 'testrsa.pem')])),
d49be019
RL
28 "openssl dgst -sign [plain RSA key, PSS padding mode, PSS restrictions]");
29
30ok(run(app(['openssl', 'dgst', '-sign', srctop_file('test', 'testrsa.pem'), '-sha1',
31 '-sigopt', 'rsa_padding_mode:pss',
32 '-out', 'testrsapss-unrestricted.sig',
33 srctop_file('test', 'testrsa.pem')])),
34 "openssl dgst -sign [plain RSA key, PSS padding mode, no PSS restrictions]");
5e047ebf 35
67eacb60
TM
36ok(!run(app(['openssl', 'dgst', '-sign', srctop_file('test', 'testrsa.pem'), '-sha512',
37 '-sigopt', 'rsa_padding_mode:pss', '-sigopt', 'rsa_pss_saltlen:max',
38 '-sigopt', 'rsa_mgf1_md:sha512', srctop_file('test', 'testrsa.pem')])),
39 "openssl dgst -sign, expect to fail gracefully");
40
41ok(!run(app(['openssl', 'dgst', '-sign', srctop_file('test', 'testrsa.pem'), '-sha512',
42 '-sigopt', 'rsa_padding_mode:pss', '-sigopt', 'rsa_pss_saltlen:2147483647',
43 '-sigopt', 'rsa_mgf1_md:sha1', srctop_file('test', 'testrsa.pem')])),
44 "openssl dgst -sign, expect to fail gracefully");
45
46ok(!run(app(['openssl', 'dgst', '-prverify', srctop_file('test', 'testrsa.pem'), '-sha512',
47 '-sigopt', 'rsa_padding_mode:pss', '-sigopt', 'rsa_pss_saltlen:max',
48 '-sigopt', 'rsa_mgf1_md:sha512', '-signature', 'testrsapss.sig',
49 srctop_file('test', 'testrsa.pem')])),
50 "openssl dgst -prverify, expect to fail gracefully");
5e047ebf 51
d49be019
RL
52ok(run(app(['openssl', 'dgst', '-prverify', srctop_file('test', 'testrsa.pem'),
53 '-sha1',
54 '-sigopt', 'rsa_padding_mode:pss',
55 '-sigopt', 'rsa_pss_saltlen:max',
56 '-sigopt', 'rsa_mgf1_md:sha512',
57 '-signature', 'testrsapss-restricted.sig',
58 srctop_file('test', 'testrsa.pem')])),
59 "openssl dgst -prverify [plain RSA key, PSS padding mode, PSS restrictions]");
60
5a3bbe17
CL
61ok(run(app(['openssl', 'dgst', '-prverify', srctop_file('test', 'testrsa.pem'),
62 '-sha1',
63 '-sigopt', 'rsa_padding_mode:pss',
64 '-sigopt', 'rsa_pss_saltlen:42',
65 '-sigopt', 'rsa_mgf1_md:sha512',
66 '-signature', 'testrsapss-restricted.sig',
67 srctop_file('test', 'testrsa.pem')])),
68 "openssl dgst -sign rsa512bit.pem -sha1 -sigopt rsa_pss_saltlen:max produces 42 bits of PSS salt");
69
d49be019
RL
70ok(run(app(['openssl', 'dgst', '-prverify', srctop_file('test', 'testrsa.pem'),
71 '-sha1',
72 '-sigopt', 'rsa_padding_mode:pss',
73 '-signature', 'testrsapss-unrestricted.sig',
5e047ebf 74 srctop_file('test', 'testrsa.pem')])),
d49be019 75 "openssl dgst -prverify [plain RSA key, PSS padding mode, no PSS restrictions]");
388d6f45
DF
76
77# Test that RSA-PSS keys are supported by genpkey and rsa commands.
78{
79 my $rsapss = "rsapss.key";
80 ok(run(app(['openssl', 'genpkey', '-algorithm', 'RSA-PSS',
81 '-pkeyopt', 'rsa_keygen_bits:1024',
82 '--out', $rsapss])));
83 ok(run(app(['openssl', 'rsa', '-check',
84 '-in', $rsapss])));
85}
48320997
DF
86
87ok(!run(app([ 'openssl', 'rsa',
88 '-in' => data_file('negativesaltlen.pem')],
89 '-out' => 'badout')));