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;
22 ok(run(test(["rsa_mp_test"])), "running rsa multi prime test");
24 my $cleartext = data_file("plain_text");
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"])),
64 ok(run(app([ 'openssl', 'genrsa', '-out', "rsamptest-$name.pem",
65 '-primes', $primes, $bits])),
69 ok(run(app([ 'openssl', 'rsa', '-check', '-in', "rsamptest-$name.pem",
74 ok(run(app([ 'openssl', 'pkeyutl', '-inkey', "rsamptest-$name.pem",
75 '-encrypt', '-in', $cleartext,
76 '-out', "rsamptest-$name.enc" ])),
78 ok(run(app([ 'openssl', 'pkeyutl', '-inkey', "rsamptest-$name.pem",
79 '-decrypt', '-in', "rsamptest-$name.enc",
80 '-out', "rsamptest-$name.dec" ])),
83 ok(run(app([ 'openssl', 'rsautl', '-inkey', "rsamptest-$name.pem",
84 '-encrypt', '-in', $cleartext,
85 '-out', "rsamptest-$name.enc" ])),
87 ok(run(app([ 'openssl', 'rsautl', '-inkey', "rsamptest-$name.pem",
88 '-decrypt', '-in', "rsamptest-$name.enc",
89 '-out', "rsamptest-$name.dec" ])),
93 ok(check_msg("rsamptest-$name.dec"), "rsa $name check result");
98 my $decrypted = shift;
102 open(my $fh, "<", $cleartext) or return 0;
104 read($fh, $msg, 10240);
106 open($fh, "<", $decrypted ) or return 0;
108 read($fh, $dec, 10240);
112 print STDERR "cleartext and decrypted are not the same";