2 # Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
3 # Copyright 2017 BaishanCloud. All rights reserved.
5 # Licensed under the OpenSSL license (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.pem',
59 '-algorithm', 'RSA', '-pkeyopt', "rsa_keygen_primes:$primes",
60 '-pkeyopt', "rsa_keygen_bits:$bits"])), "genrsa $name");
62 ok(run(app([ 'openssl', 'genrsa', '-out', 'rsamptest.pem',
63 '-primes', $primes, $bits])), "genrsa $name");
66 ok(run(app([ 'openssl', 'rsa', '-check', '-in', 'rsamptest.pem',
67 '-noout'])), "rsa -check $name");
69 ok(run(app([ 'openssl', 'pkeyutl', '-inkey', 'rsamptest.pem',
70 '-encrypt', '-in', $cleartext,
71 '-out', 'rsamptest.enc' ])), "rsa $name encrypt");
72 ok(run(app([ 'openssl', 'pkeyutl', '-inkey', 'rsamptest.pem',
73 '-decrypt', '-in', 'rsamptest.enc',
74 '-out', 'rsamptest.dec' ])), "rsa $name decrypt");
76 ok(run(app([ 'openssl', 'rsautl', '-inkey', 'rsamptest.pem',
77 '-encrypt', '-in', $cleartext,
78 '-out', 'rsamptest.enc' ])), "rsa $name encrypt");
79 ok(run(app([ 'openssl', 'rsautl', '-inkey', 'rsamptest.pem',
80 '-decrypt', '-in', 'rsamptest.enc',
81 '-out', 'rsamptest.dec' ])), "rsa $name decrypt");
84 ok(check_msg(), "rsa $name check result");
87 unlink 'rsamptest.pem';
88 unlink 'rsamptest.enc';
89 unlink 'rsamptest.dec';
97 open(my $fh, "<", $cleartext) or return 0;
99 read($fh, $msg, 10240);
101 open($fh, "<", "rsamptest.dec") or return 0;
103 read($fh, $dec, 10240);
107 print STDERR "cleartext and decrypted are not the same";