]>
git.ipfire.org Git - thirdparty/openssl.git/blob - test/recipes/15-test_mp_rsa.t
2 # Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
3 # Copyright 2017 BaishanCloud. All rights reserved.
5 # Licensed under the Apache License 2.0 (the "License"). You may not use
6 # this file except in compliance with the License. You can obtain a copy
7 # in the file LICENSE in the source distribution or at
8 # https://www.openssl.org/source/license.html
15 use OpenSSL
::Test qw
/:DEFAULT data_file/;
16 use OpenSSL
::Test
::Utils
;
38 plan tests
=> 1 + scalar(@test_param) * 5 * (disabled
('deprecated-3.0') ?
1 : 2);
40 ok
(run
(test
(["rsa_mp_test"])), "running rsa multi prime test");
42 my $cleartext = data_file
("plain_text");
45 run_mp_tests
(0) if !disabled
('deprecated-3.0');
52 foreach my $param (@test_param) {
53 my $primes = $param->{primes
};
54 my $bits = $param->{bits
};
55 my $name = ($evp ?
"evp" : "") . "${bits}p${primes}";
58 ok
(run
(app
([ 'openssl', 'genpkey', '-out', "rsamptest-$name.pem",
60 '-pkeyopt', "rsa_keygen_primes:$primes",
61 '-pkeyopt', "rsa_keygen_bits:$bits"])),
63 ok
(run
(app
([ 'openssl', 'pkey', '-check',
64 '-in', "rsamptest-$name.pem", '-noout'])),
66 ok
(run
(app
([ 'openssl', 'pkeyutl', '-inkey', "rsamptest-$name.pem",
67 '-encrypt', '-in', $cleartext,
68 '-out', "rsamptest-$name.enc" ])),
70 ok
(run
(app
([ 'openssl', 'pkeyutl', '-inkey', "rsamptest-$name.pem",
71 '-decrypt', '-in', "rsamptest-$name.enc",
72 '-out', "rsamptest-$name.dec" ])),
75 ok
(run
(app
([ 'openssl', 'genrsa', '-out', "rsamptest-$name.pem",
76 '-primes', $primes, $bits])), "genrsa $name");
77 ok
(run
(app
([ 'openssl', 'rsa', '-check',
78 '-in', "rsamptest-$name.pem", '-noout'])),
80 ok
(run
(app
([ 'openssl', 'rsautl', '-inkey', "rsamptest-$name.pem",
81 '-encrypt', '-in', $cleartext,
82 '-out', "rsamptest-$name.enc" ])),
84 ok
(run
(app
([ 'openssl', 'rsautl', '-inkey', "rsamptest-$name.pem",
85 '-decrypt', '-in', "rsamptest-$name.enc",
86 '-out', "rsamptest-$name.dec" ])),
89 ok
(check_msg
("rsamptest-$name.dec"), "rsa $name check result");
94 my $decrypted = shift;
98 open(my $fh, "<", $cleartext) or return 0;
100 read($fh, $msg, 10240);
102 open($fh, "<", $decrypted ) or return 0;
104 read($fh, $dec, 10240);
108 print STDERR
"cleartext and decrypted are not the same";