OpenPGP/Key/Secret/ElGamal.pm untested

filter: Statementstmt 0.0% 0 / 53 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 80 CC 2 SCAR 9.3
CC
2
Cov
0%
_getset
6.0
secret_props
2.0
init
2.0
CRAP 2.5
1 package Crypt::OpenPGP::Key::Secret::ElGamal;
2 use strict;
3 use warnings;
4  
5 our $VERSION = '1.21'; # VERSION
6  
7 use Crypt::OpenPGP::Key::Public::ElGamal;
8 use parent qw( Crypt::OpenPGP::Key::Secret Crypt::OpenPGP::ErrorHandler );
9  
10 sub secret_props { qw( x ) }
11 *public_props = \&Crypt::OpenPGP::Key::Public::ElGamal::public_props;
12 *crypt_props = \&Crypt::OpenPGP::Key::Public::ElGamal::crypt_props;
13 *size = \&Crypt::OpenPGP::Key::Public::ElGamal::size;
14 *keygen = \&Crypt::OpenPGP::Key::Public::ElGamal::keygen;
15 *can_encrypt = \&Crypt::OpenPGP::Key::Public::ElGamal::can_encrypt;
16  
17 sub init {
18 my $key = shift;
19 $key->{key_data} = shift || Crypt::OpenPGP::ElGamal::Private->new;
20 $key;
21 }
22  
23 sub decrypt { $_[0]->{key_data}->decrypt(@_[1..$#_]) }
24  
25 package Crypt::OpenPGP::ElGamal::Private;
26 use strict;
27 use warnings;
28  
29 use Crypt::OpenPGP::Util qw( mod_exp mod_inverse );
30 use Math::BigInt;
31  
32 sub new { bless {}, $_[0] }
33  
34 sub decrypt {
35 my $key = shift;
36 my($C) = @_;
37 my $p = $key->p;
38 my $t1 = mod_exp($C->{a}, $key->x, $p);
39 $t1 = mod_inverse($t1, $p);
40 my $n = Math::BigInt->new($C->{b} * $t1);
41 $n->bmod($p);
42 return $n;
43 }
44  
45 sub _getset {
46 my $e = shift;
47 sub {
48 my $key = shift;
49 $key->{$e} = shift if @_;
50 $key->{$e};
51 }
52 }
53  
54 *p = _getset('p');
55 *g = _getset('g');
56 *y = _getset('y');
57 *x = _getset('x');
58  
59 1;