| 1 | package Crypt::Mode::OFB; | ||
| 2 | |||
| 3 | ### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY! | ||
| 4 | |||
| 5 | 25 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 25 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 25 | our $VERSION = '0.091'; | |
| 8 | |||
| 9 | 25 | ▶ | use Crypt::Cipher; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | 53 | ▶ | sub encrypt { |
|
Subroutine
encrypt: called CC=1 SCAR=0.0
Pod
documented
| |||
| 12 | 53 | my ($self, $pt) = (shift, shift); | |
| 13 | 53 | local $SIG{__DIE__} = \&CryptX::_croak; | |
| 14 | 53 | $self->start_encrypt(@_)->add($pt); | |
| 15 | } | ||
| 16 | |||
| 17 | 53 | ▶ | sub decrypt { |
|
Subroutine
decrypt: called CC=1 SCAR=0.0
Pod
documented
| |||
| 18 | 53 | my ($self, $ct) = (shift, shift); | |
| 19 | 53 | local $SIG{__DIE__} = \&CryptX::_croak; | |
| 20 | 53 | $self->start_decrypt(@_)->add($ct); | |
| 21 | } | ||
| 22 | |||
| 23 | 0 | ▶ | sub CLONE_SKIP { 1 } # prevent cloning |
|
Subroutine
CLONE_SKIP: not called CC=1 SCAR=6.9
| |||
| 24 | |||
| 25 | 25 | 1; | |
| 26 | |||
| 27 | =pod | ||
| 28 | |||
| 29 | =head1 NAME | ||
| 30 | |||
| 31 | Crypt::Mode::OFB - Block cipher mode OFB [Output feedback] | ||
| 32 | |||
| 33 | =head1 SYNOPSIS | ||
| 34 | |||
| 35 | use Crypt::Mode::OFB; | ||
| 36 | my $m = Crypt::Mode::OFB->new('AES'); | ||
| 37 | my $key = '1234567890123456'; | ||
| 38 | my $iv = '1234567890123456'; | ||
| 39 | my $plaintext = 'example plaintext'; | ||
| 40 | my $chunk1 = 'example '; | ||
| 41 | my $chunk2 = 'plaintext'; | ||
| 42 | |||
| 43 | # encrypt or decrypt in one call | ||
| 44 | my $single_ciphertext = $m->encrypt($plaintext, $key, $iv); | ||
| 45 | my $single_plaintext = $m->decrypt($single_ciphertext, $key, $iv); | ||
| 46 | |||
| 47 | # encrypt more chunks | ||
| 48 | $m->start_encrypt($key, $iv); | ||
| 49 | my $chunked_ciphertext = ''; | ||
| 50 | $chunked_ciphertext .= $m->add($chunk1); | ||
| 51 | $chunked_ciphertext .= $m->add($chunk2); | ||
| 52 | |||
| 53 | # decrypt more chunks | ||
| 54 | $m->start_decrypt($key, $iv); | ||
| 55 | my $chunked_plaintext = ''; | ||
| 56 | $chunked_plaintext .= $m->add($chunked_ciphertext); | ||
| 57 | |||
| 58 | =head1 DESCRIPTION | ||
| 59 | |||
| 60 | This module implements OFB cipher mode. B<Note:> It works only with ciphers from L<CryptX> (Crypt::Cipher::NNNN). | ||
| 61 | |||
| 62 | =head1 METHODS | ||
| 63 | |||
| 64 | Unless noted otherwise, assume C<$m> is an existing mode object created via | ||
| 65 | C<new>, for example: | ||
| 66 | |||
| 67 | my $m = Crypt::Mode::OFB->new('AES'); | ||
| 68 | |||
| 69 | =head2 new | ||
| 70 | |||
| 71 | my $m = Crypt::Mode::OFB->new($name); | ||
| 72 | #or | ||
| 73 | my $m = Crypt::Mode::OFB->new($name, $cipher_rounds); | ||
| 74 | |||
| 75 | # $name ............ [string] one of 'AES', 'Anubis', 'Blowfish', 'CAST5', 'Camellia', 'DES', 'DES_EDE', | ||
| 76 | # 'KASUMI', 'Khazad', 'MULTI2', 'Noekeon', 'RC2', 'RC5', 'RC6', | ||
| 77 | # 'SAFERP', 'SAFER_K128', 'SAFER_K64', 'SAFER_SK128', 'SAFER_SK64', | ||
| 78 | # 'SEED', 'Skipjack', 'Twofish', 'XTEA', 'IDEA', 'Serpent' | ||
| 79 | # or any <NAME> for which there is a Crypt::Cipher::<NAME> module | ||
| 80 | # $cipher_rounds ... [integer] optional, number of rounds for given cipher | ||
| 81 | |||
| 82 | =head2 encrypt | ||
| 83 | |||
| 84 | Encrypts the plaintext in a single call. Returns the ciphertext as a binary string. | ||
| 85 | The plaintext scalar is converted to bytes using Perl's usual scalar | ||
| 86 | stringification. Defined scalars, including numbers and string-overloaded | ||
| 87 | objects, are accepted. C<undef> is treated as an empty string and may emit | ||
| 88 | Perl's usual "uninitialized value" warning. | ||
| 89 | |||
| 90 | my $ciphertext = $m->encrypt($plaintext, $key, $iv); | ||
| 91 | |||
| 92 | =head2 decrypt | ||
| 93 | |||
| 94 | Decrypts the ciphertext in a single call. Returns the plaintext as a binary string. | ||
| 95 | The ciphertext scalar is converted to bytes using Perl's usual scalar | ||
| 96 | stringification. Defined scalars, including numbers and string-overloaded | ||
| 97 | objects, are accepted. C<undef> is treated as an empty string and may emit | ||
| 98 | Perl's usual "uninitialized value" warning. | ||
| 99 | |||
| 100 | my $plaintext = $m->decrypt($ciphertext, $key, $iv); | ||
| 101 | |||
| 102 | =head2 start_encrypt | ||
| 103 | |||
| 104 | Initializes encryption mode. Returns the object itself. | ||
| 105 | |||
| 106 | $m->start_encrypt($key, $iv); | ||
| 107 | |||
| 108 | =head2 start_decrypt | ||
| 109 | |||
| 110 | Initializes decryption mode. Returns the object itself. | ||
| 111 | |||
| 112 | $m->start_decrypt($key, $iv); | ||
| 113 | |||
| 114 | =head2 add | ||
| 115 | |||
| 116 | Feeds data to the encryption or decryption stream. Returns a binary string. | ||
| 117 | |||
| 118 | Each argument is converted to bytes using Perl's usual scalar stringification. | ||
| 119 | Defined scalars, including numbers and string-overloaded objects, are | ||
| 120 | accepted. C<undef> is treated as an empty string and may emit Perl's usual | ||
| 121 | "uninitialized value" warning. | ||
| 122 | |||
| 123 | # in encrypt mode | ||
| 124 | my $ciphertext = $m->add($plaintext); | ||
| 125 | |||
| 126 | # in decrypt mode | ||
| 127 | my $plaintext = $m->add($ciphertext); | ||
| 128 | |||
| 129 | =head2 finish | ||
| 130 | |||
| 131 | OFB is a streaming mode and does not use padding, so C<finish> returns an empty | ||
| 132 | string. It exists for API consistency with L<Crypt::Mode::CBC> and | ||
| 133 | L<Crypt::Mode::ECB> and may be safely called or omitted. | ||
| 134 | |||
| 135 | $m->start_encrypt($key, $iv); | ||
| 136 | my $ciphertext = ''; | ||
| 137 | $ciphertext .= $m->add($chunk1); | ||
| 138 | $ciphertext .= $m->add($chunk2); | ||
| 139 | $ciphertext .= $m->finish; # returns '' | ||
| 140 | |||
| 141 | =head1 SEE ALSO | ||
| 142 | |||
| 143 | =over | ||
| 144 | |||
| 145 | =item * L<CryptX>, L<Crypt::Cipher> | ||
| 146 | |||
| 147 | =item * L<Crypt::Cipher::AES>, L<Crypt::Cipher::Blowfish>, ... | ||
| 148 | |||
| 149 | =item * L<https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Output_feedback_.28OFB.29> | ||
| 150 | |||
| 151 | =back | ||
| 152 | |||
| 153 | =cut | ||