diff options
author | Ralf S. Engelschall <rse@openssl.org> | 1998-12-21 10:56:39 +0000 |
---|---|---|
committer | Ralf S. Engelschall <rse@openssl.org> | 1998-12-21 10:56:39 +0000 |
commit | 58964a492275ca9a59a0cd9c8155cb2491b4b909 (patch) | |
tree | c7b16876a5789463bbbb468ef4829c8129b3d718 /perl/gen_rsa.pl | |
parent | d02b48c63a58ea4367a0e905979f140b7d090f86 (diff) | |
download | openssl-58964a492275ca9a59a0cd9c8155cb2491b4b909.tar.gz |
Import of old SSLeay release: SSLeay 0.9.0b
Diffstat (limited to 'perl/gen_rsa.pl')
-rw-r--r-- | perl/gen_rsa.pl | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/perl/gen_rsa.pl b/perl/gen_rsa.pl new file mode 100644 index 0000000000..6acf043c2a --- /dev/null +++ b/perl/gen_rsa.pl @@ -0,0 +1,49 @@ +#!/usr/local/bin/perl + +use ExtUtils::testlib; + +use SSLeay; + +$bits=512; +$bits=$ARGV[0] if $#ARGV >= 0; + +$p=SSLeay::BN::generate_prime($bits/2,0,sub {print STDERR $_[0]?"+":"."}); +print "\n"; +$q=SSLeay::BN::generate_prime($bits/2,0,sub {print STDERR $_[0]?"+":"."}); +print "\n"; + +$e=SSLeay::BN::hex2bn("10001"); + +$t1=$p-1; +$t2=$q-1; + +($t1->gcd($e) == 1) || die "p failed the gcd test\n"; +($t2->gcd($e) == 1) || die "q failed the gcd test\n"; + +($q,$p)=($p,$q) if ($p < $q); +$n=$p*$q; +$t=($p-1)*($q-1); +($t->gcd($e) == 1) || die "t failed the gcd test\n"; + +$d=$e->mod_inverse($t); + +$dmp1=$d%($p-1); +$dmq1=$d%($q-1); +$iqmp=$q->mod_inverse($p); + +print "n =$n\n"; +print "e =$e\n"; +print "d =$d\n"; +print "dmp1=$dmp1\n"; +print "dmq1=$dmq1\n"; +print "iqmp=$iqmp\n"; + +$a=SSLeay::BN::bin2bn("This is an RSA test"); +print "Test with\n'".$a->bn2bin."' or\n$a\n"; + +$t1=$a->mod_exp($e,$n); +print "$t1\n"; +$t2=$t1->mod_exp($d,$n); +print "'".$t2->bn2bin."'\n"; + + |