Update of /cvsroot/perl-openssl/Crypt/OpenSSL/RSA/t
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13434/t
Modified Files:
bignum.t rsa.t
Log Message:
Add private_encrypt and public_decrypt, contributed by
Paul G. Weiss <pa...@we...>
Index: bignum.t
===================================================================
RCS file: /cvsroot/perl-openssl/Crypt/OpenSSL/RSA/t/bignum.t,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** bignum.t 18 Feb 2004 20:14:04 -0000 1.4
--- bignum.t 18 Feb 2004 21:37:32 -0000 1.5
***************
*** 8,12 ****
sub check_datum
{
! my($p_expected, $p_actual) = @_;
ok(defined($p_expected)
? $p_actual && $p_expected->equals($p_actual)
--- 8,12 ----
sub check_datum
{
! my ($p_expected, $p_actual) = @_;
ok(defined($p_expected)
? $p_actual && $p_expected->equals($p_actual)
***************
*** 16,21 ****
sub check_key_parameters # runs 8 tests
{
! my($p_rsa, $n, $e, $d, $p, $q, $dmp1, $dmq1, $iqmp) = @_;
! my($rn, $re, $rd, $rp, $rq, $rdmp1, $rdmq1, $riqmp) =
$p_rsa->get_key_parameters();
--- 16,21 ----
sub check_key_parameters # runs 8 tests
{
! my ($p_rsa, $n, $e, $d, $p, $q, $dmp1, $dmq1, $iqmp) = @_;
! my ($rn, $re, $rd, $rp, $rq, $rdmp1, $rdmq1, $riqmp) =
$p_rsa->get_key_parameters();
***************
*** 40,44 ****
else
{
! plan test => 60;
}
}
--- 40,44 ----
else
{
! plan test => 62;
}
}
***************
*** 73,76 ****
--- 73,80 ----
new_public_key($rsa->get_public_key_string());
+ $rsa_pub->use_no_padding();
+ ok($rsa->private_encrypt($ciphertext) eq $plaintext);
+ ok($rsa_pub->public_decrypt($plaintext) eq $ciphertext);
+
my @pub_parameters = $rsa_pub->get_key_parameters();
ok(scalar(@pub_parameters) == 8);
Index: rsa.t
===================================================================
RCS file: /cvsroot/perl-openssl/Crypt/OpenSSL/RSA/t/rsa.t,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** rsa.t 18 Feb 2004 20:12:40 -0000 1.4
--- rsa.t 18 Feb 2004 21:37:32 -0000 1.5
***************
*** 5,21 ****
use Crypt::OpenSSL::RSA;
! BEGIN { plan tests => 25 }
sub _Test_Encrypt_And_Decrypt
{
! my ($plaintext_length, $rsa) = @_;
my ($ciphertext, $decoded_text);
! my $plaintext = pack("C$plaintext_length",
(1,255,0,128,4, # Make sure these characters work
! map {int(rand 256)} (1..$plaintext_length-5)));
! ok($ciphertext = $rsa->encrypt($plaintext));
! ok($decoded_text = $rsa->decrypt($ciphertext));
ok($decoded_text eq $plaintext);
}
--- 5,28 ----
use Crypt::OpenSSL::RSA;
! BEGIN { plan tests => 31 }
sub _Test_Encrypt_And_Decrypt
{
! my ($p_plaintext_length, $p_rsa, $p_check_private_encrypt) = @_;
my ($ciphertext, $decoded_text);
! my $plaintext = pack("C${p_plaintext_length}",
(1,255,0,128,4, # Make sure these characters work
! map {int(rand 256)} (1 .. $p_plaintext_length - 5)));
! ok($ciphertext = $p_rsa->encrypt($plaintext));
! ok($decoded_text = $p_rsa->decrypt($ciphertext));
ok($decoded_text eq $plaintext);
+
+ if ($p_check_private_encrypt)
+ {
+ ok($ciphertext = $p_rsa->private_encrypt($plaintext));
+ ok($decoded_text = $p_rsa->public_decrypt($ciphertext));
+ ok($decoded_text eq $plaintext);
+ }
}
***************
*** 33,38 ****
}
-
-
# On platforms without a /dev/random, we need to manually seed. In
# real life, the following would stink, but for testing purposes, it
--- 40,43 ----
***************
*** 52,65 ****
ok($rsa->check_key());
- # check if NO_PADDING works
-
$rsa->use_no_padding();
! _Test_Encrypt_And_Decrypt($rsa->size(), $rsa);
!
! $rsa->use_pkcs1_oaep_padding();
! _Test_Encrypt_And_Decrypt($rsa->size() - 42, $rsa);
$rsa->use_pkcs1_padding();
! _Test_Encrypt_And_Decrypt($rsa->size() - 11, $rsa);
#FIXME - use_sslv23_padding seems to fail on decryption. openssl bug?
--- 57,69 ----
ok($rsa->check_key());
$rsa->use_no_padding();
! _Test_Encrypt_And_Decrypt($rsa->size(), $rsa, 1);
$rsa->use_pkcs1_padding();
! _Test_Encrypt_And_Decrypt($rsa->size() - 11, $rsa, 1);
!
! $rsa->use_pkcs1_oaep_padding();
! # private_encrypt does not work with pkcs1_oaep_padding
! _Test_Encrypt_And_Decrypt($rsa->size() - 42, $rsa, 0);
#FIXME - use_sslv23_padding seems to fail on decryption. openssl bug?
|