Initial Commit
This commit is contained in:
136
database/perl/vendor/lib/Crypt/AuthEnc/CCM.pm
vendored
Normal file
136
database/perl/vendor/lib/Crypt/AuthEnc/CCM.pm
vendored
Normal file
@@ -0,0 +1,136 @@
|
||||
package Crypt::AuthEnc::CCM;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.069';
|
||||
|
||||
require Exporter; our @ISA = qw(Exporter); ### use Exporter 5.57 'import';
|
||||
our %EXPORT_TAGS = ( all => [qw( ccm_encrypt_authenticate ccm_decrypt_verify )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
sub CLONE_SKIP { 1 } # prevent cloning
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::AuthEnc::CCM - Authenticated encryption in CCM mode
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### OO interface
|
||||
use Crypt::AuthEnc::CCM;
|
||||
|
||||
# encrypt and authenticate
|
||||
my $ae = Crypt::AuthEnc::CCM->new("AES", $key, $iv, $adata, $tag_len, $pt_len);
|
||||
my $ct = $ae->encrypt_add('data1');
|
||||
$ct .= $ae->encrypt_add('data2');
|
||||
$ct .= $ae->encrypt_add('data3');
|
||||
my $tag = $ae->encrypt_done();
|
||||
|
||||
# decrypt and verify
|
||||
my $ae = Crypt::AuthEnc::CCM->new("AES", $key, $iv, $adata, $tag_len, $pt_len);
|
||||
my $pt = $ae->decrypt_add('ciphertext1');
|
||||
$pt .= $ae->decrypt_add('ciphertext2');
|
||||
$pt .= $ae->decrypt_add('ciphertext3');
|
||||
my $tag = $ae->decrypt_done();
|
||||
die "decrypt failed" unless $tag eq $expected_tag;
|
||||
|
||||
#or
|
||||
my $result = $ae->decrypt_done($expected_tag); # 0 or 1
|
||||
|
||||
### functional interface
|
||||
use Crypt::AuthEnc::CCM qw(ccm_encrypt_authenticate ccm_decrypt_verify);
|
||||
|
||||
($ciphertext, $tag) = ccm_encrypt_authenticate('AES', $key, $nonce, $adata, $tag_len, $plaintext);
|
||||
$plaintext = ccm_decrypt_verify('AES', $key, $nonce, $adata, $ciphertext, $tag);
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
CCM is a encrypt+authenticate mode that is centered around using AES (or any 16-byte cipher) as a primitive.
|
||||
Unlike EAX and OCB mode, it is only meant for packet mode where the length of the input is known in advance.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::AuthEnc::CCM qw(ccm_encrypt_authenticate ccm_decrypt_verify);
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 ccm_encrypt_authenticate
|
||||
|
||||
my ($ciphertext, $tag) = ccm_encrypt_authenticate($cipher, $key, $nonce, $adata, $tag_len, $plaintext);
|
||||
|
||||
# $cipher .. 'AES' or name of any other cipher with 16-byte block len
|
||||
# $key ..... key of proper length (e.g. 128/192/256bits for AES)
|
||||
# $nonce ... unique nonce/salt (no need to keep it secret)
|
||||
# $adata ... additional authenticated data
|
||||
# $tag_len . required length of output tag
|
||||
|
||||
CCM parameters should follow L<http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38c.pdf>
|
||||
|
||||
# tag length: 4, 6, 8, 10, 12, 14, 16 (reasonable minimum is 8)
|
||||
# nonce length: 7, 8, 9, 10, 11, 12, 13 (if you are not sure, use 11)
|
||||
# BEWARE nonce length determines max. enc/dec data size: max_data_size = 2^(8*(15-nonce_len))
|
||||
|
||||
=head2 ccm_decrypt_verify
|
||||
|
||||
my $plaintext = ccm_decrypt_verify($cipher, $key, $nonce, $adata, $ciphertext, $tag);
|
||||
# on error returns undef
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
my $ae = Crypt::AuthEnc::CCM->new($cipher, $key, $nonce, $adata, $tag_len, $pt_len);
|
||||
|
||||
# $cipher .. 'AES' or name of any other cipher with 16-byte block len
|
||||
# $key ..... key of proper length (e.g. 128/192/256bits for AES)
|
||||
# $nonce ... unique nonce/salt (no need to keep it secret)
|
||||
# $adata ... additional authenticated data
|
||||
# $tag_len . required length of output tag
|
||||
# $pt_len .. expected length of plaintext/ciphertext to encrypt/decrypt
|
||||
|
||||
=head2 encrypt_add
|
||||
|
||||
$ciphertext = $ae->encrypt_add($data); # can be called multiple times
|
||||
|
||||
=head2 encrypt_done
|
||||
|
||||
my $tag = $ae->encrypt_done; # returns $tag value
|
||||
|
||||
=head2 decrypt_add
|
||||
|
||||
$plaintext = $ae->decrypt_add($ciphertext); # can be called multiple times
|
||||
|
||||
=head2 decrypt_done
|
||||
|
||||
my $tag = $ae->decrypt_done; # returns $tag value
|
||||
#or
|
||||
my $result = $ae->decrypt_done($tag); # returns 1 (success) or 0 (failure)
|
||||
|
||||
=head2 clone
|
||||
|
||||
my $ae_new = $ae->clone;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::AuthEnc::EAX|Crypt::AuthEnc::EAX>, L<Crypt::AuthEnc::GCM|Crypt::AuthEnc::GCM>, L<Crypt::AuthEnc::OCB|Crypt::AuthEnc::OCB>
|
||||
|
||||
=item * L<https://en.wikipedia.org/wiki/CCM_mode|https://en.wikipedia.org/wiki/CCM_mode>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
147
database/perl/vendor/lib/Crypt/AuthEnc/ChaCha20Poly1305.pm
vendored
Normal file
147
database/perl/vendor/lib/Crypt/AuthEnc/ChaCha20Poly1305.pm
vendored
Normal file
@@ -0,0 +1,147 @@
|
||||
package Crypt::AuthEnc::ChaCha20Poly1305;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.069';
|
||||
|
||||
require Exporter; our @ISA = qw(Exporter); ### use Exporter 5.57 'import';
|
||||
our %EXPORT_TAGS = ( all => [qw( chacha20poly1305_encrypt_authenticate chacha20poly1305_decrypt_verify )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
sub CLONE_SKIP { 1 } # prevent cloning
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::AuthEnc::ChaCha20Poly1305 - Authenticated encryption in ChaCha20-Poly1305 mode
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### OO interface
|
||||
use Crypt::AuthEnc::ChaCha20Poly1305;
|
||||
|
||||
# encrypt and authenticate
|
||||
my $ae = Crypt::AuthEnc::ChaCha20Poly1305->new($key, $iv);
|
||||
$ae->adata_add('additional_authenticated_data1');
|
||||
$ae->adata_add('additional_authenticated_data2');
|
||||
my $ct = $ae->encrypt_add('data1');
|
||||
$ct .= $ae->encrypt_add('data2');
|
||||
$ct .= $ae->encrypt_add('data3');
|
||||
my $tag = $ae->encrypt_done();
|
||||
|
||||
# decrypt and verify
|
||||
my $ae = Crypt::AuthEnc::ChaCha20Poly1305->new($key, $iv);
|
||||
$ae->adata_add('additional_authenticated_data1');
|
||||
$ae->adata_add('additional_authenticated_data2');
|
||||
my $pt = $ae->decrypt_add('ciphertext1');
|
||||
$pt .= $ae->decrypt_add('ciphertext2');
|
||||
$pt .= $ae->decrypt_add('ciphertext3');
|
||||
my $tag = $ae->decrypt_done();
|
||||
die "decrypt failed" unless $tag eq $expected_tag;
|
||||
|
||||
#or
|
||||
my $result = $ae->decrypt_done($expected_tag); # 0 or 1
|
||||
|
||||
### functional interface
|
||||
use Crypt::AuthEnc::ChaCha20Poly1305 qw(chacha20poly1305_encrypt_authenticate chacha20poly1305_decrypt_verify);
|
||||
|
||||
my ($ciphertext, $tag) = chacha20poly1305_encrypt_authenticate($key, $iv, $adata, $plaintext);
|
||||
my $plaintext = chacha20poly1305_decrypt_verify($key, $iv, $adata, $ciphertext, $tag);
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides encryption and authentication based on ChaCha20 + Poly1305 as defined in RFC 7539 - L<https://tools.ietf.org/html/rfc7539>
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::AuthEnc::ChaCha20Poly1305 qw(chacha20poly1305_encrypt_authenticate chacha20poly1305_decrypt_verify);
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 chacha20poly1305_encrypt_authenticate
|
||||
|
||||
my ($ciphertext, $tag) = chacha20poly1305_encrypt_authenticate($key, $iv, $adata, $plaintext);
|
||||
|
||||
# $key ..... key of proper length (128 or 256 bits / 16 or 32 bytes)
|
||||
# $iv ...... initialization vector (64 or 96 bits / 8 or 12 bytes)
|
||||
# $adata ... additional authenticated data (optional)
|
||||
|
||||
=head2 chacha20poly1305_decrypt_verify
|
||||
|
||||
my $plaintext = chacha20poly1305_decrypt_verify($key, $iv, $adata, $ciphertext, $tag);
|
||||
# on error returns undef
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
my $ae = Crypt::AuthEnc::ChaCha20Poly1305->new($key, $iv);
|
||||
|
||||
# $key ..... encryption key of proper length (128 or 256 bits / 16 or 32 bytes)
|
||||
# $iv ...... initialization vector (64 or 96 bits / 8 or 12 bytes)
|
||||
|
||||
=head2 adata_add
|
||||
|
||||
Add B<additional authenticated data>.
|
||||
Can be called before the first C<encrypt_add> or C<decrypt_add>;
|
||||
|
||||
$ae->adata_add($aad_data); # can be called multiple times
|
||||
|
||||
=head2 encrypt_add
|
||||
|
||||
$ciphertext = $ae->encrypt_add($data); # can be called multiple times
|
||||
|
||||
=head2 encrypt_done
|
||||
|
||||
$tag = $ae->encrypt_done(); # returns $tag value
|
||||
|
||||
=head2 decrypt_add
|
||||
|
||||
$plaintext = $ae->decrypt_add($ciphertext); # can be called multiple times
|
||||
|
||||
=head2 decrypt_done
|
||||
|
||||
my $tag = $ae->decrypt_done; # returns $tag value
|
||||
#or
|
||||
my $result = $ae->decrypt_done($tag); # returns 1 (success) or 0 (failure)
|
||||
|
||||
=head2 set_iv
|
||||
|
||||
my $ae = Crypt::AuthEnc::ChaCha20Poly1305->new($key)->set_iv($iv);
|
||||
# $iv ...... initialization vector (64 or 96 bits / 8 or 12 bytes)
|
||||
|
||||
=head2 set_iv_rfc7905
|
||||
|
||||
See L<https://tools.ietf.org/html/rfc7905>
|
||||
|
||||
my $ae = Crypt::AuthEnc::ChaCha20Poly1305->new($key)->set_iv_rfc7905($iv, $seqnum);
|
||||
# $iv ...... initialization vector (96 bits / 12 bytes)
|
||||
# $seqnum .. 64bit integer (sequence number)
|
||||
|
||||
=head2 clone
|
||||
|
||||
my $ae_new = $ae->clone;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::AuthEnc::GCM|Crypt::AuthEnc::GCM>, L<Crypt::AuthEnc::CCM|Crypt::AuthEnc::CCM>, L<Crypt::AuthEnc::EAX|Crypt::AuthEnc::EAX>, L<Crypt::AuthEnc::OCB|Crypt::AuthEnc::OCB>
|
||||
|
||||
=item * L<https://tools.ietf.org/html/rfc7539>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
142
database/perl/vendor/lib/Crypt/AuthEnc/EAX.pm
vendored
Normal file
142
database/perl/vendor/lib/Crypt/AuthEnc/EAX.pm
vendored
Normal file
@@ -0,0 +1,142 @@
|
||||
package Crypt::AuthEnc::EAX;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.069';
|
||||
|
||||
require Exporter; our @ISA = qw(Exporter); ### use Exporter 5.57 'import';
|
||||
our %EXPORT_TAGS = ( all => [qw( eax_encrypt_authenticate eax_decrypt_verify )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
# obsolete, only for backwards compatibility
|
||||
sub header_add { goto &adata_add }
|
||||
sub aad_add { goto &adata_add }
|
||||
|
||||
sub CLONE_SKIP { 1 } # prevent cloning
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::AuthEnc::EAX - Authenticated encryption in EAX mode
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### OO interface
|
||||
use Crypt::AuthEnc::EAX;
|
||||
|
||||
# encrypt and authenticate
|
||||
my $ae = Crypt::AuthEnc::EAX->new("AES", $key, $iv);
|
||||
$ae->adata_add('additional_authenticated_data1');
|
||||
$ae->adata_add('additional_authenticated_data2');
|
||||
my $ct = $ae->encrypt_add('data1');
|
||||
$ct .= $ae->encrypt_add('data2');
|
||||
$ct .= $ae->encrypt_add('data3');
|
||||
my $tag = $ae->encrypt_done();
|
||||
|
||||
# decrypt and verify
|
||||
my $ae = Crypt::AuthEnc::EAX->new("AES", $key, $iv);
|
||||
$ae->adata_add('additional_authenticated_data1');
|
||||
$ae->adata_add('additional_authenticated_data2');
|
||||
my $pt = $ae->decrypt_add('ciphertext1');
|
||||
$pt .= $ae->decrypt_add('ciphertext2');
|
||||
$pt .= $ae->decrypt_add('ciphertext3');
|
||||
my $tag = $ae->decrypt_done();
|
||||
die "decrypt failed" unless $tag eq $expected_tag;
|
||||
|
||||
#or
|
||||
my $result = $ae->decrypt_done($expected_tag); # 0 or 1
|
||||
|
||||
### functional interface
|
||||
use Crypt::AuthEnc::EAX qw(eax_encrypt_authenticate eax_decrypt_verify);
|
||||
|
||||
my ($ciphertext, $tag) = eax_encrypt_authenticate('AES', $key, $iv, $adata, $plaintext);
|
||||
my $plaintext = eax_decrypt_verify('AES', $key, $iv, $adata, $ciphertext, $tag);
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
EAX is a mode that requires a cipher, CTR and OMAC support and provides encryption and authentication.
|
||||
It is initialized with a random IV that can be shared publicly, additional authenticated data which can
|
||||
be fixed and public, and a random secret symmetric key.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::AuthEnc::EAX qw(eax_encrypt_authenticate eax_decrypt_verify);
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 eax_encrypt_authenticate
|
||||
|
||||
my ($ciphertext, $tag) = eax_encrypt_authenticate($cipher, $key, $iv, $adata, $plaintext);
|
||||
|
||||
# $cipher .. 'AES' or name of any other cipher with 16-byte block len
|
||||
# $key ..... AES key of proper length (128/192/256bits)
|
||||
# $iv ...... unique initialization vector (no need to keep it secret)
|
||||
# $adata ... additional authenticated data
|
||||
|
||||
=head2 eax_decrypt_verify
|
||||
|
||||
my $plaintext = eax_decrypt_verify($cipher, $key, $iv, $adata, $ciphertext, $tag);
|
||||
# on error returns undef
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
my $ae = Crypt::AuthEnc::EAX->new($cipher, $key, $iv);
|
||||
#or
|
||||
my $ae = Crypt::AuthEnc::EAX->new($cipher, $key, $iv, $adata);
|
||||
|
||||
# $cipher .. 'AES' or name of any other cipher with 16-byte block len
|
||||
# $key ..... AES key of proper length (128/192/256bits)
|
||||
# $iv ...... unique initialization vector (no need to keep it secret)
|
||||
# $adata ... additional authenticated data (optional)
|
||||
|
||||
=head2 adata_add
|
||||
|
||||
$ae->adata_add($adata); # can be called multiple times
|
||||
|
||||
=head2 encrypt_add
|
||||
|
||||
$ciphertext = $ae->encrypt_add($data); # can be called multiple times
|
||||
|
||||
=head2 encrypt_done
|
||||
|
||||
$tag = $ae->encrypt_done(); # returns $tag value
|
||||
|
||||
=head2 decrypt_add
|
||||
|
||||
$plaintext = $ae->decrypt_add($ciphertext); # can be called multiple times
|
||||
|
||||
=head2 decrypt_done
|
||||
|
||||
my $tag = $ae->decrypt_done; # returns $tag value
|
||||
#or
|
||||
my $result = $ae->decrypt_done($tag); # returns 1 (success) or 0 (failure)
|
||||
|
||||
=head2 clone
|
||||
|
||||
my $ae_new = $ae->clone;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::AuthEnc::CCM|Crypt::AuthEnc::CCM>, L<Crypt::AuthEnc::GCM|Crypt::AuthEnc::GCM>, L<Crypt::AuthEnc::OCB|Crypt::AuthEnc::OCB>
|
||||
|
||||
=item * L<https://en.wikipedia.org/wiki/EAX_mode|https://en.wikipedia.org/wiki/EAX_mode>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
148
database/perl/vendor/lib/Crypt/AuthEnc/GCM.pm
vendored
Normal file
148
database/perl/vendor/lib/Crypt/AuthEnc/GCM.pm
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
package Crypt::AuthEnc::GCM;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.069';
|
||||
|
||||
require Exporter; our @ISA = qw(Exporter); ### use Exporter 5.57 'import';
|
||||
our %EXPORT_TAGS = ( all => [qw( gcm_encrypt_authenticate gcm_decrypt_verify )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
sub CLONE_SKIP { 1 } # prevent cloning
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::AuthEnc::GCM - Authenticated encryption in GCM mode
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### OO interface
|
||||
use Crypt::AuthEnc::GCM;
|
||||
|
||||
# encrypt and authenticate
|
||||
my $ae = Crypt::AuthEnc::GCM->new("AES", $key, $iv);
|
||||
$ae->adata_add('additional_authenticated_data1');
|
||||
$ae->adata_add('additional_authenticated_data2');
|
||||
my $ct = $ae->encrypt_add('data1');
|
||||
$ct .= $ae->encrypt_add('data2');
|
||||
$ct .= $ae->encrypt_add('data3');
|
||||
my $tag = $ae->encrypt_done();
|
||||
|
||||
# decrypt and verify
|
||||
my $ae = Crypt::AuthEnc::GCM->new("AES", $key, $iv);
|
||||
$ae->adata_add('additional_authenticated_data1');
|
||||
$ae->adata_add('additional_authenticated_data2');
|
||||
my $pt = $ae->decrypt_add('ciphertext1');
|
||||
$pt .= $ae->decrypt_add('ciphertext2');
|
||||
$pt .= $ae->decrypt_add('ciphertext3');
|
||||
my $tag = $ae->decrypt_done();
|
||||
die "decrypt failed" unless $tag eq $expected_tag;
|
||||
|
||||
#or
|
||||
my $result = $ae->decrypt_done($expected_tag); # 0 or 1
|
||||
|
||||
### functional interface
|
||||
use Crypt::AuthEnc::GCM qw(gcm_encrypt_authenticate gcm_decrypt_verify);
|
||||
|
||||
my ($ciphertext, $tag) = gcm_encrypt_authenticate('AES', $key, $iv, $adata, $plaintext);
|
||||
my $plaintext = gcm_decrypt_verify('AES', $key, $iv, $adata, $ciphertext, $tag);
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Galois/Counter Mode (GCM) - provides encryption and authentication.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::AuthEnc::GCM qw(gcm_encrypt_authenticate gcm_decrypt_verify);
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 gcm_encrypt_authenticate
|
||||
|
||||
my ($ciphertext, $tag) = gcm_encrypt_authenticate($cipher, $key, $iv, $adata, $plaintext);
|
||||
|
||||
# $cipher .. 'AES' or name of any other cipher with 16-byte block len
|
||||
# $key ..... AES key of proper length (128/192/256bits)
|
||||
# $iv ...... initialization vector
|
||||
# $adata ... additional authenticated data
|
||||
|
||||
=head2 gcm_decrypt_verify
|
||||
|
||||
my $plaintext = gcm_decrypt_verify($cipher, $key, $iv, $adata, $ciphertext, $tag);
|
||||
# on error returns undef
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
my $ae = Crypt::AuthEnc::GCM->new($cipher, $key);
|
||||
#or
|
||||
my $ae = Crypt::AuthEnc::GCM->new($cipher, $key, $iv);
|
||||
|
||||
# $cipher .. 'AES' or name of any other cipher
|
||||
# $key ..... encryption key of proper length
|
||||
# $iv ...... initialization vector (optional, you can set it later via iv_add method)
|
||||
|
||||
=head2 iv_add
|
||||
|
||||
Set initialization vector (IV).
|
||||
|
||||
$ae->iv_add($iv_data); #can be called multiple times
|
||||
|
||||
=head2 adata_add
|
||||
|
||||
Add B<additional authenticated data>.
|
||||
Can be called B<after> all C<iv_add> calls but before the first C<encrypt_add> or C<decrypt_add>.
|
||||
|
||||
$ae->adata_add($aad_data); # can be called multiple times
|
||||
|
||||
=head2 encrypt_add
|
||||
|
||||
$ciphertext = $ae->encrypt_add($data); # can be called multiple times
|
||||
|
||||
=head2 encrypt_done
|
||||
|
||||
$tag = $ae->encrypt_done(); # returns $tag value
|
||||
|
||||
=head2 decrypt_add
|
||||
|
||||
$plaintext = $ae->decrypt_add($ciphertext); # can be called multiple times
|
||||
|
||||
=head2 decrypt_done
|
||||
|
||||
my $tag = $ae->decrypt_done; # returns $tag value
|
||||
#or
|
||||
my $result = $ae->decrypt_done($tag); # returns 1 (success) or 0 (failure)
|
||||
|
||||
=head2 reset
|
||||
|
||||
$ae->reset;
|
||||
|
||||
=head2 clone
|
||||
|
||||
my $ae_new = $ae->clone;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::AuthEnc::CCM|Crypt::AuthEnc::CCM>, L<Crypt::AuthEnc::EAX|Crypt::AuthEnc::EAX>, L<Crypt::AuthEnc::OCB|Crypt::AuthEnc::OCB>
|
||||
|
||||
=item * L<https://en.wikipedia.org/wiki/Galois/Counter_Mode>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
155
database/perl/vendor/lib/Crypt/AuthEnc/OCB.pm
vendored
Normal file
155
database/perl/vendor/lib/Crypt/AuthEnc/OCB.pm
vendored
Normal file
@@ -0,0 +1,155 @@
|
||||
package Crypt::AuthEnc::OCB;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.069';
|
||||
|
||||
require Exporter; our @ISA = qw(Exporter); ### use Exporter 5.57 'import';
|
||||
our %EXPORT_TAGS = ( all => [qw( ocb_encrypt_authenticate ocb_decrypt_verify )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
# obsolete, only for backwards compatibility
|
||||
sub aad_add { goto &adata_add }
|
||||
sub blocksize { return 16 }
|
||||
|
||||
sub CLONE_SKIP { 1 } # prevent cloning
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::AuthEnc::OCB - Authenticated encryption in OCBv3 mode
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### OO interface
|
||||
use Crypt::AuthEnc::OCB;
|
||||
|
||||
# encrypt and authenticate
|
||||
my $ae = Crypt::AuthEnc::OCB->new("AES", $key, $nonce, $tag_len);
|
||||
$ae->adata_add('additional_authenticated_data1');
|
||||
$ae->adata_add('additional_authenticated_data2');
|
||||
my $ct = $ae->encrypt_add('data1');
|
||||
$ct .= $ae->encrypt_add('data2');
|
||||
$ct .= $ae->encrypt_add('data3');
|
||||
$ct .= $ae->encrypt_last('rest of data');
|
||||
my $tag = $ae->encrypt_done();
|
||||
|
||||
# decrypt and verify
|
||||
my $ae = Crypt::AuthEnc::OCB->new("AES", $key, $nonce, $tag_len);
|
||||
$ae->adata_add('additional_authenticated_data1');
|
||||
$ae->adata_add('additional_authenticated_data2');
|
||||
my $pt = $ae->decrypt_add('ciphertext1');
|
||||
$pt .= $ae->decrypt_add('ciphertext2');
|
||||
$pt .= $ae->decrypt_add('ciphertext3');
|
||||
$pt .= $ae->decrypt_last('rest of data');
|
||||
my $tag = $ae->decrypt_done();
|
||||
die "decrypt failed" unless $tag eq $expected_tag;
|
||||
|
||||
#or
|
||||
my $result = $ae->decrypt_done($expected_tag); # 0 or 1
|
||||
|
||||
### functional interface
|
||||
use Crypt::AuthEnc::OCB qw(ocb_encrypt_authenticate ocb_decrypt_verify);
|
||||
|
||||
my ($ciphertext, $tag) = ocb_encrypt_authenticate('AES', $key, $nonce, $adata, $tag_len, $plaintext);
|
||||
my $plaintext = ocb_decrypt_verify('AES', $key, $nonce, $adata, $ciphertext, $tag);
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements OCB v3 according to L<https://tools.ietf.org/html/rfc7253>
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::AuthEnc::OCB qw(ocb_encrypt_authenticate ocb_decrypt_verify);
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 ocb_encrypt_authenticate
|
||||
|
||||
my ($ciphertext, $tag) = ocb_encrypt_authenticate($cipher, $key, $nonce, $adata, $tag_len, $plaintext);
|
||||
|
||||
# $cipher .. 'AES' or name of any other cipher with 16-byte block len
|
||||
# $key ..... AES key of proper length (128/192/256bits)
|
||||
# $nonce ... unique nonce/salt (no need to keep it secret)
|
||||
# $adata ... additional authenticated data
|
||||
# $tag_len . required length of output tag
|
||||
|
||||
=head2 ocb_decrypt_verify
|
||||
|
||||
my $plaintext = ocb_decrypt_verify($cipher, $key, $nonce, $adata, $ciphertext, $tag);
|
||||
# on error returns undef
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
my $ae = Crypt::AuthEnc::OCB->new($cipher, $key, $nonce, $tag_len);
|
||||
|
||||
# $cipher .. 'AES' or name of any other cipher with 16-byte block len
|
||||
# $key ..... AES key of proper length (128/192/256bits)
|
||||
# $nonce ... unique nonce/salt (no need to keep it secret)
|
||||
# $tag_len . required length of output tag
|
||||
|
||||
=head2 adata_add
|
||||
|
||||
$ae->adata_add($adata); #can be called multiple times
|
||||
|
||||
=head2 encrypt_add
|
||||
|
||||
$ciphertext = $ae->encrypt_add($data); # can be called multiple times
|
||||
|
||||
#BEWARE: size of $data has to be multiple of blocklen (16 for AES)
|
||||
|
||||
=head2 encrypt_last
|
||||
|
||||
$ciphertext = $ae->encrypt_last($data);
|
||||
|
||||
=head2 encrypt_done
|
||||
|
||||
$tag = $ae->encrypt_done(); # returns $tag value
|
||||
|
||||
=head2 decrypt_add
|
||||
|
||||
$plaintext = $ae->decrypt_add($ciphertext); # can be called multiple times
|
||||
|
||||
#BEWARE: size of $ciphertext has to be multiple of blocklen (16 for AES)
|
||||
|
||||
=head2 decrypt_last
|
||||
|
||||
$plaintext = $ae->decrypt_last($data);
|
||||
|
||||
=head2 decrypt_done
|
||||
|
||||
my $tag = $ae->decrypt_done; # returns $tag value
|
||||
#or
|
||||
my $result = $ae->decrypt_done($tag); # returns 1 (success) or 0 (failure)
|
||||
|
||||
=head2 clone
|
||||
|
||||
my $ae_new = $ae->clone;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::AuthEnc::CCM|Crypt::AuthEnc::CCM>, L<Crypt::AuthEnc::GCM|Crypt::AuthEnc::GCM>, L<Crypt::AuthEnc::EAX|Crypt::AuthEnc::EAX>
|
||||
|
||||
=item * L<https://en.wikipedia.org/wiki/OCB_mode>
|
||||
|
||||
=item * L<https://tools.ietf.org/html/rfc7253>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
Reference in New Issue
Block a user