File Coverage

blib/lib/Crypt/Mode/CFB.pm
Criterion Covered Total %
statement 15 16 93.7
branch n/a
condition n/a
subroutine 5 6 83.3
pod 2 2 100.0
total 22 24 91.6


line stmt bran cond sub pod time code
1             package Crypt::Mode::CFB;
2              
3             ### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
4              
5 24     24   153698 use strict;
  24         44  
  24         904  
6 24     24   122 use warnings;
  24         60  
  24         1785  
7             our $VERSION = '0.089';
8              
9 24     24   792 use Crypt::Cipher;
  24         55  
  24         5462  
10              
11             sub encrypt {
12 53     53 1 338701 my ($self, $pt) = (shift, shift);
13 53         258 local $SIG{__DIE__} = \&CryptX::_croak;
14 53         644 $self->start_encrypt(@_)->add($pt);
15             }
16              
17             sub decrypt {
18 53     53 1 1559 my ($self, $ct) = (shift, shift);
19 53         144 local $SIG{__DIE__} = \&CryptX::_croak;
20 53         335 $self->start_decrypt(@_)->add($ct);
21             }
22              
23 0     0     sub CLONE_SKIP { 1 } # prevent cloning
24              
25             1;
26              
27             =pod
28              
29             =head1 NAME
30              
31             Crypt::Mode::CFB - Block cipher mode CFB [Cipher feedback]
32              
33             =head1 SYNOPSIS
34              
35             use Crypt::Mode::CFB;
36             my $m = Crypt::Mode::CFB->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 CFB cipher mode. B It works only with ciphers from L (Crypt::Cipher::NNNN).
61              
62             =head1 METHODS
63              
64             Unless noted otherwise, assume C<$m> is an existing mode object created via
65             C, for example:
66              
67             my $m = Crypt::Mode::CFB->new('AES');
68              
69             =head2 new
70              
71             my $m = Crypt::Mode::CFB->new($name);
72             #or
73             my $m = Crypt::Mode::CFB->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 for which there is a Crypt::Cipher:: 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 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 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 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             CFB is a streaming mode and does not use padding, so C returns an empty
132             string. It exists for API consistency with L and
133             L 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, L
146              
147             =item * L, L, ...
148              
149             =item * L
150              
151             =back
152              
153             =cut