| 1 | package Crypt::Sodium::XS::aead; | ||||||||||||||
| 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 | ABYTES | ||||||||||||||
| 13 | KEYBYTES | ||||||||||||||
| 14 | MESSAGEBYTES_MAX | ||||||||||||||
| 15 | NPUBBYTES | ||||||||||||||
| 16 | NSECBYTES | ||||||||||||||
| 17 | ); | ||||||||||||||
| 18 | |||||||||||||||
| 19 | 1 | my @bases = qw( | |||||||||||||
| 20 | decrypt | ||||||||||||||
| 21 | decrypt_detached | ||||||||||||||
| 22 | encrypt | ||||||||||||||
| 23 | encrypt_detached | ||||||||||||||
| 24 | keygen | ||||||||||||||
| 25 | nonce | ||||||||||||||
| 26 | ); | ||||||||||||||
| 27 | |||||||||||||||
| 28 | # NB: no generic functions for aead | ||||||||||||||
| 29 | |||||||||||||||
| 30 | my $chacha20poly1305 = [ | ||||||||||||||
| 31 | 6 | (map { "aead_chacha20poly1305_$_" } @bases), | |||||||||||||
| 32 | 1 | (map { "aead_chacha20poly1305_$_" } @constant_bases), | |||||||||||||
| 33 | ]; | ||||||||||||||
| 34 | |||||||||||||||
| 35 | my $chacha20poly1305_ietf = [ | ||||||||||||||
| 36 | 6 | (map { "aead_chacha20poly1305_ietf_$_" } @bases), | |||||||||||||
| 37 | 1 | (map { "aead_chacha20poly1305_ietf_$_" } @constant_bases), | |||||||||||||
| 38 | ]; | ||||||||||||||
| 39 | |||||||||||||||
| 40 | my $aes256gcm = [ | ||||||||||||||
| 41 | 7 | (map { "aead_aes256gcm_$_" } @bases, "beforenm"), | |||||||||||||
| 42 | 1 | (map { "aead_aes256gcm_$_" } @constant_bases), | |||||||||||||
| 43 | ]; | ||||||||||||||
| 44 | |||||||||||||||
| 45 | my $xchacha20poly1305_ietf = [ | ||||||||||||||
| 46 | 6 | (map { "aead_xchacha20poly1305_ietf_$_" } @bases), | |||||||||||||
| 47 | 1 | (map { "aead_xchacha20poly1305_ietf_$_" } @constant_bases), | |||||||||||||
| 48 | ]; | ||||||||||||||
| 49 | |||||||||||||||
| 50 | my $aegis128l = [ | ||||||||||||||
| 51 | 6 | (map { "aead_aegis128l_$_" } @bases), | |||||||||||||
| 52 | 1 | (map { "aead_aegis128l_$_" } @constant_bases), | |||||||||||||
| 53 | ]; | ||||||||||||||
| 54 | |||||||||||||||
| 55 | my $aegis256 = [ | ||||||||||||||
| 56 | 6 | (map { "aead_aegis256_$_" } @bases), | |||||||||||||
| 57 | 1 | (map { "aead_aegis256_$_" } @constant_bases), | |||||||||||||
| 58 | ]; | ||||||||||||||
| 59 | |||||||||||||||
| 60 | 1 | my $features = [qw[ | |||||||||||||
| 61 | aead_aes256gcm_available | ||||||||||||||
| 62 | aead_aegis_available | ||||||||||||||
| 63 | ]]; | ||||||||||||||
| 64 | |||||||||||||||
| 65 | 1 | our %EXPORT_TAGS = ( | |||||||||||||
| 66 | all => [ @$chacha20poly1305, @$chacha20poly1305_ietf, | ||||||||||||||
| 67 | @$aes256gcm, @$xchacha20poly1305_ietf, | ||||||||||||||
| 68 | @$aegis128l, @$aegis256, @$features, | ||||||||||||||
| 69 | ], | ||||||||||||||
| 70 | chacha20poly1305 => $chacha20poly1305, | ||||||||||||||
| 71 | chacha20poly1305_ietf => $chacha20poly1305_ietf, | ||||||||||||||
| 72 | aes256gcm => $aes256gcm, | ||||||||||||||
| 73 | xchacha20poly1305_ietf => $xchacha20poly1305_ietf, | ||||||||||||||
| 74 | aegis128l => $aegis128l, | ||||||||||||||
| 75 | aegis256 => $aegis256, | ||||||||||||||
| 76 | features => $features, | ||||||||||||||
| 77 | ); | ||||||||||||||
| 78 | |||||||||||||||
| 79 | 1 | our @EXPORT_OK = @{$EXPORT_TAGS{all}}; | |||||||||||||
| 80 | } | ||||||||||||||
| 81 | |||||||||||||||
| 82 | 1 | *aes256gcm_available = \&aead_aes256gcm_available; | |||||||||||||
| 83 | 1 | *aegis_available = \&aead_aegis_available; | |||||||||||||
| 84 | |||||||||||||||
| 85 | package Crypt::Sodium::XS::OO::aead; | ||||||||||||||
| 86 | 1 | ▶ | use parent 'Crypt::Sodium::XS::OO::Base'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 87 | |||||||||||||||
| 88 | my %methods = ( | ||||||||||||||
| 89 | chacha20poly1305 => { | ||||||||||||||
| 90 | ABYTES => \&Crypt::Sodium::XS::aead::aead_chacha20poly1305_ABYTES, | ||||||||||||||
| 91 | KEYBYTES => \&Crypt::Sodium::XS::aead::aead_chacha20poly1305_KEYBYTES, | ||||||||||||||
| 92 | MESSAGEBYTES_MAX => \&Crypt::Sodium::XS::aead::aead_chacha20poly1305_MESSAGEBYTES_MAX, | ||||||||||||||
| 93 | NPUBBYTES => \&Crypt::Sodium::XS::aead::aead_chacha20poly1305_NPUBBYTES, | ||||||||||||||
| 94 | 0 | ▶ | PRIMITIVE => sub { 'chacha20poly1305' }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 95 | 0 | ▶ | beforenm => sub { die "beforenm is only supported for the aes256gcm primitive" }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 96 | decrypt => \&Crypt::Sodium::XS::aead::aead_chacha20poly1305_decrypt, | ||||||||||||||
| 97 | decrypt_detached => \&Crypt::Sodium::XS::aead::aead_chacha20poly1305_decrypt_detached, | ||||||||||||||
| 98 | encrypt => \&Crypt::Sodium::XS::aead::aead_chacha20poly1305_encrypt, | ||||||||||||||
| 99 | encrypt_detached => \&Crypt::Sodium::XS::aead::aead_chacha20poly1305_encrypt_detached, | ||||||||||||||
| 100 | keygen => \&Crypt::Sodium::XS::aead::aead_chacha20poly1305_keygen, | ||||||||||||||
| 101 | nonce => \&Crypt::Sodium::XS::aead::aead_chacha20poly1305_nonce, | ||||||||||||||
| 102 | }, | ||||||||||||||
| 103 | chacha20poly1305_ietf => { | ||||||||||||||
| 104 | ABYTES => \&Crypt::Sodium::XS::aead::aead_chacha20poly1305_ietf_ABYTES, | ||||||||||||||
| 105 | KEYBYTES => \&Crypt::Sodium::XS::aead::aead_chacha20poly1305_ietf_KEYBYTES, | ||||||||||||||
| 106 | MESSAGEBYTES_MAX => \&Crypt::Sodium::XS::aead::aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX, | ||||||||||||||
| 107 | NPUBBYTES => \&Crypt::Sodium::XS::aead::aead_chacha20poly1305_ietf_NPUBBYTES, | ||||||||||||||
| 108 | 0 | ▶ | PRIMITIVE => sub { 'chacha20poly1305_ietf' }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 109 | 0 | ▶ | beforenm => sub { die "beforenm is only supported for the aes256gcm primitive" }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 110 | decrypt => \&Crypt::Sodium::XS::aead::aead_chacha20poly1305_ietf_decrypt, | ||||||||||||||
| 111 | decrypt_detached => \&Crypt::Sodium::XS::aead::aead_chacha20poly1305_ietf_decrypt_detached, | ||||||||||||||
| 112 | encrypt => \&Crypt::Sodium::XS::aead::aead_chacha20poly1305_ietf_encrypt, | ||||||||||||||
| 113 | encrypt_detached => \&Crypt::Sodium::XS::aead::aead_chacha20poly1305_ietf_encrypt_detached, | ||||||||||||||
| 114 | keygen => \&Crypt::Sodium::XS::aead::aead_chacha20poly1305_ietf_keygen, | ||||||||||||||
| 115 | nonce => \&Crypt::Sodium::XS::aead::aead_chacha20poly1305_ietf_nonce, | ||||||||||||||
| 116 | }, | ||||||||||||||
| 117 | Crypt::Sodium::XS::aead->aegis_available ? ( | ||||||||||||||
| 118 | aegis128l => { | ||||||||||||||
| 119 | ABYTES => \&Crypt::Sodium::XS::aead::aead_aegis128l_ABYTES, | ||||||||||||||
| 120 | KEYBYTES => \&Crypt::Sodium::XS::aead::aead_aegis128l_KEYBYTES, | ||||||||||||||
| 121 | MESSAGEBYTES_MAX => \&Crypt::Sodium::XS::aead::aead_aegis128l_MESSAGEBYTES_MAX, | ||||||||||||||
| 122 | NPUBBYTES => \&Crypt::Sodium::XS::aead::aead_aegis128l_NPUBBYTES, | ||||||||||||||
| 123 | 0 | ▶ | PRIMITIVE => sub { 'aegis128l' }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 124 | 0 | ▶ | beforenm => sub { die "beforenm is only supported for the aes256gcm primitive" }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 125 | decrypt => \&Crypt::Sodium::XS::aead::aead_aegis128l_decrypt, | ||||||||||||||
| 126 | decrypt_detached => \&Crypt::Sodium::XS::aead::aead_aegis128l_decrypt_detached, | ||||||||||||||
| 127 | encrypt => \&Crypt::Sodium::XS::aead::aead_aegis128l_encrypt, | ||||||||||||||
| 128 | encrypt_detached => \&Crypt::Sodium::XS::aead::aead_aegis128l_encrypt_detached, | ||||||||||||||
| 129 | keygen => \&Crypt::Sodium::XS::aead::aead_aegis128l_keygen, | ||||||||||||||
| 130 | nonce => \&Crypt::Sodium::XS::aead::aead_aegis128l_nonce, | ||||||||||||||
| 131 | }, | ||||||||||||||
| 132 | aegis256 => { | ||||||||||||||
| 133 | ABYTES => \&Crypt::Sodium::XS::aead::aead_aegis256_ABYTES, | ||||||||||||||
| 134 | KEYBYTES => \&Crypt::Sodium::XS::aead::aead_aegis256_KEYBYTES, | ||||||||||||||
| 135 | MESSAGEBYTES_MAX => \&Crypt::Sodium::XS::aead::aead_aegis256_MESSAGEBYTES_MAX, | ||||||||||||||
| 136 | NPUBBYTES => \&Crypt::Sodium::XS::aead::aead_aegis256_NPUBBYTES, | ||||||||||||||
| 137 | 0 | ▶ | PRIMITIVE => sub { 'aegis256' }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 138 | 0 | ▶ | beforenm => sub { die "beforenm is only supported for the aes256gcm primitive" }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 139 | decrypt => \&Crypt::Sodium::XS::aead::aead_aegis256_decrypt, | ||||||||||||||
| 140 | decrypt_detached => \&Crypt::Sodium::XS::aead::aead_aegis256_decrypt_detached, | ||||||||||||||
| 141 | encrypt => \&Crypt::Sodium::XS::aead::aead_aegis256_encrypt, | ||||||||||||||
| 142 | encrypt_detached => \&Crypt::Sodium::XS::aead::aead_aegis256_encrypt_detached, | ||||||||||||||
| 143 | keygen => \&Crypt::Sodium::XS::aead::aead_aegis256_keygen, | ||||||||||||||
| 144 | nonce => \&Crypt::Sodium::XS::aead::aead_aegis256_nonce, | ||||||||||||||
| 145 | }, | ||||||||||||||
| 146 | ) : (), | ||||||||||||||
| 147 | Crypt::Sodium::XS::aead->aes256gcm_available ? ( | ||||||||||||||
| 148 | aes256gcm => { | ||||||||||||||
| 149 | ABYTES => \&Crypt::Sodium::XS::aead::aead_aes256gcm_ABYTES, | ||||||||||||||
| 150 | KEYBYTES => \&Crypt::Sodium::XS::aead::aead_aes256gcm_KEYBYTES, | ||||||||||||||
| 151 | MESSAGEBYTES_MAX => \&Crypt::Sodium::XS::aead::aead_aes256gcm_MESSAGEBYTES_MAX, | ||||||||||||||
| 152 | NPUBBYTES => \&Crypt::Sodium::XS::aead::aead_aes256gcm_NPUBBYTES, | ||||||||||||||
| 153 | 0 | ▶ | PRIMITIVE => sub { 'aes256gcm' }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 154 | beforenm => \&Crypt::Sodium::XS::aead::aead_aes256gcm_beforenm, | ||||||||||||||
| 155 | decrypt => \&Crypt::Sodium::XS::aead::aead_aes256gcm_decrypt, | ||||||||||||||
| 156 | decrypt_detached => \&Crypt::Sodium::XS::aead::aead_aes256gcm_decrypt_detached, | ||||||||||||||
| 157 | encrypt => \&Crypt::Sodium::XS::aead::aead_aes256gcm_encrypt, | ||||||||||||||
| 158 | encrypt_detached => \&Crypt::Sodium::XS::aead::aead_aes256gcm_encrypt_detached, | ||||||||||||||
| 159 | keygen => \&Crypt::Sodium::XS::aead::aead_aes256gcm_keygen, | ||||||||||||||
| 160 | nonce => \&Crypt::Sodium::XS::aead::aead_aes256gcm_nonce, | ||||||||||||||
| 161 | }, | ||||||||||||||
| 162 | ) : (), | ||||||||||||||
| 163 | xchacha20poly1305_ietf => { | ||||||||||||||
| 164 | ABYTES => \&Crypt::Sodium::XS::aead::aead_xchacha20poly1305_ietf_ABYTES, | ||||||||||||||
| 165 | KEYBYTES => \&Crypt::Sodium::XS::aead::aead_xchacha20poly1305_ietf_KEYBYTES, | ||||||||||||||
| 166 | MESSAGEBYTES_MAX => \&Crypt::Sodium::XS::aead::aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAX, | ||||||||||||||
| 167 | NPUBBYTES => \&Crypt::Sodium::XS::aead::aead_xchacha20poly1305_ietf_NPUBBYTES, | ||||||||||||||
| 168 | 0 | ▶ | PRIMITIVE => sub { 'xchacha20poly1305_ietf' }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 169 | 0 | ▶ | beforenm => sub { die "beforenm is only supported for the aes256gcm primitive" }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 170 | 1 | ▶ | decrypt => \&Crypt::Sodium::XS::aead::aead_xchacha20poly1305_ietf_decrypt, | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 171 | decrypt_detached => \&Crypt::Sodium::XS::aead::aead_xchacha20poly1305_ietf_decrypt_detached, | ||||||||||||||
| 172 | encrypt => \&Crypt::Sodium::XS::aead::aead_xchacha20poly1305_ietf_encrypt, | ||||||||||||||
| 173 | encrypt_detached => \&Crypt::Sodium::XS::aead::aead_xchacha20poly1305_ietf_encrypt_detached, | ||||||||||||||
| 174 | keygen => \&Crypt::Sodium::XS::aead::aead_xchacha20poly1305_ietf_keygen, | ||||||||||||||
| 175 | nonce => \&Crypt::Sodium::XS::aead::aead_xchacha20poly1305_ietf_nonce, | ||||||||||||||
| 176 | }, | ||||||||||||||
| 177 | ); | ||||||||||||||
| 178 | |||||||||||||||
| 179 | 7 | ▶ | sub Crypt::Sodium::XS::aead::primitives { keys %methods } | ||||||||||||
|
Subroutine
primitives: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 180 | 1 | *primitives = \&Crypt::Sodium::XS::aead::primitives; | |||||||||||||
| 181 | 1 | *aes256gcm_available = \&Crypt::Sodium::XS::aead::aes256gcm_available; | |||||||||||||
| 182 | 1 | *aegis_available = \&Crypt::Sodium::XS::aead::aegis_available; | |||||||||||||
| 183 | |||||||||||||||
| 184 | 20 | ▶ | sub ABYTES { my $self = shift; goto $methods{$self->{primitive}}->{ABYTES}; } | ||||||||||||
|
Subroutine
ABYTES: called CC=1 SCAR=0.0
| |||||||||||||||
| 185 | 18 | ▶ | sub KEYBYTES { my $self = shift; goto $methods{$self->{primitive}}->{KEYBYTES}; } | ||||||||||||
|
Subroutine
KEYBYTES: called CC=1 SCAR=0.0
| |||||||||||||||
| 186 | 6 | ▶ | sub MESSAGEBYTES_MAX { my $self = shift; goto $methods{$self->{primitive}}->{MESSAGEBYTES_MAX}; } | ||||||||||||
|
Subroutine
MESSAGEBYTES_MAX: called CC=1 SCAR=0.0
| |||||||||||||||
| 187 | 18 | ▶ | sub NPUBBYTES { my $self = shift; goto $methods{$self->{primitive}}->{NPUBBYTES}; } | ||||||||||||
|
Subroutine
NPUBBYTES: called CC=1 SCAR=0.0
| |||||||||||||||
| 188 | 0 | ▶ | sub PRIMITIVE { my $self = shift; goto $methods{$self->{primitive}}->{PRIMITIVE}; } | ||||||||||||
|
Subroutine
PRIMITIVE: not called CC=1 SCAR=6.9
| |||||||||||||||
| 189 | 2 | ▶ | sub beforenm { my $self = shift; goto $methods{$self->{primitive}}->{beforenm}; } | ||||||||||||
|
Subroutine
beforenm: called CC=1 SCAR=0.0
| |||||||||||||||
| 190 | 72 | ▶ | sub decrypt { my $self = shift; goto $methods{$self->{primitive}}->{decrypt}; } | ||||||||||||
|
Subroutine
decrypt: called CC=1 SCAR=0.0
| |||||||||||||||
| 191 | 12 | ▶ | sub decrypt_detached { my $self = shift; goto $methods{$self->{primitive}}->{decrypt_detached}; } | ||||||||||||
|
Subroutine
decrypt_detached: called CC=1 SCAR=0.0
| |||||||||||||||
| 192 | 24 | ▶ | sub encrypt { my $self = shift; goto $methods{$self->{primitive}}->{encrypt}; } | ||||||||||||
|
Subroutine
encrypt: called CC=1 SCAR=0.0
| |||||||||||||||
| 193 | 12 | ▶ | sub encrypt_detached { my $self = shift; goto $methods{$self->{primitive}}->{encrypt_detached}; } | ||||||||||||
|
Subroutine
encrypt_detached: called CC=1 SCAR=0.0
| |||||||||||||||
| 194 | 12 | ▶ | sub keygen { my $self = shift; goto $methods{$self->{primitive}}->{keygen}; } | ||||||||||||
|
Subroutine
keygen: called CC=1 SCAR=0.0
| |||||||||||||||
| 195 | 12 | ▶ | sub nonce { my $self = shift; goto $methods{$self->{primitive}}->{nonce}; } | ||||||||||||
|
Subroutine
nonce: called CC=1 SCAR=0.0
| |||||||||||||||
| 196 | |||||||||||||||
| 197 | 1 | 1; | |||||||||||||
| 198 | |||||||||||||||
| 199 | __END__ | ||||||||||||||