OpenPGP/Key/Public/ElGamal.pm

filter: Statementstmt 53.4% 31 / 58 Branchbran 0.0% 0 / 4 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 55.0% 11 / 20 Podpod 33.3% 3 / 9 totaltotal 47.9% 46 / 96 CC 4 SCAR 8.3
CC
4
Cov
49%
gen_k
6.0
__ANON__
6.0
init
2.1
CRAP 2.3
« OpenPGP/Digest.pm ↑ Summary OpenPGP/ErrorHandler.pm »
1 package Crypt::OpenPGP::Key::Public::ElGamal;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 our $VERSION = '1.21'; # VERSION
5  
6 1 ▶use Crypt::OpenPGP::Util qw( bitsize);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use parent qw( Crypt::OpenPGP::Key::Public Crypt::OpenPGP::ErrorHandler );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 0 ▶sub can_encrypt { 1 }
Subroutine can_encrypt: not called CC=1 SCAR=6.9
Pod documented
10 0 ▶sub abbrev { 'g' }
Subroutine abbrev: not called CC=1 SCAR=6.9
Pod undocumented
11  
12 1 ▶sub public_props { qw( p g y ) }
Subroutine public_props: called CC=1 SCAR=0.0
Pod undocumented
13 1 ▶sub crypt_props { qw( a b ) }
Subroutine crypt_props: called CC=1 SCAR=0.0
Pod undocumented
14 0 ▶sub sig_props { qw( a b ) }
Subroutine sig_props: not called CC=1 SCAR=6.9
Pod undocumented
15  
16 0 ▶sub size { bitsize($_[0]->p) }
Subroutine size: not called CC=1 SCAR=6.9
Pod documented
17  
18 1 ▶sub init {
Subroutine init: called CC=2 SCAR=7.6
Pod undocumented
19 1 my $key = shift;
20 1 ▶ $key->{key_data} = shift || Crypt::OpenPGP::ElGamal::Public->new;
Condition33%1/3
shift() || 'Crypt::OpenPGP::ElGamal::Public'->new
l!l&&r!l&&!r
010
MC/DC0%0/2
shift() || 'Crypt::OpenPGP::ElGamal::Public'->new
shift() 'Crypt::OpenPGP::ElGamal::Public'->new
Truth table33%1/3
A || B
A= shift()B= 'Crypt::OpenPGP::ElGamal::Public'->new
ABresult
1X1
011
000
21 1 $key;
22 }
23  
24 0 ▶sub keygen {
Subroutine keygen: not called CC=1 SCAR=6.9
Pod documented
25 0 return $_[0]->error("ElGamal key generation is not supported");
26 }
27  
28 0 ▶sub encrypt {
Subroutine encrypt: not called CC=1 SCAR=6.9
Pod undocumented
29 0 my $key = shift;
30 0 my($M) = @_;
31 0 $key->{key_data}->encrypt($M);
32 }
33  
34 package Crypt::OpenPGP::ElGamal::Public;
35 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 1 ▶use Crypt::OpenPGP::Util qw( mod_exp );
Subroutine BEGIN: called CC=1 SCAR=0.0
38 1 ▶use Math::BigInt;
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 1 ▶sub new { bless {}, $_[0] }
Subroutine new: called CC=1 SCAR=0.0
41  
42 0 ▶sub encrypt {
Subroutine encrypt: not called CC=1 SCAR=6.9
43 0 my $key = shift;
44 0 my($M) = @_;
45 0 my $k = gen_k($key->p);
46 0 my $a = mod_exp($key->g, $k, $key->p);
47 0 my $b = mod_exp($key->y, $k, $key->p);
48 0 $b->bmod($key->p);
49 0 { a => $a, b => $b * $M };
50 }
51  
52 0 ▶sub gen_k {
Subroutine gen_k: not called CC=2 SCAR=17.9
53 0 my($p) = @_;
54 ## XXX choose bitsize based on bitsize of $p
55 0 my $bits = 198;
56 0 my $p_minus1 = Math::BigInt->new($p);
57 0 $p_minus1->bsub(1);
58  
59 0 my $k = Crypt::OpenPGP::Util::get_random_bigint($bits);
60 0 while (1) {
61 0 ▶ last if Math::BigInt::bgcd($k, $p_minus1) == 1;
Branch: 1 branch
BranchTrueFalseTotal
if Math::BigInt::bgcd($k, $p_minus1) == 1 0 0 0
62 0 $k++;
63 }
64 0 $k;
65 }
66  
67 3 ▶sub _getset {
Subroutine _getset: called CC=1 SCAR=3.1
68 3 my $e = shift;
69 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
70 0 my $key = shift;
71 0 ▶ $key->{$e} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
72 0 $key->{$e};
73 }
74 3 }
75  
76 1 *p = _getset('p');
77 1 *g = _getset('g');
78 1 *y = _getset('y');
79  
80 1 1;
« OpenPGP/Digest.pm ↑ Summary OpenPGP/ErrorHandler.pm »