1Crypt::Mode::CTR(3) User Contributed Perl Documentation Crypt::Mode::CTR(3)
2
3
4
6 Crypt::Mode::CTR - Block cipher mode CTR [Counter mode]
7
9 use Crypt::Mode::CTR;
10 my $m = Crypt::Mode::CTR->new('AES');
11
12 #(en|de)crypt at once
13 my $ciphertext = $m->encrypt($plaintext, $key, $iv);
14 my $plaintext = $m->decrypt($ciphertext, $key, $iv);
15
16 #encrypt more chunks
17 $m->start_encrypt($key, $iv);
18 my $ciphertext = $m->add('some data');
19 $ciphertext .= $m->add('more data');
20
21 #decrypt more chunks
22 $m->start_decrypt($key, $iv);
23 my $plaintext = $m->add($some_ciphertext);
24 $plaintext .= $m->add($more_ciphertext);
25
27 This module implements CTR cipher mode. NOTE: it works only with
28 ciphers from CryptX (Crypt::Cipher::NNNN).
29
31 new
32 my $m = Crypt::Mode::CTR->new($cipher_name);
33 #or
34 my $m = Crypt::Mode::CTR->new($cipher_name, $ctr_mode, $ctr_width);
35 #or
36 my $m = Crypt::Mode::CTR->new($cipher_name, $ctr_mode, $ctr_width, $cipher_rounds);
37
38 # $ctr_mode .... 0 little-endian counter (DEFAULT)
39 # 1 big-endian counter
40 # 2 little-endian + RFC3686 incrementing
41 # 3 big-endian + RFC3686 incrementing
42 # $ctr_width ... counter width in bytes (DEFAULT = full block width)
43 # $cipher_rounds ... optional num of rounds for given cipher
44
45 encrypt
46 my $ciphertext = $m->encrypt($plaintext, $key, $iv);
47
48 decrypt
49 my $plaintext = $m->decrypt($ciphertext, $key, $iv);
50
51 start_encrypt
52 $m->start_encrypt($key, $iv);
53
54 start_decrypt
55 $m->start_decrypt($key, $iv);
56
57 add
58 # in encrypt mode
59 my $plaintext = $m->add($ciphertext);
60
61 # in decrypt mode
62 my $ciphertext = $m->add($plaintext);
63
65 · CryptX, Crypt::Cipher
66
67 · Crypt::Cipher::AES, Crypt::Cipher::Blowfish, ...
68
69 · <https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Counter_.28CTR.29>
70
71
72
73perl v5.28.0 2017-09-15 Crypt::Mode::CTR(3)