line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
5
|
|
|
5
|
|
556864
|
use 5.006002; |
|
5
|
|
|
|
|
15
|
|
2
|
5
|
|
|
5
|
|
23
|
use strict; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
123
|
|
3
|
5
|
|
|
5
|
|
21
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
296
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Math::EllipticCurve::Prime; |
6
|
|
|
|
|
|
|
{ |
7
|
|
|
|
|
|
|
$Math::EllipticCurve::Prime::VERSION = '0.003'; |
8
|
|
|
|
|
|
|
} |
9
|
|
|
|
|
|
|
# ABSTRACT: elliptic curve operations over prime fields |
10
|
|
|
|
|
|
|
|
11
|
5
|
|
|
5
|
|
20
|
use Math::BigInt 1.78 try => 'GMP,FastCalc'; |
|
5
|
|
|
|
|
88
|
|
|
5
|
|
|
|
|
24
|
|
12
|
5
|
|
|
5
|
|
4349
|
use Math::EllipticCurve::Prime::Point; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
2883
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our %predefined = ( |
16
|
|
|
|
|
|
|
secp112r1 => { |
17
|
|
|
|
|
|
|
p => "db7c2abf62e35e668076bead208b", |
18
|
|
|
|
|
|
|
a => "db7c2abf62e35e668076bead2088", |
19
|
|
|
|
|
|
|
b => "659ef8ba043916eede8911702b22", |
20
|
|
|
|
|
|
|
g => "0409487239995a5ee76b55f9c2f098a89ce5af8724c0a23e0e0ff77500", |
21
|
|
|
|
|
|
|
n => "db7c2abf62e35e7628dfac6561c5", |
22
|
|
|
|
|
|
|
h => "01", |
23
|
|
|
|
|
|
|
}, |
24
|
|
|
|
|
|
|
secp160r1 => { |
25
|
|
|
|
|
|
|
p => "ffffffffffffffffffffffffffffffff7fffffff", |
26
|
|
|
|
|
|
|
a => "ffffffffffffffffffffffffffffffff7ffffffc", |
27
|
|
|
|
|
|
|
b => "1c97befc54bd7a8b65acf89f81d4d4adc565fa45", |
28
|
|
|
|
|
|
|
g => "044a96b5688ef573284664698968c38bb913cbfc8223a628553168947d59dcc912042351377ac5fb32", |
29
|
|
|
|
|
|
|
n => "0100000000000000000001f4c8f927aed3ca752257", |
30
|
|
|
|
|
|
|
h => "01", |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
secp160r2 => { |
33
|
|
|
|
|
|
|
p => "fffffffffffffffffffffffffffffffeffffac73", |
34
|
|
|
|
|
|
|
a => "fffffffffffffffffffffffffffffffeffffac70", |
35
|
|
|
|
|
|
|
b => "b4e134d3fb59eb8bab57274904664d5af50388ba", |
36
|
|
|
|
|
|
|
g => "0452dcb034293a117e1f4ff11b30f7199d3144ce6dfeaffef2e331f296e071fa0df9982cfea7d43f2e", |
37
|
|
|
|
|
|
|
n => "0100000000000000000000351ee786a818f3a1a16b", |
38
|
|
|
|
|
|
|
h => "01", |
39
|
|
|
|
|
|
|
}, |
40
|
|
|
|
|
|
|
secp192k1 => { |
41
|
|
|
|
|
|
|
p => "fffffffffffffffffffffffffffffffffffffffeffffee37", |
42
|
|
|
|
|
|
|
a => "00", |
43
|
|
|
|
|
|
|
b => "03", |
44
|
|
|
|
|
|
|
g => "04db4ff10ec057e9ae26b07d0280b7f4341da5d1b1eae06c7d9b2f2f6d9c5628a7844163d015be86344082aa88d95e2f9d", |
45
|
|
|
|
|
|
|
n => "fffffffffffffffffffffffe26f2fc170f69466a74defd8d", |
46
|
|
|
|
|
|
|
h => "01", |
47
|
|
|
|
|
|
|
}, |
48
|
|
|
|
|
|
|
secp192r1 => { |
49
|
|
|
|
|
|
|
p => "fffffffffffffffffffffffffffffffeffffffffffffffff", |
50
|
|
|
|
|
|
|
a => "fffffffffffffffffffffffffffffffefffffffffffffffc", |
51
|
|
|
|
|
|
|
b => "64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1", |
52
|
|
|
|
|
|
|
g => "04188da80eb03090f67cbf20eb43a18800f4ff0afd82ff101207192b95ffc8da78631011ed6b24cdd573f977a11e794811", |
53
|
|
|
|
|
|
|
n => "ffffffffffffffffffffffff99def836146bc9b1b4d22831", |
54
|
|
|
|
|
|
|
h => "01", |
55
|
|
|
|
|
|
|
}, |
56
|
|
|
|
|
|
|
secp224r1 => { |
57
|
|
|
|
|
|
|
p => "ffffffffffffffffffffffffffffffff000000000000000000000001", |
58
|
|
|
|
|
|
|
a => "fffffffffffffffffffffffffffffffefffffffffffffffffffffffe", |
59
|
|
|
|
|
|
|
b => "b4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4", |
60
|
|
|
|
|
|
|
g => "04b70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21bd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34", |
61
|
|
|
|
|
|
|
n => "ffffffffffffffffffffffffffff16a2e0b8f03e13dd29455c5c2a3d", |
62
|
|
|
|
|
|
|
h => "01", |
63
|
|
|
|
|
|
|
}, |
64
|
|
|
|
|
|
|
secp256k1 => { |
65
|
|
|
|
|
|
|
p => "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f", |
66
|
|
|
|
|
|
|
a => "00", |
67
|
|
|
|
|
|
|
b => "07", |
68
|
|
|
|
|
|
|
g => "0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8", |
69
|
|
|
|
|
|
|
n => "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141", |
70
|
|
|
|
|
|
|
h => "01", |
71
|
|
|
|
|
|
|
}, |
72
|
|
|
|
|
|
|
secp256r1 => { |
73
|
|
|
|
|
|
|
p => "ffffffff00000001000000000000000000000000ffffffffffffffffffffffff", |
74
|
|
|
|
|
|
|
a => "ffffffff00000001000000000000000000000000fffffffffffffffffffffffc", |
75
|
|
|
|
|
|
|
b => "5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b", |
76
|
|
|
|
|
|
|
g => "046b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c2964fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5", |
77
|
|
|
|
|
|
|
n => "ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551", |
78
|
|
|
|
|
|
|
h => "01", |
79
|
|
|
|
|
|
|
}, |
80
|
|
|
|
|
|
|
secp384r1 => { |
81
|
|
|
|
|
|
|
p => "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff", |
82
|
|
|
|
|
|
|
a => "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc", |
83
|
|
|
|
|
|
|
b => "b3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef", |
84
|
|
|
|
|
|
|
g => "04aa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab73617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f", |
85
|
|
|
|
|
|
|
n => "ffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973", |
86
|
|
|
|
|
|
|
h => "01", |
87
|
|
|
|
|
|
|
}, |
88
|
|
|
|
|
|
|
secp521r1 => { |
89
|
|
|
|
|
|
|
p => "01ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", |
90
|
|
|
|
|
|
|
a => "01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc", |
91
|
|
|
|
|
|
|
b => "0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00", |
92
|
|
|
|
|
|
|
g => "0400c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650", |
93
|
|
|
|
|
|
|
n => "01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409", |
94
|
|
|
|
|
|
|
h => "01", |
95
|
|
|
|
|
|
|
}, |
96
|
|
|
|
|
|
|
); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
our %aliases = ( |
99
|
|
|
|
|
|
|
P192 => "secp192r1", |
100
|
|
|
|
|
|
|
P224 => "secp224r1", |
101
|
|
|
|
|
|
|
P256 => "secp256r1", |
102
|
|
|
|
|
|
|
P384 => "secp384r1", |
103
|
|
|
|
|
|
|
P521 => "secp521r1", |
104
|
|
|
|
|
|
|
); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub new { |
108
|
44
|
|
|
44
|
1
|
33758
|
my ($class, %args) = @_; |
109
|
|
|
|
|
|
|
|
110
|
44
|
100
|
|
|
|
161
|
return $class->from_name($args{name}) if $args{name}; |
111
|
|
|
|
|
|
|
|
112
|
17
|
|
|
|
|
32
|
my $self = \%args; |
113
|
17
|
|
33
|
|
|
93
|
$class = ref($class) || $class; |
114
|
17
|
|
|
|
|
28
|
bless $self, $class; |
115
|
17
|
|
|
|
|
59
|
return $self->init; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub from_name { |
120
|
27
|
|
|
27
|
1
|
34
|
my ($class, $name) = @_; |
121
|
27
|
100
|
|
|
|
75
|
$name = $aliases{$name} if defined $aliases{$name}; |
122
|
27
|
|
|
|
|
43
|
my $params = $predefined{$name}; |
123
|
27
|
100
|
|
|
|
72
|
return unless defined $params; |
124
|
17
|
|
|
|
|
104
|
my $self = $class->new(%$params); |
125
|
17
|
|
|
|
|
39
|
$self->{name} = $name; |
126
|
17
|
|
|
|
|
50
|
return $self; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub init { |
130
|
17
|
|
|
17
|
0
|
28
|
my $self = shift; |
131
|
17
|
|
|
|
|
37
|
foreach my $param (qw/p a b n h/) { |
132
|
|
|
|
|
|
|
$self->{$param} = Math::BigInt->new("0x$self->{$param}") |
133
|
85
|
50
|
|
|
|
30988
|
unless ref $self->{$param}; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
$self->{g} = Math::EllipticCurve::Prime::Point->from_hex($self->{g}) |
136
|
17
|
50
|
|
|
|
1261
|
unless ref $self->{g}; |
137
|
17
|
|
|
|
|
56
|
$self->{g}->curve($self); |
138
|
17
|
|
|
|
|
29
|
return $self; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub name { |
143
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
144
|
0
|
|
|
|
|
0
|
return $self->{name}; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub p { |
149
|
95178
|
|
|
95178
|
1
|
150181
|
my $self = shift; |
150
|
95178
|
|
|
|
|
210169
|
return $self->{p}; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub a { |
155
|
58573
|
|
|
58573
|
1
|
76053
|
my $self = shift; |
156
|
58573
|
|
|
|
|
150169
|
return $self->{a}; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub b { |
161
|
10
|
|
|
10
|
1
|
2162
|
my $self = shift; |
162
|
10
|
|
|
|
|
27
|
return $self->{b}; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub g { |
167
|
293
|
|
|
293
|
1
|
443662
|
my $self = shift; |
168
|
293
|
|
|
|
|
694
|
return $self->{g}; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub n { |
173
|
10
|
|
|
10
|
1
|
15
|
my $self = shift; |
174
|
10
|
|
|
|
|
38
|
return $self->{n}; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub h { |
179
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
180
|
0
|
|
|
|
|
|
return $self->{h}; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
1; |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
__END__ |