line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::Perl::ECDSA::EC::FieldElement; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
43
|
use strict; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
1478
|
|
4
|
7
|
|
|
7
|
|
32
|
use warnings; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
2910
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
#both bigint |
7
|
|
|
|
|
|
|
sub new { |
8
|
550594
|
|
|
550594
|
0
|
1168040
|
my ($class, $q, $x) = @_; |
9
|
|
|
|
|
|
|
|
10
|
550594
|
50
|
|
|
|
953775
|
die Crypt::Perl::X::create('Generic', 'Need both q and x!') if grep { !defined } $q, $x; |
|
1101188
|
|
|
|
|
2641215
|
|
11
|
|
|
|
|
|
|
|
12
|
550594
|
|
|
|
|
2551795
|
return bless { x => $x, q => $q }, $class; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#$other isa ECFieldElement |
16
|
|
|
|
|
|
|
sub equals { |
17
|
0
|
|
|
0
|
0
|
0
|
my ($self, $other) = @_; |
18
|
|
|
|
|
|
|
|
19
|
0
|
0
|
|
|
|
0
|
if ($other eq $self) { #??? |
20
|
0
|
|
|
|
|
0
|
return 1; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
0
|
|
|
0
|
return $self->{q}->beq($other->{q}) && $self->{x}->beq($other->{x}); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub to_bigint { |
27
|
960586
|
|
|
960586
|
0
|
4277914
|
my ($self) = @_; |
28
|
|
|
|
|
|
|
|
29
|
960586
|
|
|
|
|
2149078
|
return $self->{'x'}; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub negate { |
33
|
796
|
|
|
796
|
0
|
1896
|
my ($self) = @_; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
return (ref $self)->new( |
36
|
|
|
|
|
|
|
$self->{'q'}, |
37
|
796
|
|
|
|
|
3583
|
$self->{'x'}->copy()->bneg()->bmod($self->{'q'}), |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub add { |
42
|
0
|
|
|
0
|
0
|
|
my ($self, $b) = @_; |
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
|
|
|
0
|
0
|
|
my ($self, $b) = @_; |
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
|
|
|
0
|
0
|
|
my ($self, $b) = @_; |
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
|
|
|
0
|
0
|
|
my ($self) = @_; |
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
|
|
|
|
|
|
|
1; |