line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::Mode::CBC; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY! |
4
|
|
|
|
|
|
|
|
5
|
17
|
|
|
17
|
|
139543
|
use strict; |
|
17
|
|
|
|
|
50
|
|
|
17
|
|
|
|
|
490
|
|
6
|
17
|
|
|
17
|
|
80
|
use warnings; |
|
17
|
|
|
|
|
48
|
|
|
17
|
|
|
|
|
712
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.079_007'; |
8
|
|
|
|
|
|
|
|
9
|
17
|
|
|
17
|
|
6575
|
use Crypt::Cipher; |
|
17
|
|
|
|
|
39
|
|
|
17
|
|
|
|
|
2659
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub encrypt { |
12
|
54
|
|
|
54
|
1
|
73788
|
my ($self, $pt) = (shift, shift); |
13
|
54
|
|
|
|
|
260
|
local $SIG{__DIE__} = \&CryptX::_croak; |
14
|
54
|
|
|
|
|
779
|
$self->start_encrypt(@_)->add($pt) . $self->finish; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub decrypt { |
18
|
87
|
|
|
87
|
1
|
714
|
my ($self, $ct) = (shift, shift); |
19
|
87
|
|
|
|
|
338
|
local $SIG{__DIE__} = \&CryptX::_croak; |
20
|
87
|
|
|
|
|
1930
|
$self->start_decrypt(@_)->add($ct) . $self->finish; |
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::CBC - Block cipher mode CBC [Cipher-block chaining] |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 SYNOPSIS |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
use Crypt::Mode::CBC; |
36
|
|
|
|
|
|
|
my $m = Crypt::Mode::CBC->new('AES'); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
#(en|de)crypt at once |
39
|
|
|
|
|
|
|
my $ciphertext = $m->encrypt($plaintext, $key, $iv); |
40
|
|
|
|
|
|
|
my $plaintext = $m->decrypt($ciphertext, $key, $iv); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
#encrypt more chunks |
43
|
|
|
|
|
|
|
$m->start_encrypt($key, $iv); |
44
|
|
|
|
|
|
|
my $ciphertext = $m->add('some data'); |
45
|
|
|
|
|
|
|
$ciphertext .= $m->add('more data'); |
46
|
|
|
|
|
|
|
$ciphertext .= $m->finish; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
#decrypt more chunks |
49
|
|
|
|
|
|
|
$m->start_decrypt($key, $iv); |
50
|
|
|
|
|
|
|
my $plaintext = $m->add($some_ciphertext); |
51
|
|
|
|
|
|
|
$plaintext .= $m->add($more_ciphertext); |
52
|
|
|
|
|
|
|
$plaintext .= $m->finish; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 DESCRIPTION |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
This module implements CBC cipher mode. B it works only with ciphers from L (Crypt::Cipher::NNNN). |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 METHODS |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 new |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $m = Crypt::Mode::CBC->new($name); |
63
|
|
|
|
|
|
|
#or |
64
|
|
|
|
|
|
|
my $m = Crypt::Mode::CBC->new($name, $padding); |
65
|
|
|
|
|
|
|
#or |
66
|
|
|
|
|
|
|
my $m = Crypt::Mode::CBC->new($name, $padding, $cipher_rounds); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# $name ....... one of 'AES', 'Anubis', 'Blowfish', 'CAST5', 'Camellia', 'DES', 'DES_EDE', |
69
|
|
|
|
|
|
|
# 'KASUMI', 'Khazad', 'MULTI2', 'Noekeon', 'RC2', 'RC5', 'RC6', |
70
|
|
|
|
|
|
|
# 'SAFERP', 'SAFER_K128', 'SAFER_K64', 'SAFER_SK128', 'SAFER_SK64', |
71
|
|
|
|
|
|
|
# 'SEED', 'Skipjack', 'Twofish', 'XTEA', 'IDEA', 'Serpent' |
72
|
|
|
|
|
|
|
# simply any for which there exists Crypt::Cipher:: |
73
|
|
|
|
|
|
|
# $padding .... 0 no padding (plaintext size has to be multiple of block length) |
74
|
|
|
|
|
|
|
# 1 PKCS5 padding, Crypt::CBC's "standard" - DEFAULT |
75
|
|
|
|
|
|
|
# 2 Crypt::CBC's "oneandzeroes" |
76
|
|
|
|
|
|
|
# 3 ANSI X.923 padding |
77
|
|
|
|
|
|
|
# 4 zero padding |
78
|
|
|
|
|
|
|
# 5 zero padding (+a block of zeros if the output length is divisible by the blocksize) |
79
|
|
|
|
|
|
|
# $cipher_rounds ... optional num of rounds for given cipher |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 encrypt |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my $ciphertext = $m->encrypt($plaintext, $key, $iv); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 decrypt |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my $plaintext = $m->decrypt($ciphertext, $key, $iv); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 start_encrypt |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$m->start_encrypt($key, $iv); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 start_decrypt |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
$m->start_decrypt($key, $iv); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 add |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# in encrypt mode |
100
|
|
|
|
|
|
|
my $plaintext = $m->add($ciphertext); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# in decrypt mode |
103
|
|
|
|
|
|
|
my $ciphertext = $m->add($plaintext); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 finish |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
#encrypt more chunks |
108
|
|
|
|
|
|
|
$m->start_encrypt($key, $iv); |
109
|
|
|
|
|
|
|
my $ciphertext = ''; |
110
|
|
|
|
|
|
|
$ciphertext .= $m->add('some data'); |
111
|
|
|
|
|
|
|
$ciphertext .= $m->add('more data'); |
112
|
|
|
|
|
|
|
$ciphertext .= $m->finish; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
#decrypt more chunks |
115
|
|
|
|
|
|
|
$m->start_decrypt($key, $iv); |
116
|
|
|
|
|
|
|
my $plaintext = ''; |
117
|
|
|
|
|
|
|
$plaintext .= $m->add($some_ciphertext); |
118
|
|
|
|
|
|
|
$plaintext .= $m->add($more_ciphertext); |
119
|
|
|
|
|
|
|
$plaintext .= $m->finish; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 SEE ALSO |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=over |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item * L, L |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item * L, L, ... |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item * L |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=back |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |