But even if I supply the same password to the genrsarandom() function everytime (by using a global variable), the Crypt::OpenSSL::RSA function still generates different keypairs everytime. Have a look at it here:#!/usr/bin/perl use CGI ':standard'; use Digest::SHA qw(sha512); use Crypt::OpenSSL::Random; use Crypt::OpenSSL::RSA; $passphrase = param('genpass'); $prngdata = ""; print "Content-Type: text/html\n\n"; if ($passphrase) { Crypt::OpenSSL::Random::random_seed(&genrsarandom(1024)); Crypt::OpenSSL::RSA->import_random_seed(); $rsa = Crypt::OpenSSL::RSA->generate_key(1024); print "PRNG data length: ". length($prngdata)."<br>"; print "PRNG data in hex: " . uc(unpack("H*", $prngdata)) . "<br><br>"; $pubkey = $rsa->get_public_key_string(); $privkey = $rsa->get_private_key_string(); $pubkey =~ s/\n/<br>/sgi; $privkey =~ s/\n/<br>/sgi; print "Public key: <br>" . $pubkey . "<br><br>"; print "Private key: <br>" . $privkey; } else { print "<form action=\"RSAgen.cgi\">PassPhrase: <input type=\"text\" na +me=\"genpass\"><input type=\"submit\" value=\"genrsa\"></form>"; } #################################################### # CSPRNG BASED ON A PASSWORD # RETURNS SAME RANDOM DATA UPON SUPPLYING # THE SAME PASSWORD #################################################### sub genrsarandom() { $bytes = $_[0]; $randomdata = ""; $numberofrounds = int($bytes / 64) + 1; for ($i = 0; $i < $numberofrounds; $i++) { $randomdata = $randomdata . sha512($passphrase . sha512($i.$i)); } $randomdata = substr($randomdata, 0, $bytes); $prngdata = $randomdata; return $randomdata; }
http://www.sebn.us.to/old/RSAgen.cgi
Enter something in the textbox. It now generates a keypair, but the problem is that the keypair is different everytime, even if you supply the same password again. However, theres NO error in the genrsarandom() function since it returns the same random data everytime the same password is supplied. The system should return the same keypair everytime the same password is entered.How can I make so the Crypt::OpenSSL::RSA in some way directly use my supplied random data for key generation?
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |