| 1 | package Crypt::Sodium::XS::curve25519; | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use Crypt::Sodium::XS; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Exporter 'import'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | _define_constants(); | |||||||||
| 9 | |||||||||||
| 10 | { | ||||||||||
| 11 | 1 | my @constant_bases = qw( | |||||||||
| 12 | BYTES | ||||||||||
| 13 | NONREDUCEDSCALARBYTES | ||||||||||
| 14 | SCALARBYTES | ||||||||||
| 15 | ); | ||||||||||
| 16 | |||||||||||
| 17 | 1 | my @bases = qw( | |||||||||
| 18 | add | ||||||||||
| 19 | is_valid_point | ||||||||||
| 20 | random | ||||||||||
| 21 | scalar_add | ||||||||||
| 22 | scalar_complement | ||||||||||
| 23 | scalar_mul | ||||||||||
| 24 | scalar_negate | ||||||||||
| 25 | scalar_random | ||||||||||
| 26 | scalar_reduce | ||||||||||
| 27 | scalar_sub | ||||||||||
| 28 | sub | ||||||||||
| 29 | ); | ||||||||||
| 30 | |||||||||||
| 31 | my $ed25519 = [ | ||||||||||
| 32 | 12 | (map { "core_ed25519_$_" } @bases, "from_uniform"), | |||||||||
| 33 | 1 | (map { "core_ed25519_$_" } @constant_bases, "UNIFORMBYTES"), | |||||||||
| 34 | ]; | ||||||||||
| 35 | |||||||||||
| 36 | my $ristretto255 = [ | ||||||||||
| 37 | 12 | (map { "core_ristretto255_$_" } @bases, "from_hash"), | |||||||||
| 38 | 1 | (map { "core_ristretto255_$_" } @constant_bases, "HASHBYTES"), | |||||||||
| 39 | ]; | ||||||||||
| 40 | |||||||||||
| 41 | 1 | my $features = [qw[ | |||||||||
| 42 | core_ristretto255_available | ||||||||||
| 43 | ]]; | ||||||||||
| 44 | |||||||||||
| 45 | 1 | our %EXPORT_TAGS = ( | |||||||||
| 46 | all => [ @$features, @$ed25519, @$ristretto255, @$features, ], | ||||||||||
| 47 | features => $features, | ||||||||||
| 48 | ed25519 => $ed25519, | ||||||||||
| 49 | features => $features, | ||||||||||
| 50 | ristretto255 => $ristretto255, | ||||||||||
| 51 | ); | ||||||||||
| 52 | |||||||||||
| 53 | 1 | our @EXPORT_OK = @{$EXPORT_TAGS{all}}; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 1 | *ristretto255_available = \&core_ristretto255_available; | |||||||||
| 57 | |||||||||||
| 58 | package Crypt::Sodium::XS::OO::curve25519; | ||||||||||
| 59 | 1 | ▶ | use parent 'Crypt::Sodium::XS::OO::Base'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 60 | |||||||||||
| 61 | my %methods = ( | ||||||||||
| 62 | ed25519 => { | ||||||||||
| 63 | BYTES => \&Crypt::Sodium::XS::curve25519::core_ed25519_BYTES, | ||||||||||
| 64 | 0 | ▶ | HASHBYTES => sub { die 'HASHBYTES only supported by ristretto255 primitive' }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 65 | NONREDUCEDSCALARBYTES => \&Crypt::Sodium::XS::curve25519::core_ed25519_NONREDUCEDSCALARBYTES, | ||||||||||
| 66 | 0 | ▶ | PRIMITIVE => sub { 'ed25519' }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 67 | SCALARBYTES => \&Crypt::Sodium::XS::curve25519::core_ed25519_SCALARBYTES, | ||||||||||
| 68 | UNIFORMBYTES => \&Crypt::Sodium::XS::curve25519::core_ed25519_UNIFORMBYTES, | ||||||||||
| 69 | add => \&Crypt::Sodium::XS::curve25519::core_ed25519_add, | ||||||||||
| 70 | 0 | ▶ | from_hash => sub { die 'from_hash only supported by ristretto255 primitive' }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 71 | from_uniform => \&Crypt::Sodium::XS::curve25519::core_ed25519_from_uniform, | ||||||||||
| 72 | is_valid_point => \&Crypt::Sodium::XS::curve25519::core_ed25519_is_valid_point, | ||||||||||
| 73 | random => \&Crypt::Sodium::XS::curve25519::core_ed25519_random, | ||||||||||
| 74 | scalar_add => \&Crypt::Sodium::XS::curve25519::core_ed25519_scalar_add, | ||||||||||
| 75 | scalar_complement => \&Crypt::Sodium::XS::curve25519::core_ed25519_scalar_complement, | ||||||||||
| 76 | scalar_mul => \&Crypt::Sodium::XS::curve25519::core_ed25519_scalar_mul, | ||||||||||
| 77 | scalar_negate => \&Crypt::Sodium::XS::curve25519::core_ed25519_scalar_negate, | ||||||||||
| 78 | scalar_random => \&Crypt::Sodium::XS::curve25519::core_ed25519_scalar_random, | ||||||||||
| 79 | scalar_reduce => \&Crypt::Sodium::XS::curve25519::core_ed25519_scalar_reduce, | ||||||||||
| 80 | scalar_sub => \&Crypt::Sodium::XS::curve25519::core_ed25519_scalar_sub, | ||||||||||
| 81 | sub => \&Crypt::Sodium::XS::curve25519::core_ed25519_sub, | ||||||||||
| 82 | }, | ||||||||||
| 83 | Crypt::Sodium::XS::curve25519->ristretto255_available ? ( | ||||||||||
| 84 | ristretto255 => { | ||||||||||
| 85 | BYTES => \&Crypt::Sodium::XS::curve25519::core_ristretto255_BYTES, | ||||||||||
| 86 | HASHBYTES => \&Crypt::Sodium::XS::curve25519::core_ristretto255_HASHBYTES, | ||||||||||
| 87 | NONREDUCEDSCALARBYTES => \&Crypt::Sodium::XS::curve25519::core_ristretto255_NONREDUCEDSCALARBYTES, | ||||||||||
| 88 | 0 | ▶ | PRIMITIVE => sub { 'ristretto255' }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 89 | SCALARBYTES => \&Crypt::Sodium::XS::curve25519::core_ristretto255_SCALARBYTES, | ||||||||||
| 90 | 0 | ▶ | UNIFORMBYTES => sub { die 'UNIFORMBYTES only supported by ed25519 primitive' }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 91 | add => \&Crypt::Sodium::XS::curve25519::core_ristretto255_add, | ||||||||||
| 92 | from_hash => \&Crypt::Sodium::XS::curve25519::core_ristretto255_from_hash, | ||||||||||
| 93 | 0 | ▶ | from_uniform => sub { die 'from_uniform only supported by ed25519 primitive' }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 94 | 1 | ▶ | is_valid_point => \&Crypt::Sodium::XS::curve25519::core_ristretto255_is_valid_point, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 95 | random => \&Crypt::Sodium::XS::curve25519::core_ristretto255_random, | ||||||||||
| 96 | scalar_add => \&Crypt::Sodium::XS::curve25519::core_ristretto255_scalar_add, | ||||||||||
| 97 | scalar_complement => \&Crypt::Sodium::XS::curve25519::core_ristretto255_scalar_complement, | ||||||||||
| 98 | scalar_mul => \&Crypt::Sodium::XS::curve25519::core_ristretto255_scalar_mul, | ||||||||||
| 99 | scalar_negate => \&Crypt::Sodium::XS::curve25519::core_ristretto255_scalar_negate, | ||||||||||
| 100 | scalar_random => \&Crypt::Sodium::XS::curve25519::core_ristretto255_scalar_random, | ||||||||||
| 101 | scalar_reduce => \&Crypt::Sodium::XS::curve25519::core_ristretto255_scalar_reduce, | ||||||||||
| 102 | scalar_sub => \&Crypt::Sodium::XS::curve25519::core_ristretto255_scalar_sub, | ||||||||||
| 103 | sub => \&Crypt::Sodium::XS::curve25519::core_ristretto255_sub, | ||||||||||
| 104 | }, | ||||||||||
| 105 | ) : (), | ||||||||||
| 106 | ); | ||||||||||
| 107 | |||||||||||
| 108 | 4 | ▶ | sub Crypt::Sodium::XS::curve25519::primitives { keys %methods } | ||||||||
|
Subroutine
primitives: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 109 | 1 | *primitives = \&Crypt::Sodium::XS::curve25519::primitives; | |||||||||
| 110 | 1 | *ristretto255_available = \&Crypt::Sodium::XS::curve25519::ristretto255_available; | |||||||||
| 111 | |||||||||||
| 112 | 2 | ▶ | sub BYTES { my $self = shift; goto $methods{$self->{primitive}}->{BYTES}; } | ||||||||
|
Subroutine
BYTES: called CC=1 SCAR=0.0
| |||||||||||
| 113 | 0 | ▶ | sub HASHBYTES { my $self = shift; goto $methods{$self->{primitive}}->{HASHBYTES}; } | ||||||||
|
Subroutine
HASHBYTES: not called CC=1 SCAR=6.9
| |||||||||||
| 114 | 0 | ▶ | sub NONREDUCEDSCALARBYTES { my $self = shift; goto $methods{$self->{primitive}}->{NONREDUCEDSCALARBYTES}; } | ||||||||
|
Subroutine
NONREDUCEDSCALARBYTES: not called CC=1 SCAR=6.9
| |||||||||||
| 115 | 0 | ▶ | sub PRIMITIVE { my $self = shift; goto $methods{$self->{primitive}}->{PRIMITIVE}; } | ||||||||
|
Subroutine
PRIMITIVE: not called CC=1 SCAR=6.9
| |||||||||||
| 116 | 8 | ▶ | sub SCALARBYTES { my $self = shift; goto $methods{$self->{primitive}}->{SCALARBYTES}; } | ||||||||
|
Subroutine
SCALARBYTES: called CC=1 SCAR=0.0
| |||||||||||
| 117 | 0 | ▶ | sub UNIFORMBYTES { my $self = shift; goto $methods{$self->{primitive}}->{UNIFORMBYTES}; } | ||||||||
|
Subroutine
UNIFORMBYTES: not called CC=1 SCAR=6.9
| |||||||||||
| 118 | 4 | ▶ | sub add { my $self = shift; goto $methods{$self->{primitive}}->{add}; } | ||||||||
|
Subroutine
add: called CC=1 SCAR=0.0
| |||||||||||
| 119 | 0 | ▶ | sub from_hash { my $self = shift; goto $methods{$self->{primitive}}->{from_hash}; } | ||||||||
|
Subroutine
from_hash: not called CC=1 SCAR=6.9
| |||||||||||
| 120 | 0 | ▶ | sub from_uniform { my $self = shift; goto $methods{$self->{primitive}}->{from_uniform}; } | ||||||||
|
Subroutine
from_uniform: not called CC=1 SCAR=6.9
| |||||||||||
| 121 | 2 | ▶ | sub is_valid_point { my $self = shift; goto $methods{$self->{primitive}}->{is_valid_point}; } | ||||||||
|
Subroutine
is_valid_point: called CC=1 SCAR=0.0
| |||||||||||
| 122 | 2 | ▶ | sub random { my $self = shift; goto $methods{$self->{primitive}}->{random}; } | ||||||||
|
Subroutine
random: called CC=1 SCAR=0.0
| |||||||||||
| 123 | 0 | ▶ | sub scalar_add { my $self = shift; goto $methods{$self->{primitive}}->{scalar_add}; } | ||||||||
|
Subroutine
scalar_add: not called CC=1 SCAR=6.9
| |||||||||||
| 124 | 0 | ▶ | sub scalar_complement { my $self = shift; goto $methods{$self->{primitive}}->{scalar_complement}; } | ||||||||
|
Subroutine
scalar_complement: not called CC=1 SCAR=6.9
| |||||||||||
| 125 | 0 | ▶ | sub scalar_mul { my $self = shift; goto $methods{$self->{primitive}}->{scalar_mul}; } | ||||||||
|
Subroutine
scalar_mul: not called CC=1 SCAR=6.9
| |||||||||||
| 126 | 2 | ▶ | sub scalar_negate { my $self = shift; goto $methods{$self->{primitive}}->{scalar_negate}; } | ||||||||
|
Subroutine
scalar_negate: called CC=1 SCAR=0.0
| |||||||||||
| 127 | 4 | ▶ | sub scalar_random { my $self = shift; goto $methods{$self->{primitive}}->{scalar_random}; } | ||||||||
|
Subroutine
scalar_random: called CC=1 SCAR=0.0
| |||||||||||
| 128 | 0 | ▶ | sub scalar_reduce { my $self = shift; goto $methods{$self->{primitive}}->{scalar_reduce}; } | ||||||||
|
Subroutine
scalar_reduce: not called CC=1 SCAR=6.9
| |||||||||||
| 129 | 0 | ▶ | sub scalar_sub { my $self = shift; goto $methods{$self->{primitive}}->{scalar_sub}; } | ||||||||
|
Subroutine
scalar_sub: not called CC=1 SCAR=6.9
| |||||||||||
| 130 | 0 | ▶ | sub sub { my $self = shift; goto $methods{$self->{primitive}}->{sub}; } | ||||||||
|
Subroutine
sub: not called CC=1 SCAR=6.9
| |||||||||||
| 131 | |||||||||||
| 132 | 1 | 1; | |||||||||
| 133 | |||||||||||
| 134 | __END__ | ||||||||||