|  line  | 
 stmt  | 
 bran  | 
 cond  | 
 sub  | 
 pod  | 
 time  | 
 code  | 
| 
1
 | 
  
 
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 package Crypt::Perl::ECDSA::EncodedPoint;  | 
| 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
3
 | 
7
 | 
 
 | 
 
 | 
  
7
  
 | 
 
 | 
40
 | 
 use strict;  | 
| 
 
 | 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
14
 | 
    | 
| 
 
 | 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
159
 | 
    | 
| 
4
 | 
7
 | 
 
 | 
 
 | 
  
7
  
 | 
 
 | 
35
 | 
 use warnings;  | 
| 
 
 | 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
13
 | 
    | 
| 
 
 | 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
139
 | 
    | 
| 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
6
 | 
7
 | 
 
 | 
 
 | 
  
7
  
 | 
 
 | 
31
 | 
 use Try::Tiny;  | 
| 
 
 | 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
15
 | 
    | 
| 
 
 | 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
274
 | 
    | 
| 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
8
 | 
7
 | 
 
 | 
 
 | 
  
7
  
 | 
 
 | 
2583
 | 
 use Crypt::Perl::ECDSA::Utils ();  | 
| 
 
 | 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
19
 | 
    | 
| 
 
 | 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
126
 | 
    | 
| 
9
 | 
7
 | 
 
 | 
 
 | 
  
7
  
 | 
 
 | 
41
 | 
 use Crypt::Perl::X ();  | 
| 
 
 | 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
15
 | 
    | 
| 
 
 | 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2205
 | 
    | 
| 
10
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
11
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 #input can be a string or BigInt,  | 
| 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 #in any of “hybrid”, “uncompressed”, or “compressed” formats  | 
| 
13
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub new {  | 
| 
14
 | 
711
 | 
 
 | 
 
 | 
  
711
  
 | 
  
0
  
 | 
2336
 | 
     my ($class, $input) = @_;  | 
| 
15
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
16
 | 
711
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1435
 | 
     my $bin;  | 
| 
17
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     my $input_is_obj;  | 
| 
19
 | 
711
 | 
  
100
  
 | 
 
 | 
  
711
  
 | 
 
 | 
6737
 | 
     if ( try { $input->isa('Crypt::Perl::BigInt') } ) {  | 
| 
 
 | 
711
 | 
 
 | 
 
 | 
 
 | 
 
 | 
23225
 | 
    | 
| 
20
 | 
547
 | 
 
 | 
 
 | 
 
 | 
 
 | 
8919
 | 
         $bin = $input->as_bytes();  | 
| 
21
 | 
547
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1309
 | 
         $input_is_obj = 1;  | 
| 
22
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
23
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     else {  | 
| 
24
 | 
164
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2545
 | 
         $input =~ s<\A\0+><>;  | 
| 
25
 | 
164
 | 
 
 | 
 
 | 
 
 | 
 
 | 
455
 | 
         $bin = $input;  | 
| 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
27
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
28
 | 
711
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4151
 | 
     my $first_octet = ord substr( $bin, 0, 1 );  | 
| 
29
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
30
 | 
711
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1802
 | 
     my $self = bless {}, $class;  | 
| 
31
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     #Accommodate “hybrid” points  | 
| 
33
 | 
711
 | 
  
100
  
 | 
  
100
  
 | 
 
 | 
 
 | 
8346
 | 
     if ($first_octet == 6 || $first_octet == 7) {  | 
| 
 
 | 
 
 | 
  
100
  
 | 
  
 66
  
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
 
 | 
 
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
34
 | 
201
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1190
 | 
         $self->{'_bin'} = "\x04" . substr( $bin, 1 );  | 
| 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     elsif ($first_octet == 4) {  | 
| 
37
 | 
306
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1364
 | 
         $self->{'_bin'} = $bin;  | 
| 
38
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
39
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     elsif ($first_octet == 2 || $first_octet == 3) {  | 
| 
40
 | 
204
 | 
 
 | 
 
 | 
 
 | 
 
 | 
786
 | 
         $self->{'_compressed_bin'} = $bin;  | 
| 
41
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
42
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     else {  | 
| 
43
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
         die Crypt::Perl::X::Create('Generic', sprintf "Invalid leading octet in ECDSA point: %v02x", $bin);  | 
| 
44
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
45
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
46
 | 
711
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3861
 | 
     return $self;  | 
| 
47
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
48
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
49
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 #returns a string  | 
| 
50
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub get_compressed {  | 
| 
51
 | 
7
 | 
 
 | 
 
 | 
  
7
  
 | 
  
0
  
 | 
22
 | 
     my ($self) = @_;  | 
| 
52
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
53
 | 
7
 | 
 
 | 
  
 66
  
 | 
 
 | 
 
 | 
31
 | 
     return $self->{'_compressed_bin'} ||= do {  | 
| 
54
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
15
 | 
         Crypt::Perl::ECDSA::Utils::compress_point( $self->{'_bin'} );  | 
| 
55
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     };  | 
| 
56
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
57
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
58
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 #returns a string  | 
| 
59
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub get_uncompressed {  | 
| 
60
 | 
674
 | 
 
 | 
 
 | 
  
674
  
 | 
  
0
  
 | 
2245
 | 
     my ($self, $curve_hr) = @_;  | 
| 
61
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
62
 | 
674
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
2386
 | 
     die "Need curve! (p, a, b)" if !$curve_hr;  | 
| 
63
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
64
 | 
674
 | 
 
 | 
  
 66
  
 | 
 
 | 
 
 | 
5493
 | 
     return $self->{'_bin'} ||= do {  | 
| 
65
 | 
112
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
853
 | 
         die "Need compressed bin!" if !$self->{'_compressed_bin'};  | 
| 
66
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
67
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         Crypt::Perl::ECDSA::Utils::decompress_point(  | 
| 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             $self->{'_compressed_bin'},  | 
| 
69
 | 
112
 | 
 
 | 
 
 | 
 
 | 
 
 | 
805
 | 
             @{$curve_hr}{ qw( p a b ) },  | 
| 
 
 | 
112
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1653
 | 
    | 
| 
70
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         );  | 
| 
71
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     };  | 
| 
72
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
73
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
74
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 #If there’s ever a demand for “hybrid”:  | 
| 
75
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 #0x06 and 0x07 take the place of the uncompressed leading 0x04,  | 
| 
76
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 #analogous to 0x02 and 0x03 in the compressed form.  | 
| 
77
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
78
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 1;  |