@@ -6,7 +6,7 @@ use Crypt::OpenSSL::RSA;
66use Crypt::OpenSSL::Guess qw( openssl_version) ;
77
88BEGIN {
9- plan tests => 37 + ( UNIVERSAL::can( " Crypt::OpenSSL::RSA" , " use_sha512_hash" ) ? 4 * 5 : 0 ) + ( UNIVERSAL::can( " Crypt::OpenSSL::RSA" , " use_whirlpool_hash" ) ? 1 * 5 : 0 );
9+ plan tests => 67 + ( UNIVERSAL::can( " Crypt::OpenSSL::RSA" , " use_sha512_hash" ) ? 4 * 5 : 0 ) + ( UNIVERSAL::can( " Crypt::OpenSSL::RSA" , " use_whirlpool_hash" ) ? 1 * 5 : 0 );
1010}
1111
1212sub _Test_Encrypt_And_Decrypt {
@@ -37,16 +37,17 @@ sub _Test_Sign_And_Verify {
3737 my $sig = eval { $rsa -> sign($plaintext ) };
3838 SKIP: {
3939 skip " OpenSSL error: illegal or unsupported padding mode - $hash " , 5 if $@ =~ / illegal or unsupported padding mode/i ;
40- ok( $rsa_pub -> verify( $plaintext , $sig ) );
40+ skip " OpenSSL error: invalid digest - $hash " , 5 if $@ =~ / invalid digest/i ;
41+ ok( $rsa_pub -> verify( $plaintext , $sig ), " rsa_pub verify $hash " );
4142
4243 my $false_sig = unpack " H*" , $sig ;
4344 $false_sig =~ tr / [a-f]/ [0a-d]/ ;
44- ok( !$rsa_pub -> verify( $plaintext , pack ( " H*" , $false_sig ) ) );
45- ok( !$rsa -> verify( $plaintext , pack ( " H*" , $false_sig ) ) );
45+ ok( !$rsa_pub -> verify( $plaintext , pack ( " H*" , $false_sig ) ), " rsa_pub do not verify invalid $hash " );
46+ ok( !$rsa -> verify( $plaintext , pack ( " H*" , $false_sig ) ), " rsa do not verify invalid $hash " );
4647
4748 my $sig_of_other = $rsa -> sign(" different" );
48- ok( !$rsa_pub -> verify( $plaintext , $sig_of_other ) );
49- ok( !$rsa -> verify( $plaintext , $sig_of_other ) );
49+ ok( !$rsa_pub -> verify( $plaintext , $sig_of_other ), " rsa_pub do not verify unmatching message " );
50+ ok( !$rsa -> verify( $plaintext , $sig_of_other ), " rsa do not verify unmatching message " );
5051 }
5152}
5253
@@ -69,8 +70,8 @@ Crypt::OpenSSL::RSA->import_random_seed();
6970
7071ok( Crypt::OpenSSL::RSA-> generate_key(512)-> size() * 8 == 512 );
7172
72- my $rsa = Crypt::OpenSSL::RSA-> generate_key(1024 );
73- ok( $rsa -> size() * 8 == 1024 );
73+ my $rsa = Crypt::OpenSSL::RSA-> generate_key(2048 );
74+ ok( $rsa -> size() * 8 == 2048 );
7475ok( $rsa -> check_key() );
7576
7677$rsa -> use_no_padding();
@@ -121,31 +122,38 @@ _check_for_croak(
121122
122123$plaintext .= $plaintext x 5 ;
123124
124- # check signature algorithms
125- $rsa -> use_md5_hash();
126- $rsa_pub -> use_md5_hash();
127- _Test_Sign_And_Verify( $plaintext , $rsa , $rsa_pub , " md5" );
125+ my @paddings = qw/ pkcs1_oaep pkcs1_pss/ ;
126+ foreach my $padding (@paddings ) {
127+ my $p = " use_$padding \_ padding" ;
128128
129- $rsa -> use_sha1_hash();
130- $rsa_pub -> use_sha1_hash();
131- _Test_Sign_And_Verify( $plaintext , $rsa , $rsa_pub , " sha1" );
129+ $rsa -> $p ;
130+ $rsa_pub -> $p ;
131+ # check signature algorithms
132+ $rsa -> use_md5_hash();
133+ $rsa_pub -> use_md5_hash();
134+ _Test_Sign_And_Verify( $plaintext , $rsa , $rsa_pub , " md5 with $padding padding" );
132135
133- if ( UNIVERSAL::can( " Crypt::OpenSSL::RSA" , " use_sha512_hash" ) ) {
136+ $rsa -> use_sha1_hash();
137+ $rsa_pub -> use_sha1_hash();
138+ _Test_Sign_And_Verify( $plaintext , $rsa , $rsa_pub , " sha1 with $padding padding" );
139+
140+ if ( UNIVERSAL::can( " Crypt::OpenSSL::RSA" , " use_sha512_hash" ) ) {
134141 $rsa -> use_sha224_hash();
135142 $rsa_pub -> use_sha224_hash();
136- _Test_Sign_And_Verify( $plaintext , $rsa , $rsa_pub , " sha224" );
143+ _Test_Sign_And_Verify( $plaintext , $rsa , $rsa_pub , " sha224 with $padding padding " );
137144
138145 $rsa -> use_sha256_hash();
139146 $rsa_pub -> use_sha256_hash();
140- _Test_Sign_And_Verify( $plaintext , $rsa , $rsa_pub , " sha256" );
147+ _Test_Sign_And_Verify( $plaintext , $rsa , $rsa_pub , " sha256 with $padding padding " );
141148
142149 $rsa -> use_sha384_hash();
143150 $rsa_pub -> use_sha384_hash();
144- _Test_Sign_And_Verify( $plaintext , $rsa , $rsa_pub , " sha384" );
151+ _Test_Sign_And_Verify( $plaintext , $rsa , $rsa_pub , " sha384 with $padding padding " );
145152
146153 $rsa -> use_sha512_hash();
147154 $rsa_pub -> use_sha512_hash();
148- _Test_Sign_And_Verify( $plaintext , $rsa , $rsa_pub , " sha512" );
155+ _Test_Sign_And_Verify( $plaintext , $rsa , $rsa_pub , " sha512 with $padding padding" );
156+ }
149157}
150158
151159my ( $major , $minor , $patch ) = openssl_version();
0 commit comments