2 # Copyright 2017-2023 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 => 2 + scalar(@test_param) * 5 * 2;
40 ok(run(test(["rsa_mp_test"])), "running rsa multi prime test");
42 ok(run(app(['openssl', 'pkey', '-noout', '-check', '-in',
43 data_file('rsamplcm.pem')])), "checking lcm in key check");
45 my $cleartext = data_file("plain_text");
55 foreach my $param (@test_param) {
56 my $primes = $param->{primes};
57 my $bits = $param->{bits};
58 my $name = ($evp ? "evp" : "") . "${bits}p${primes}";
61 ok(run(app([ 'openssl', 'genpkey', '-out', "rsamptest-$name.pem",
63 '-pkeyopt', "rsa_keygen_primes:$primes",
64 '-pkeyopt', "rsa_keygen_bits:$bits"])),
66 ok(run(app([ 'openssl', 'pkey', '-check',
67 '-in', "rsamptest-$name.pem", '-noout'])),
69 ok(run(app([ 'openssl', 'pkeyutl', '-inkey', "rsamptest-$name.pem",
70 '-encrypt', '-in', $cleartext,
71 '-out', "rsamptest-$name.enc" ])),
73 ok(run(app([ 'openssl', 'pkeyutl', '-inkey', "rsamptest-$name.pem",
74 '-decrypt', '-in', "rsamptest-$name.enc",
75 '-out', "rsamptest-$name.dec" ])),
78 ok(run(app([ 'openssl', 'genrsa', '-out', "rsamptest-$name.pem",
79 '-primes', $primes, $bits])), "genrsa $name");
80 ok(run(app([ 'openssl', 'rsa', '-check',
81 '-in', "rsamptest-$name.pem", '-noout'])),
83 if (!disabled('deprecated-3.0')) {
84 ok(run(app([ 'openssl', 'rsautl', '-inkey', "rsamptest-$name.pem",
85 '-encrypt', '-in', $cleartext,
86 '-out', "rsamptest-$name.enc" ])),
88 ok(run(app([ 'openssl', 'rsautl', '-inkey', "rsamptest-$name.pem",
89 '-decrypt', '-in', "rsamptest-$name.enc",
90 '-out', "rsamptest-$name.dec" ])),
93 ok(run(app([ 'openssl', 'pkeyutl', '-inkey', "rsamptest-$name.pem",
94 '-encrypt', '-in', $cleartext,
95 '-out', "rsamptest-$name.enc" ])),
97 ok(run(app([ 'openssl', 'pkeyutl', '-inkey', "rsamptest-$name.pem",
98 '-decrypt', '-in', "rsamptest-$name.enc",
99 '-out', "rsamptest-$name.dec" ])),
100 "rsa $name decrypt");
103 ok(check_msg("rsamptest-$name.dec"), "rsa $name check result");
108 my $decrypted = shift;
112 open(my $fh, "<", $cleartext) or return 0;
114 read($fh, $msg, 10240);
116 open($fh, "<", $decrypted ) or return 0;
118 read($fh, $dec, 10240);
122 print STDERR "cleartext and decrypted are not the same";