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 # $cipher_name .. one of 'AES', 'Anubis', 'Blowfish', 'CAST5', 'Camellia', 'DES', 'DES_EDE',
39 # 'KASUMI', 'Khazad', 'MULTI2', 'Noekeon', 'RC2', 'RC5', 'RC6',
40 # 'SAFERP', 'SAFER_K128', 'SAFER_K64', 'SAFER_SK128', 'SAFER_SK64',
41 # 'SEED', 'Skipjack', 'Twofish', 'XTEA', 'IDEA', 'Serpent'
42 # simply any <NAME> for which there exists Crypt::Cipher::<NAME>
43 # $ctr_mode ..... 0 little-endian counter (DEFAULT)
44 # 1 big-endian counter
45 # 2 little-endian + RFC3686 incrementing
46 # 3 big-endian + RFC3686 incrementing
47 # $ctr_width .... counter width in bytes (DEFAULT = full block width)
48 # $cipher_rounds ... optional num of rounds for given cipher
49
50 encrypt
51 my $ciphertext = $m->encrypt($plaintext, $key, $iv);
52
53 decrypt
54 my $plaintext = $m->decrypt($ciphertext, $key, $iv);
55
56 start_encrypt
57 $m->start_encrypt($key, $iv);
58
59 start_decrypt
60 $m->start_decrypt($key, $iv);
61
62 add
63 # in encrypt mode
64 my $plaintext = $m->add($ciphertext);
65
66 # in decrypt mode
67 my $ciphertext = $m->add($plaintext);
68
70 • CryptX, Crypt::Cipher
71
72 • Crypt::Cipher::AES, Crypt::Cipher::Blowfish, ...
73
74 • <https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Counter_.28CTR.29>
75
76
77
78perl v5.34.0 2022-02-14 Crypt::Mode::CTR(3)