line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::Mode::CTR; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY! |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
57768
|
use strict; |
|
3
|
|
|
|
|
15
|
|
|
3
|
|
|
|
|
82
|
|
6
|
3
|
|
|
3
|
|
11
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
98
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.080'; |
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
321
|
use Crypt::Cipher; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
374
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub encrypt { |
12
|
13
|
|
|
13
|
1
|
16384
|
my ($self, $pt) = (shift, shift); |
13
|
13
|
|
|
|
|
54
|
local $SIG{__DIE__} = \&CryptX::_croak; |
14
|
13
|
|
|
|
|
151
|
$self->start_encrypt(@_)->add($pt); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub decrypt { |
18
|
13
|
|
|
13
|
1
|
2150
|
my ($self, $ct) = (shift, shift); |
19
|
13
|
|
|
|
|
43
|
local $SIG{__DIE__} = \&CryptX::_croak; |
20
|
13
|
|
|
|
|
85
|
$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::CTR - Block cipher mode CTR [Counter mode] |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 SYNOPSIS |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
use Crypt::Mode::CTR; |
36
|
|
|
|
|
|
|
my $m = Crypt::Mode::CTR->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
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
#decrypt more chunks |
48
|
|
|
|
|
|
|
$m->start_decrypt($key, $iv); |
49
|
|
|
|
|
|
|
my $plaintext = $m->add($some_ciphertext); |
50
|
|
|
|
|
|
|
$plaintext .= $m->add($more_ciphertext); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 DESCRIPTION |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
This module implements CTR cipher mode. B it works only with ciphers from L (Crypt::Cipher::NNNN). |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 METHODS |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 new |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $m = Crypt::Mode::CTR->new($cipher_name); |
61
|
|
|
|
|
|
|
#or |
62
|
|
|
|
|
|
|
my $m = Crypt::Mode::CTR->new($cipher_name, $ctr_mode, $ctr_width); |
63
|
|
|
|
|
|
|
#or |
64
|
|
|
|
|
|
|
my $m = Crypt::Mode::CTR->new($cipher_name, $ctr_mode, $ctr_width, $cipher_rounds); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# $cipher_name .. one of 'AES', 'Anubis', 'Blowfish', 'CAST5', 'Camellia', 'DES', 'DES_EDE', |
67
|
|
|
|
|
|
|
# 'KASUMI', 'Khazad', 'MULTI2', 'Noekeon', 'RC2', 'RC5', 'RC6', |
68
|
|
|
|
|
|
|
# 'SAFERP', 'SAFER_K128', 'SAFER_K64', 'SAFER_SK128', 'SAFER_SK64', |
69
|
|
|
|
|
|
|
# 'SEED', 'Skipjack', 'Twofish', 'XTEA', 'IDEA', 'Serpent' |
70
|
|
|
|
|
|
|
# simply any for which there exists Crypt::Cipher:: |
71
|
|
|
|
|
|
|
# $ctr_mode ..... 0 little-endian counter (DEFAULT) |
72
|
|
|
|
|
|
|
# 1 big-endian counter |
73
|
|
|
|
|
|
|
# 2 little-endian + RFC3686 incrementing |
74
|
|
|
|
|
|
|
# 3 big-endian + RFC3686 incrementing |
75
|
|
|
|
|
|
|
# $ctr_width .... counter width in bytes (DEFAULT = full block width) |
76
|
|
|
|
|
|
|
# $cipher_rounds ... optional num of rounds for given cipher |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 encrypt |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
my $ciphertext = $m->encrypt($plaintext, $key, $iv); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 decrypt |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my $plaintext = $m->decrypt($ciphertext, $key, $iv); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 start_encrypt |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
$m->start_encrypt($key, $iv); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 start_decrypt |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
$m->start_decrypt($key, $iv); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 add |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# in encrypt mode |
97
|
|
|
|
|
|
|
my $plaintext = $m->add($ciphertext); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# in decrypt mode |
100
|
|
|
|
|
|
|
my $ciphertext = $m->add($plaintext); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 SEE ALSO |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=over |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item * L, L |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item * L, L, ... |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item * L |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=back |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |