lib/Crypt/Perl/ECDSA/EC/FieldElement.pm

filter: Statementstmt 55.5% 15 / 27 Branchbran 25.0% 1 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 5 / 10 Podpod 0.0% 0 / 8 totaltotal 38.8% 21 / 54 CC 4 SCAR 13.9
CC
4
Cov
47%
equals
12.0
new
2.0
add
2.0
CRAP 4.0
« blib/lib/Crypt/Perl/Math.pm ↑ Summary lib/Crypt/Perl/ECDSA/EncodedPoint.pm »
1 package Crypt::Perl::ECDSA::EC::FieldElement;
2  
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 #both bigint
7 sub new {
8 550396 ▶ my ($class, $q, $x) = @_;
Subroutine new: called CC=2 SCAR=7.0
Pod undocumented
9  
10 550396 ▶ die Crypt::Perl::X::create('Generic', 'Need both q and x!') if grep { !defined } $q, $x;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not defined $_;} $q, $x 0 550396 550396
11  
12 550396 return bless { x => $x, q => $q }, $class;
13 }
14  
15 #$other isa ECFieldElement
16 sub equals {
17 0 ▶ my ($self, $other) = @_;
Subroutine equals: not called CC=3 SCAR=24.8
Pod undocumented
18  
19 0 ▶ if ($other eq $self) { #???
Branch: 1 branch
BranchTrueFalseTotal
if ($other eq $self) 0 0 0
20 0 return 1;
21 }
22  
23 0 ▶ return $self->{q}->beq($other->{q}) && $self->{x}->beq($other->{x});
Condition0%0/3
$self->{'q'}->beq($other->{'q'}) && $self->{'x'}->beq($other->{'x'})
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{'q'}->beq($other->{'q'}) && $self->{'x'}->beq($other->{'x'})
$self->{'q'}->beq($other->{'q'}) $self->{'x'}->beq($other->{'x'})
Truth table0%0/3
A && B
A= $self->{'q'}->beq($other->{'q'})B= $self->{'x'}->beq($other->{'x'})
ABresult
0X0
100
111
24 }
25  
26 sub to_bigint {
27 960184 ▶ my ($self) = @_;
Subroutine to_bigint: called CC=1 SCAR=0.0
Pod undocumented
28  
29 960184 return $self->{'x'};
30 }
31  
32 sub negate {
33 796 ▶ my ($self) = @_;
Subroutine negate: called CC=1 SCAR=0.0
Pod undocumented
34  
35 return (ref $self)->new(
36 $self->{'q'},
37 796 $self->{'x'}->copy()->bneg()->bmod($self->{'q'}),
38 );
39 }
40  
41 sub add {
42 0 ▶ my ($self, $b) = @_;
Subroutine add: not called CC=1 SCAR=6.9
Pod undocumented
43  
44 return $self->new(
45 $self->{'q'},
46 0 $self->{'x'}->copy()->badd($b->to_bigint())->bmod($self->{'q'}),
47 );
48 }
49  
50 sub subtract {
51 0 ▶ my ($self, $b) = @_;
Subroutine subtract: not called CC=1 SCAR=6.9
Pod undocumented
52  
53 return $self->new(
54 $self->{'q'},
55 0 $self->{'x'}->copy()->bsub($b->to_bigint())->bmod($self->{'q'}),
56 );
57 }
58  
59 sub multiply {
60 0 ▶ my ($self, $b) = @_;
Subroutine multiply: not called CC=1 SCAR=6.9
Pod undocumented
61  
62 return $self->new(
63 $self->{'q'},
64 0 $self->{'x'}->copy()->bmul($b->to_bigint())->bmod($self->{'q'}),
65 );
66 }
67  
68 sub square {
69 0 ▶ my ($self) = @_;
Subroutine square: not called CC=1 SCAR=6.9
Pod undocumented
70  
71 return $self->new(
72 $self->{'q'},
73 0 $self->{'x'}->copy()->bmodpow(2, $self->{'q'}),
74 );
75 }
76  
77 #sub negate {
78 # my ($self) = @_;
79 #
80 # return $self->_spawn_mod( $self->{'x'}->copy()->bneg() );
81 #}
82 #
83 #sub add {
84 # my ($self, $b) = @_;
85 #
86 # return $self->_spawn_mod( $self->{'x'}->copy()->badd($b->to_bigint()) );
87 #}
88 #
89 #sub subtract {
90 # my ($self, $b) = @_;
91 #
92 # return $self->_spawn_mod( $self->{'x'}->copy()->bsub($b->to_bigint()) );
93 #}
94 #
95 #sub multiply {
96 # my ($self, $b) = @_;
97 #
98 # return $self->_spawn_mod( $self->{'x'}->copy()->bmul($b->to_bigint()) );
99 #}
100 #
101 #sub square {
102 # my ($self) = @_;
103 #
104 # return $self->_spawn( $self->{'x'}->copy()->bmodpow(2, $self->{'q'}) );
105 #}
106 #
107 #sub _spawn_mod {
108 # my ($self, $num) = @_;
109 #
110 # $num->bmod( $self->{'q'} );
111 #
112 # return $self->_spawn($num);
113 #}
114 #
115 #sub _spawn {
116 # my ($self, $num) = @_;
117 #
118 # return (ref $self)->new( $self->{'q'}, $num );
119 #}
120 #
121 ##Unused:
122 #sub divide {
123 # my ($self, $b) = @_;
124 #
125 # return $self->new(
126 # $self->{'q'},
127 # ($self->{'x'} * $b->to_bigint()->copy()->bmodinv($self->{'q'})) % $self->{'q'},
128 # );
129 #}
130  
131 7 1;
« blib/lib/Crypt/Perl/Math.pm ↑ Summary lib/Crypt/Perl/ECDSA/EncodedPoint.pm »