CryptX
view release on metacpan or search on metacpan
lib/Crypt/Mode/CTR.pm view on Meta::CPAN
# 'KASUMI', 'Khazad', 'MULTI2', 'Noekeon', 'RC2', 'RC5', 'RC6',
# 'SAFERP', 'SAFER_K128', 'SAFER_K64', 'SAFER_SK128', 'SAFER_SK64',
# 'SEED', 'Skipjack', 'Twofish', 'XTEA', 'IDEA', 'Serpent'
# or any <NAME> for which there is a Crypt::Cipher::<NAME> module
# $ctr_mode ..... [integer] CTR_COUNTER_LITTLE_ENDIAN (0) - little-endian counter (DEFAULT)
# CTR_COUNTER_BIG_ENDIAN (1) - big-endian counter
# CTR_COUNTER_LITTLE_ENDIAN | 2 (2) - little-endian + RFC 3686 initial-counter-incrementing
# CTR_COUNTER_BIG_ENDIAN | 2 (3) - big-endian + RFC 3686 initial-counter-incrementing
# $ctr_width .... [integer] counter width in bytes (DEFAULT = full block width, e.g. 16 for AES)
# $cipher_rounds ... [integer] optional, number of rounds for given cipher
=head2 encrypt
Encrypts the plaintext in a single call. Returns the ciphertext as a binary string.
The plaintext scalar is converted to bytes using Perl's usual scalar
stringification. Defined scalars, including numbers and string-overloaded
objects, are accepted. C<undef> is treated as an empty string and may emit
Perl's usual "uninitialized value" warning.
my $ciphertext = $m->encrypt($plaintext, $key, $iv);
=head2 decrypt
Decrypts the ciphertext in a single call. Returns the plaintext as a binary string.
The ciphertext scalar is converted to bytes using Perl's usual scalar
stringification. Defined scalars, including numbers and string-overloaded
objects, are accepted. C<undef> is treated as an empty string and may emit
Perl's usual "uninitialized value" warning.
my $plaintext = $m->decrypt($ciphertext, $key, $iv);
=head2 start_encrypt
Initializes encryption mode. Returns the object itself.
$m->start_encrypt($key, $iv);
=head2 start_decrypt
Initializes decryption mode. Returns the object itself.
$m->start_decrypt($key, $iv);
=head2 add
Feeds data to the encryption or decryption stream. Returns a binary string.
Each argument is converted to bytes using Perl's usual scalar stringification.
Defined scalars, including numbers and string-overloaded objects, are
accepted. C<undef> is treated as an empty string and may emit Perl's usual
"uninitialized value" warning.
# in encrypt mode
my $ciphertext = $m->add($plaintext);
# in decrypt mode
my $plaintext = $m->add($ciphertext);
=head2 finish
CTR is a streaming mode and does not use padding, so C<finish> returns an empty
string. It exists for API consistency with L<Crypt::Mode::CBC> and
L<Crypt::Mode::ECB> and may be safely called or omitted.
$m->start_encrypt($key, $iv);
my $ciphertext = '';
$ciphertext .= $m->add($chunk1);
$ciphertext .= $m->add($chunk2);
$ciphertext .= $m->finish; # returns ''
=head1 SEE ALSO
=over
=item * L<CryptX>, L<Crypt::Cipher>
=item * L<Crypt::Cipher::AES>, L<Crypt::Cipher::Blowfish>, ...
=item * L<https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Counter_.28CTR.29>
=back
=cut
( run in 0.738 second using v1.01-cache-2.11-cpan-140bd7fdf52 )