Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Crypt::RSA without Pari

by roperl (Beadle)
on Oct 30, 2017 at 16:40 UTC ( [id://1202338]=perlquestion: print w/replies, xml ) Need Help??

roperl has asked for the wisdom of the Perl Monks concerning the following question:

I'm having some issue with Crypt::OpenPGP when using Public Key encryption with RSA keys. I have Alt::Crypt:RSA installed which uses GMP instead of Pari However, I'm still seeing Crypt::Random which Crypt::RSA calls using Pari. This seems to hang when calling /dev/udrandom is there a multiple requests to encrypt a file at the same time. I solved this in my code by inserting 1/4 second sleep using usleep(250000). This seems to stop /dev/urandom from blocking. I would like to get this solved without having to insert the sleep

Replies are listed 'Best First'.
Re: Crypt::RSA without Pari
by danaj (Friar) on Oct 30, 2017 at 19:04 UTC

    You have Alt::Crypt::RSA::BigInt installed (not Alt::Crypt::RSA)? Also install Math::BigInt::GMP.

    One rather crude way to check is to do man Crypt::RSA and check the REPORTING BUGS section. If it has a third paragraph talking about segmentation faults and Math::Pari, then you've got the original Math::Pari version. Here's a more complicated but better one command line method:

    perl -E 'use Crypt::RSA::Key; my($pari,$big) = ($Math::Pari::VERSION, +$Math::BigInt::VERSION); my $lib = Math::BigInt->config()->{lib} if $ +big; printf "Using %s\n", $pari ? "Pari $pari" : $big ? "BigInt with +$lib" : "???";'

    With Crypt::RSA installed it shows Using Pari 2.01080900 where with Alt::Crypt::RSA::BigInt it shows Using BigInt with Math::BigInt::GMP

    /dev/urandom shouldn't be hanging. Crypt::Random reads from /dev/random which can block waiting for more entropy. Alt::Crypt::RSA::BigInt version 0.06 (April 2017) should just read about 256 bytes at the start, as it uses an ISAAC CSPRNG after that.

      My perl instances seems to be using Math::BigInt::GMP
      #/opt/perl/bin/perl -E 'use Crypt::RSA::Key; my($pari,$big) = ($Math:: +Pari::VERSION, $Math::BigInt::VERSION); my $lib = Math::BigInt->confi +g()->{lib} if $big; printf "Using %s\n", $pari ? "Pari $pari" : $big +? "BigInt with $lib" : "???";' Using BigInt with Math::BigInt::GMP
      However, when run the following using an RSA public key
      my $ct = $pgp->encrypt( Filename => 'plain.txt', Recipients => $key, C +ipher => 'DES3' ) or die "Encryption failed: ", $pgp->errstr;
      I see Pari library being opened.
      #truss ./encrypt_openpgp.pl 2>&1 | grep open | grep Pari open64("/opt/perl-5.26.0/lib/site_perl/5.26.0/sun4-solaris-thread-mult +i/Math/Pari.pm", O_RDONLY) = 4 open("/opt/perl-5.26.0/lib/site_perl/5.26.0/sun4-solaris-thread-multi/ +auto/Math/Pari/Pari.so", O_RDONLY) = 4
      And when I see my code hanging it always has this file open: /opt/perl-5.26.0/lib/site_perl/5.26.0/Crypt/Random.pm

      If I remove Math::Pari he program fails with
      ./encrypt_openpgp.pl No random source available! at /opt/perl-5.26.0/lib/site_perl/5.26.0/C +rypt/OpenPGP/Util.pm line 111.
      sub get_random_bytes { 103 my $length = shift; 104 if (eval 'require Crypt::Random; 1;') { 105 return Crypt::Random::makerandom_octet( Length => +$length); 106 } 107 elsif (eval 'require Bytes::Random::Secure; 1;') { 108 return Bytes::Random::Secure::random_bytes($length +); 109 } 110 else { 111 die "No random source available!"; 112 } 113 }
        I think i figured out what was happening. I didn't have Bytes::Random::Secure, so OpenPGP was still calling Crypt::Random which still uses Pari I removed and rebuilt OpenPGP. Now I don't see any references to the Pari library I'll see if this fixes my hanging issue

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1202338]
Approved by Discipulus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-23 10:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found