« lib/Crypt/Perl/ECDSA/EC/FieldElement.pm
↑ Summary
lib/Crypt/Perl/X509/Extension/cRLDistributionPoints.pm »
| 1 | package Crypt::Perl::ECDSA::EncodedPoint; | ||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use Crypt::Perl::ECDSA::Utils (); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use Crypt::Perl::X (); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||
| 11 | #input can be a string or BigInt, | ||||||||||||||||||||||||||||||||||||
| 12 | #in any of “hybrid”, “uncompressed”, or “compressed” formats | ||||||||||||||||||||||||||||||||||||
| 13 | sub new { | ||||||||||||||||||||||||||||||||||||
| 14 | 711 | ▶ | my ($class, $input) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||
| 16 | 711 | my $bin; | |||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||
| 18 | my $input_is_obj; | ||||||||||||||||||||||||||||||||||||
| 19 | 711 | ▶ | if ( try { $input->isa('Crypt::Perl::BigInt') } ) { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 20 | 547 | $bin = $input->as_bytes(); | |||||||||||||||||||||||||||||||||||
| 21 | 547 | $input_is_obj = 1; | |||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||
| 23 | else { | ||||||||||||||||||||||||||||||||||||
| 24 | 164 | $input =~ s<\A\0+><>; | |||||||||||||||||||||||||||||||||||
| 25 | 164 | $bin = $input; | |||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||
| 28 | 711 | my $first_octet = ord substr( $bin, 0, 1 ); | |||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||
| 30 | 711 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||
| 32 | #Accommodate “hybrid” points | ||||||||||||||||||||||||||||||||||||
| 33 | 711 | ▶ | if ($first_octet == 6 || $first_octet == 7) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
$first_octet == 6 or $first_octet == 7
MC/DC100%2/2
$first_octet == 6 or $first_octet == 7
$first_octet == 6
$first_octet == 7
Truth table100%3/3
A or B
A= $first_octet == 6B= $first_octet == 7
| |||||||||||||||||||||||||||||||||||||
| 34 | 201 | $self->{'_bin'} = "\x04" . substr( $bin, 1 ); | |||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||
| 36 | elsif ($first_octet == 4) { | ||||||||||||||||||||||||||||||||||||
| 37 | 306 | $self->{'_bin'} = $bin; | |||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||
| 39 | ▶ | elsif ($first_octet == 2 || $first_octet == 3) { | |||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$first_octet == 2 or $first_octet == 3
MC/DC0%0/2
$first_octet == 2 or $first_octet == 3
$first_octet == 2
$first_octet == 3
Truth table66%2/3
A or B
A= $first_octet == 2B= $first_octet == 3
| |||||||||||||||||||||||||||||||||||||
| 40 | 204 | $self->{'_compressed_bin'} = $bin; | |||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||
| 42 | else { | ||||||||||||||||||||||||||||||||||||
| 43 | 0 | die Crypt::Perl::X::Create('Generic', sprintf "Invalid leading octet in ECDSA point: %v02x", $bin); | |||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||
| 46 | 711 | return $self; | |||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||
| 49 | #returns a string | ||||||||||||||||||||||||||||||||||||
| 50 | sub get_compressed { | ||||||||||||||||||||||||||||||||||||
| 51 | 7 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
get_compressed: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||
| 53 | 7 | ▶ | return $self->{'_compressed_bin'} ||= do { | ||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"_compressed_bin"} ||= do {
Crypt::Perl::ECDSA::Utils::compress_point($self->{"_bin"})
}
MC/DC0%0/2
$self->{"_compressed_bin"} ||= do {
Crypt::Perl::ECDSA::Utils::compress_point($self->{"_bin"})
}
$self->{"_compressed_bin"}
do {
Crypt::Perl::ECDSA::Utils::compress_point($self->{"_bin"})
}
Truth table66%2/3
A ||= B
A= $self->{"_compressed_bin"}B= do {
Crypt::Perl::ECDSA::Utils::compress_point($self->{"_bin"})
}
| |||||||||||||||||||||||||||||||||||||
| 54 | 3 | Crypt::Perl::ECDSA::Utils::compress_point( $self->{'_bin'} ); | |||||||||||||||||||||||||||||||||||
| 55 | }; | ||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||
| 58 | #returns a string | ||||||||||||||||||||||||||||||||||||
| 59 | sub get_uncompressed { | ||||||||||||||||||||||||||||||||||||
| 60 | 674 | ▶ | my ($self, $curve_hr) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
get_uncompressed: called CC=4 SCAR=14.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||
| 62 | 674 | ▶ | die "Need curve! (p, a, b)" if !$curve_hr; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||
| 64 | 674 | ▶ | return $self->{'_bin'} ||= do { | ||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"_bin"} ||= do {
die "Need compressed bin!" unless $self->{"_compressed_bin"};
Crypt::Perl::ECDSA::Utils::decompress_point($self->{"_compressed_bin"}, @{$curve_hr;}{"p", "a", "b"})
}
MC/DC0%0/2
$self->{"_bin"} ||= do {
die "Need compressed bin!" unless $self->{"_compressed_bin"};
Crypt::Perl::ECDSA::Utils::decompress_point($self->{"_compressed_bin"}, @{$curve_hr;}{"p", "a", "b"})
}
$self->{"_bin"}
do {
die "Need compressed bin!" unless $self->{"_compressed_bin"};
Crypt::Perl::ECDSA::Utils::decompress_point($self->{"_compressed_bin"}, @{$curve_hr;}{"p", "a", "b"})
}
Truth table66%2/3
A ||= B
A= $self->{"_bin"}B= do {
die "Need compressed bin!" unless $self->{"_compressed_bin"};
Crypt::Perl::ECDSA::Utils::decompress_point($self->{"_compressed_bin"}, @{$curve_hr;}{"p", "a", "b"})
}
| |||||||||||||||||||||||||||||||||||||
| 65 | 112 | ▶ | die "Need compressed bin!" if !$self->{'_compressed_bin'}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||
| 67 | Crypt::Perl::ECDSA::Utils::decompress_point( | ||||||||||||||||||||||||||||||||||||
| 68 | $self->{'_compressed_bin'}, | ||||||||||||||||||||||||||||||||||||
| 69 | 112 | @{$curve_hr}{ qw( p a b ) }, | |||||||||||||||||||||||||||||||||||
| 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 | 7 | 1; | |||||||||||||||||||||||||||||||||||