Skip to main content
  • Home
  • login
  • Browse the archive

    swh mirror partner logo
swh logo
SoftwareHeritage
Software
Heritage
Mirror
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • 93e7082
  • /
  • recipes
  • /
  • 15-test_rsax931.t
Raw File
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge Iframe embedding
swh:1:cnt:04b32fa03db4c9fecec10ce63c465f7508715ef2
directory badge Iframe embedding
swh:1:dir:3ca313b5eba3d300231bbbb449b79e1bd65e76ca
15-test_rsax931.t
#! /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");

ENEA — Copyright (C), ENEA. License: GNU AGPLv3+.
Legal notes  ::  JavaScript license information ::  Web API

back to top