File Coverage

blib/lib/Crypt/Eksblowfish/Blowfish.pm
Criterion Covered Total %
statement 13 13 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 19 19 100.0


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             Crypt::Eksblowfish::Blowfish - Blowfish block cipher via Eksblowfish engine
4              
5             =head1 SYNOPSIS
6              
7             use Crypt::Eksblowfish::Blowfish;
8              
9             $block_size = Crypt::Eksblowfish::Blowfish->blocksize;
10             $key_size = Crypt::Eksblowfish::Blowfish->keysize;
11              
12             $cipher = Crypt::Eksblowfish::Blowfish->new($key);
13              
14             $block_size = $cipher->blocksize;
15             $ciphertext = $cipher->encrypt($plaintext);
16             $plaintext = $cipher->decrypt($ciphertext);
17              
18             $p_array = $cipher->p_array;
19             $s_boxes = $cipher->s_boxes;
20             if($cipher->is_weak) { ...
21              
22             =head1 DESCRIPTION
23              
24             An object of this type encapsulates a keyed instance of the Blowfish
25             block cipher, ready to encrypt and decrypt.
26              
27             Blowfish is a symmetric cipher algorithm designed by Bruce Schneier
28             in 1993. It operates on 64-bit blocks, and takes a variable-length key
29             from 32 bits (4 octets) to 448 bits (56 octets) in increments of 8 bits
30             (1 octet).
31              
32             This implementation of Blowfish uses an encryption engine that was
33             originally implemented in order to support Eksblowfish, which is a
34             variant of Blowfish modified to make keying particularly expensive.
35             See L for that variant; this class implements the
36             original Blowfish.
37              
38             =cut
39              
40             package Crypt::Eksblowfish::Blowfish;
41              
42 1     1   42818 { use 5.006; }
  1         3  
  1         37  
43 1     1   6 use warnings;
  1         2  
  1         35  
44 1     1   5 use strict;
  1         1  
  1         46  
45              
46             our $VERSION = "0.009";
47              
48 1     1   988 use parent "Crypt::Eksblowfish::Subkeyed";
  1         408  
  1         5  
49              
50             die "mismatched versions of Crypt::Eksblowfish modules"
51             unless $Crypt::Eksblowfish::Subkeyed::VERSION eq $VERSION;
52              
53             =head1 CLASS METHODS
54              
55             =over
56              
57             =item Crypt::Eksblowfish::Blowfish->blocksize
58              
59             Returns 8, indicating the Blowfish block size of 8 octets. This method
60             may be called on either the class or an instance.
61              
62             =item Crypt::Eksblowfish::Blowfish->keysize
63              
64             Returns 0, indicating that the key size is variable. This situation is
65             handled specially by C.
66              
67             =back
68              
69             =cut
70              
71 1     1 1 502 sub keysize { 0 }
72              
73             =head1 CONSTRUCTOR
74              
75             =over
76              
77             =item Crypt::Eksblowfish::Blowfish->new(KEY)
78              
79             Performs key setup on a new instance of the Blowfish algorithm, returning
80             the keyed state. The KEY may be any length from 4 octets to 56 octets
81             inclusive.
82              
83             You may occasionally come across an alleged Blowfish key that is outside
84             this length range, and so is rejected by this constructor. Blowfish
85             can internally process a key of any octet length up to 72 octets, and
86             some implementations don't enforce the official length restrictions.
87             If it is necessary for compatibility, a key of out-of-range length can
88             be processed by L.
89              
90             =back
91              
92             =head1 METHODS
93              
94             =over
95              
96             =item $cipher->blocksize
97              
98             Returns 8, indicating the Blowfish block size of 8 octets. This method
99             may be called on either the class or an instance.
100              
101             =item $cipher->encrypt(PLAINTEXT)
102              
103             PLAINTEXT must be exactly eight octets. The block is encrypted, and
104             the ciphertext is returned.
105              
106             =item $cipher->decrypt(CIPHERTEXT)
107              
108             CIPHERTEXT must be exactly eight octets. The block is decrypted, and
109             the plaintext is returned.
110              
111             =item $cipher->p_array
112              
113             =item $cipher->s_boxes
114              
115             These methods extract the subkeys from the keyed cipher.
116             This is not required in ordinary operation. See the superclass
117             L for details.
118              
119             =item $cipher->is_weak
120              
121             This method checks whether the cipher has been keyed with a weak key.
122             It may be desired to avoid using weak keys. See the superclass
123             L for details.
124              
125             =back
126              
127             =head1 SEE ALSO
128              
129             L,
130             L,
131             L,
132             L
133              
134             =head1 AUTHOR
135              
136             Eksblowfish guts originally by Solar Designer (solar at openwall.com).
137              
138             Modifications and Perl interface by Andrew Main (Zefram)
139             .
140              
141             =head1 COPYRIGHT
142              
143             Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011
144             Andrew Main (Zefram)
145              
146             The original Eksblowfish code (in the form of crypt()) from which
147             this module is derived is in the public domain. It may be found at
148             L.
149              
150             =head1 LICENSE
151              
152             This module is free software; you can redistribute it and/or modify it
153             under the same terms as Perl itself.
154              
155             =cut
156              
157             1;