Skip to content

Commit fdfedbd

Browse files
committed
Converted ElGamal packages to use Math::BigInt instead of Math::Pari
1 parent 1cf99d6 commit fdfedbd

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

lib/Crypt/OpenPGP/Key/Public/ElGamal.pm

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ package Crypt::OpenPGP::ElGamal::Public;
3535
use strict;
3636

3737
use Crypt::OpenPGP::Util qw( mod_exp );
38-
use Math::Pari qw( Mod lift gcd );
38+
use Math::BigInt;
3939

4040
sub new { bless {}, $_[0] }
4141

@@ -45,20 +45,22 @@ sub encrypt {
4545
my $k = gen_k($key->p);
4646
my $a = mod_exp($key->g, $k, $key->p);
4747
my $b = mod_exp($key->y, $k, $key->p);
48-
$b = Mod($b, $key->p);
49-
$b = lift($b * $M);
50-
{ a => $a, b => $b };
48+
$b->bmod($key->p);
49+
{ a => $a, b => $b * $M };
5150
}
5251

5352
sub gen_k {
5453
my($p) = @_;
5554
## XXX choose bitsize based on bitsize of $p
5655
my $bits = 198;
5756
my $p_minus1 = $p - 1;
57+
5858
require Crypt::Random;
5959
my $k = Crypt::Random::makerandom( Size => $bits, Strength => 0 );
60+
# We get back a Math::Pari object, but need a Math::BigInt
61+
$k = Math::BigInt->new($k);
6062
while (1) {
61-
last if gcd($k, $p_minus1) == 1;
63+
last if Math::BigInt::bgcd($k, $p_minus1) == 1;
6264
$k++;
6365
}
6466
$k;

lib/Crypt/OpenPGP/Key/Secret/ElGamal.pm

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ package Crypt::OpenPGP::ElGamal::Private;
2525
use strict;
2626

2727
use Crypt::OpenPGP::Util qw( mod_exp mod_inverse );
28-
use Math::Pari qw( Mod lift );
28+
use Math::BigInt;
2929

3030
sub new { bless {}, $_[0] }
3131

@@ -35,8 +35,9 @@ sub decrypt {
3535
my $p = $key->p;
3636
my $t1 = mod_exp($C->{a}, $key->x, $p);
3737
$t1 = mod_inverse($t1, $p);
38-
my $output = Mod($C->{b}, $p);
39-
lift($output * $t1);
38+
my $n = Math::BigInt->new($C->{b} * $t1);
39+
$n->bmod($p);
40+
return $n;
4041
}
4142

4243
sub _getset {

0 commit comments

Comments
 (0)