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

filter: Statementstmt 0.0% 0 / 26 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 51 CC 3 SCAR 12.0
CC
3
Cov
0%
new
6.0
equals
6.0
to_bigint
2.0
CRAP 3.3
1 package Crypt::Perl::ECDSA::EC::FieldElement;
2  
3 use strict;
4 use warnings;
5  
6 #both bigint
7 sub new {
8 my ($class, $q, $x) = @_;
9  
10 die Crypt::Perl::X::create('Generic', 'Need both q and x!') if grep { !defined } $q, $x;
11  
12 return bless { x => $x, q => $q }, $class;
13 }
14  
15 #$other isa ECFieldElement
16 sub equals {
17 my ($self, $other) = @_;
18  
19 if ($other eq $self) { #???
20 return 1;
21 }
22  
23 return $self->{q}->beq($other->{q}) && $self->{x}->beq($other->{x});
24 }
25  
26 sub to_bigint {
27 my ($self) = @_;
28  
29 return $self->{'x'};
30 }
31  
32 sub negate {
33 my ($self) = @_;
34  
35 return (ref $self)->new(
36 $self->{'q'},
37 $self->{'x'}->copy()->bneg()->bmod($self->{'q'}),
38 );
39 }
40  
41 sub add {
42 my ($self, $b) = @_;
43  
44 return $self->new(
45 $self->{'q'},
46 $self->{'x'}->copy()->badd($b->to_bigint())->bmod($self->{'q'}),
47 );
48 }
49  
50 sub subtract {
51 my ($self, $b) = @_;
52  
53 return $self->new(
54 $self->{'q'},
55 $self->{'x'}->copy()->bsub($b->to_bigint())->bmod($self->{'q'}),
56 );
57 }
58  
59 sub multiply {
60 my ($self, $b) = @_;
61  
62 return $self->new(
63 $self->{'q'},
64 $self->{'x'}->copy()->bmul($b->to_bigint())->bmod($self->{'q'}),
65 );
66 }
67  
68 sub square {
69 my ($self) = @_;
70  
71 return $self->new(
72 $self->{'q'},
73 $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 1;