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 9use strict; 10use warnings; 11 12use OpenSSL::Test qw(:DEFAULT srctop_file); 13use OpenSSL::Test::Utils; 14 15BEGIN { 16 setup("test_rsax931"); 17} 18 19plan tests => 6; 20 21my $infile = srctop_file("test", "certs", "sm2.key"); 22my $inkey = srctop_file("test", "testrsa2048.pem"); 23 24ok(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 31ok(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 38ok(!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 45ok(!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 51ok(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 58ok(!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"); 64