From: slontis Date: Fri, 3 Feb 2023 22:25:03 +0000 (+1000) Subject: Add Tests for RSA signatures using X931 padding. X-Git-Tag: openssl-3.2.0-alpha1~1166 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=513b20a982e237fbd4c281c1c7ba817864f9a827;p=thirdparty%2Fopenssl.git Add Tests for RSA signatures using X931 padding. Reviewed-by: Dmitry Belyavskiy Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/20211) --- diff --git a/test/recipes/15-test_rsax931.t b/test/recipes/15-test_rsax931.t new file mode 100644 index 00000000000..04b32fa03db --- /dev/null +++ b/test/recipes/15-test_rsax931.t @@ -0,0 +1,63 @@ +#! /usr/bin/env perl +# Copyright 2023 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 OpenSSL::Test qw(:DEFAULT srctop_file); +use OpenSSL::Test::Utils; + +BEGIN { + setup("test_rsax931"); +} + +plan tests => 6; + +my $infile = srctop_file("test", "certs", "sm2.key"); +my $inkey = srctop_file("test", "testrsa2048.pem"); + +ok(run(app(['openssl', 'pkeyutl', '-in', $infile, '-rawin', '-inkey', $inkey, + '-digest', 'SHA256', + '-pkeyopt', 'pad-mode:x931', + '-sign', + '-out', 'sigx931.txt'])), + "RSA Sign with x931 padding using SHA256"); + +ok(run(app(['openssl', 'pkeyutl', '-in', $infile, '-rawin', '-inkey', $inkey, + '-digest', 'SHA256', + '-pkeyopt', 'pad-mode:x931', + '-verify', + '-sigfile', 'sigx931.txt'])), + "RSA Verify with x931 padding using SHA256"); + +ok(!run(app(['openssl', 'pkeyutl', '-in', $infile, '-rawin', '-inkey', $inkey, + '-digest', 'SHA512', + '-pkeyopt', 'pad-mode:x931', + '-verify', + '-sigfile', 'sigx931.txt'])), + "RSA Verify with x931 padding fails if digest is different"); + +ok(!run(app(['openssl', 'pkeyutl', '-in', $infile, '-rawin', '-inkey', $inkey, + '-digest', 'SHA512-256', + '-pkeyopt', 'pad-mode:x931', + '-sign'])), + "RSA Sign with x931 padding using unsupported digest should fail"); + +ok(run(app(['openssl', 'pkeyutl', '-in', $infile, '-rawin', '-inkey', $inkey, + '-digest', 'SHA256', + '-pkeyopt', 'pad-mode:oaep', + '-sign', + '-out', 'sigoaep.txt'])), + "RSA Sign with oaep padding using SHA256"); + +ok(!run(app(['openssl', 'pkeyutl', '-in', $infile, '-rawin', '-inkey', $inkey, + '-digest', 'SHA256', + '-pkeyopt', 'pad-mode:x931', + '-verify', + '-sigfile', 'sigoaep.txt'])), + "RSA Verify with x931 padding using data signed with oaep padding should fail");