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