File Coverage

blib/lib/Crypt/Mode/ECB.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::ECB;
2              
3             ### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
4              
5 21     21   77547 use strict;
  21         28  
  21         582  
6 21     21   84 use warnings;
  21         26  
  21         1029  
7             our $VERSION = '0.088_004';
8              
9 21     21   413 use Crypt::Cipher;
  21         27  
  21         3206  
10              
11             sub encrypt {
12 66     66 1 460771 my ($self, $pt) = (shift, shift);
13 66         268 local $SIG{__DIE__} = \&CryptX::_croak;
14 66         840 $self->start_encrypt(@_)->add($pt) . $self->finish;
15             }
16              
17             sub decrypt {
18 66     66 1 1193 my ($self, $ct) = (shift, shift);
19 66         146 local $SIG{__DIE__} = \&CryptX::_croak;
20 66         391 $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::ECB - Block cipher mode ECB [Electronic codebook]
32              
33             =head1 SYNOPSIS
34              
35             use Crypt::Mode::ECB;
36             my $m = Crypt::Mode::ECB->new('AES');
37             my $key = '1234567890123456';
38             my $plaintext = 'example plaintext';
39             my $chunk1 = 'example ';
40             my $chunk2 = 'plaintext';
41              
42             #(en|de)crypt at once
43             my $single_ciphertext = $m->encrypt($plaintext, $key);
44             my $single_plaintext = $m->decrypt($single_ciphertext, $key);
45              
46             #encrypt more chunks
47             $m->start_encrypt($key);
48             my $chunked_ciphertext = '';
49             $chunked_ciphertext .= $m->add($chunk1);
50             $chunked_ciphertext .= $m->add($chunk2);
51             $chunked_ciphertext .= $m->finish;
52              
53             #decrypt more chunks
54             $m->start_decrypt($key);
55             my $chunked_plaintext = '';
56             $chunked_plaintext .= $m->add($chunked_ciphertext);
57             $chunked_plaintext .= $m->finish;
58              
59             =head1 DESCRIPTION
60              
61             This module implements ECB cipher mode. B it works only with ciphers from L (Crypt::Cipher::NNNN).
62             B, if you are not sure go for L!
63              
64             =head1 METHODS
65              
66             Unless noted otherwise, assume C<$m> is an existing mode object created via
67             C, for example:
68              
69             my $m = Crypt::Mode::ECB->new('AES');
70              
71             =head2 new
72              
73             my $m = Crypt::Mode::ECB->new($name);
74             #or
75             my $m = Crypt::Mode::ECB->new($name, $padding);
76             #or
77             my $m = Crypt::Mode::ECB->new($name, $padding, $cipher_rounds);
78              
79             # $name ....... [string] one of 'AES', 'Anubis', 'Blowfish', 'CAST5', 'Camellia', 'DES', 'DES_EDE',
80             # 'KASUMI', 'Khazad', 'MULTI2', 'Noekeon', 'RC2', 'RC5', 'RC6',
81             # 'SAFERP', 'SAFER_K128', 'SAFER_K64', 'SAFER_SK128', 'SAFER_SK64',
82             # 'SEED', 'Skipjack', 'Twofish', 'XTEA', 'IDEA', 'Serpent'
83             # simply any for which there exists Crypt::Cipher::
84             # $padding .... [integer] 0 no padding (plaintext size has to be multiple of block length)
85             # 1 PKCS5 padding, Crypt::CBC's "standard" - DEFAULT
86             # 2 Crypt::CBC's "oneandzeroes"
87             # 3 ANSI X.923 padding
88             # 4 zero padding
89             # 5 zero padding (+a block of zeros if the output length is divisible by the blocksize)
90             # $cipher_rounds ... [integer] optional, num of rounds for given cipher
91              
92             =head2 encrypt
93              
94             Encrypts the plaintext in a single call. Returns the ciphertext as a binary string.
95             The plaintext 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 $ciphertext = $m->encrypt($plaintext, $key);
101              
102             =head2 decrypt
103              
104             Decrypts the ciphertext in a single call. Returns the plaintext as a binary string.
105             The ciphertext scalar is converted to bytes using Perl's usual scalar
106             stringification. Defined scalars, including numbers and string-overloaded
107             objects, are accepted. C is treated as an empty string and may emit
108             Perl's usual "uninitialized value" warning.
109              
110             my $plaintext = $m->decrypt($ciphertext, $key);
111              
112             =head2 start_encrypt
113              
114             Initializes encryption mode. Returns the object itself.
115              
116             $m->start_encrypt($key);
117              
118             =head2 start_decrypt
119              
120             Initializes decryption mode. Returns the object itself.
121              
122             $m->start_decrypt($key);
123              
124             =head2 add
125              
126             Feeds data to the encryption or decryption stream. Returns a binary string.
127              
128             Each argument is converted to bytes using Perl's usual scalar stringification.
129             Defined scalars, including numbers and string-overloaded objects, are
130             accepted. C is treated as an empty string and may emit Perl's usual
131             "uninitialized value" warning.
132              
133             # in encrypt mode
134             my $ciphertext = $m->add($plaintext);
135              
136             # in decrypt mode
137             my $plaintext = $m->add($ciphertext);
138              
139             =head2 finish
140              
141             #encrypt more chunks
142             $m->start_encrypt($key);
143             my $chunk1 = 'example ';
144             my $chunk2 = 'plaintext';
145             my $ciphertext = '';
146             $ciphertext .= $m->add($chunk1);
147             $ciphertext .= $m->add($chunk2);
148             $ciphertext .= $m->finish;
149              
150             #decrypt more chunks
151             $m->start_decrypt($key);
152             my $plaintext = '';
153             $plaintext .= $m->add($ciphertext);
154             $plaintext .= $m->finish;
155              
156             =head1 SEE ALSO
157              
158             =over
159              
160             =item * L, L
161              
162             =item * L, L, ...
163              
164             =item * L
165              
166             =back
167              
168             =cut