blob: 6acf043c2aaaaf723d6d0b6ff8846d894d577164 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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";
|