Skip to main content
  • Home
  • login
  • Browse the archive

    swh mirror partner logo
swh logo
SoftwareHeritage
Software
Heritage
Mirror
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • 72e1ac8
  • /
  • gen_rsa.pl
Raw File
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge Iframe embedding
swh:1:cnt:6acf043c2aaaaf723d6d0b6ff8846d894d577164
directory badge Iframe embedding
swh:1:dir:72e1ac845e1e2c2c3aa79ef56db7ae5647a322dc
gen_rsa.pl
#!/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";


ENEA — Copyright (C), ENEA. License: GNU AGPLv3+.
Legal notes  ::  JavaScript license information ::  Web API

back to top