File tree Expand file tree Collapse file tree 2 files changed +11
-8
lines changed Expand file tree Collapse file tree 2 files changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ package Crypt::OpenPGP::ElGamal::Public;
35
35
use strict;
36
36
37
37
use Crypt::OpenPGP::Util qw( mod_exp ) ;
38
- use Math::Pari qw( Mod lift gcd ) ;
38
+ use Math::BigInt ;
39
39
40
40
sub new { bless {}, $_ [0] }
41
41
@@ -45,20 +45,22 @@ sub encrypt {
45
45
my $k = gen_k($key -> p);
46
46
my $a = mod_exp($key -> g, $k , $key -> p);
47
47
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 };
51
50
}
52
51
53
52
sub gen_k {
54
53
my ($p ) = @_ ;
55
54
# # XXX choose bitsize based on bitsize of $p
56
55
my $bits = 198;
57
56
my $p_minus1 = $p - 1;
57
+
58
58
require Crypt::Random;
59
59
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 );
60
62
while (1) {
61
- last if gcd ($k , $p_minus1 ) == 1;
63
+ last if Math::BigInt::bgcd ($k , $p_minus1 ) == 1;
62
64
$k ++;
63
65
}
64
66
$k ;
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ package Crypt::OpenPGP::ElGamal::Private;
25
25
use strict;
26
26
27
27
use Crypt::OpenPGP::Util qw( mod_exp mod_inverse ) ;
28
- use Math::Pari qw( Mod lift ) ;
28
+ use Math::BigInt ;
29
29
30
30
sub new { bless {}, $_ [0] }
31
31
@@ -35,8 +35,9 @@ sub decrypt {
35
35
my $p = $key -> p;
36
36
my $t1 = mod_exp($C -> {a }, $key -> x, $p );
37
37
$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 ;
40
41
}
41
42
42
43
sub _getset {
You can’t perform that action at this time.
0 commit comments