line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypto::ECC::PublicKey; |
2
|
|
|
|
|
|
|
$Crypto::ECC::PublicKey::VERSION = '0.003'; |
3
|
1
|
|
|
1
|
|
7
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
4
|
1
|
|
|
1
|
|
293
|
use Crypto::ECC::Point; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
501
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
with "Object::GMP"; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has generator => ( is => 'ro' ); |
9
|
|
|
|
|
|
|
has point => ( is => 'ro' ); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $Point = 'Crypto::ECC::Point'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub BUILD { |
14
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
15
|
|
|
|
|
|
|
|
16
|
0
|
0
|
|
|
|
|
my $n = $self->generator->order |
17
|
|
|
|
|
|
|
or die 'Generator Must have order.'; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $p = $self->point; |
20
|
|
|
|
|
|
|
|
21
|
0
|
0
|
|
|
|
|
if ( $Point->cmp( $Point->mul( $n, $p ), $Point->infinity ) != 0 ) { |
22
|
0
|
|
|
|
|
|
die "Generator Point order is bad."; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
0
|
0
|
0
|
|
|
|
if ( ( $p->x <=> 0 ) < 0 |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
26
|
|
|
|
|
|
|
|| ( $n <=> $p->x ) <= 0 |
27
|
|
|
|
|
|
|
|| ( $p->y <=> 0 ) < 0 |
28
|
|
|
|
|
|
|
|| ( $n <=> $p->y ) <= 0 ) |
29
|
|
|
|
|
|
|
{ |
30
|
0
|
|
|
|
|
|
die "Generator Point has x and y out of range."; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub verifies { |
35
|
0
|
|
|
0
|
0
|
|
my ( $self, $hash, $signature ) = @_; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my $_g = $self->generator; |
38
|
0
|
|
|
|
|
|
my $n = $_g->order; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $r = $signature->r; |
41
|
0
|
|
|
|
|
|
my $s = $signature->s; |
42
|
|
|
|
|
|
|
|
43
|
0
|
0
|
0
|
|
|
|
if ( ( $r <=> 1 ) < 0 || ( $r <=> ( $n - 1 ) ) > 0 ) { |
44
|
0
|
|
|
|
|
|
return 0; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
0
|
|
|
|
if ( ( $s <=> 1 ) < 0 || ( $s <=> ( $n - 1 ) ) > 0 ) { |
48
|
0
|
|
|
|
|
|
return 0; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $c = $s->copy->bmodinv($n); |
52
|
0
|
|
|
|
|
|
my $u1 = ( $hash * $c ) % $n; |
53
|
0
|
|
|
|
|
|
my $u2 = ( $r * $c ) % $n; |
54
|
0
|
|
|
|
|
|
my $xy = |
55
|
|
|
|
|
|
|
$Point->add( $Point->mul( $u1, $_g ), $Point->mul( $u2, $self->point ) ); |
56
|
0
|
|
|
|
|
|
my $v = $xy->x % $n; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
return $v == $r; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub hashref { |
62
|
0
|
|
|
0
|
0
|
|
my ( $self, %options ) = @_; |
63
|
0
|
|
|
|
|
|
my %hash = map { ; $_ => $self->$_->hashref(%options) } keys %$self; |
|
0
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
return \%hash; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |