← Index
NYTProf Performance Profile   « line view »
For svc/members/upsert
  Run on Tue Jan 13 11:50:22 2015
Reported on Tue Jan 13 12:09:50 2015

Filename/usr/lib/x86_64-linux-gnu/perl5/5.20/Crypt/Eksblowfish/Subkeyed.pm
StatementsExecuted 12 statements in 254µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11116µs16µsCrypt::Eksblowfish::Subkeyed::::BEGIN@73Crypt::Eksblowfish::Subkeyed::BEGIN@73
11115µs15µsCrypt::Eksblowfish::Subkeyed::::BEGIN@69Crypt::Eksblowfish::Subkeyed::BEGIN@69
1119µs16µsCrypt::Eksblowfish::Subkeyed::::BEGIN@70Crypt::Eksblowfish::Subkeyed::BEGIN@70
1116µs16µsCrypt::Eksblowfish::Subkeyed::::BEGIN@71Crypt::Eksblowfish::Subkeyed::BEGIN@71
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1=head1 NAME
2
3Crypt::Eksblowfish::Subkeyed - Blowfish/Eksblowfish with access to subkeys
4
5=head1 SYNOPSIS
6
7 use Crypt::Eksblowfish::Subkeyed;
8
9 $block_size = Crypt::Eksblowfish::Subkeyed->blocksize;
10
11 $cipher = Crypt::Eksblowfish::Subkeyed
12 ->new_from_subkeys(\@p_array, \@s_boxes);
13 $cipher = Crypt::Eksblowfish::Subkeyed->new_initial;
14
15 $block_size = $cipher->blocksize;
16 $ciphertext = $cipher->encrypt($plaintext);
17 $plaintext = $cipher->decrypt($ciphertext);
18
19 $p_array = $cipher->p_array;
20 $s_boxes = $cipher->s_boxes;
21 if($cipher->is_weak) { ...
22
23=head1 DESCRIPTION
24
25An object of this class encapsulates a keyed instance of the Blowfish
26or Eksblowfish block cipher, ready to encrypt and decrypt. Normally
27this class will not be used directly, but through subclasses such as
28L<Crypt::Eksblowfish>.
29
30Eksblowfish is a variant of the Blowfish cipher with a modified key setup
31algorithm. This class doesn't implement either form of key setup, but
32only provides the actual encryption and decryption parts of the ciphers.
33This part is shared between Blowfish and Eksblowfish, and also any other
34cipher that uses the core of Blowfish but supplies its own key setup.
35This class has "Eksblowfish" in its name rather than "Blowfish" merely
36due to the historical accident that it is derived from the encryption
37engine that was used to implement Eksblowfish.
38
39The key setup phase of a block cipher, also known as the "key
40schedule", produces a set of "subkeys", which are somewhat like ordinary
41cryptographic keys (which are the input to the key setup algorithm) but
42are much larger. In some block ciphers the subkeys also have special
43interrelationships. In Blowfish the subkeys consist of a "P-array" of 18
4432-bit entries (one per encryption round plus two more) and four "S-boxes"
45("S" is for "substitution") each of which consists of 256 32-bit entries.
46There is no special relationship between the values of the subkeys.
47
48Methods in this class allow a cipher object to be constructed from
49a full set of subkeys, and for the subkeys to be extracted from a
50cipher object. Normal users don't need to do either of these things.
51It's mainly useful when devising a new key schedule to stick onto the
52Blowfish core, or when performing cryptanalysis of the cipher algorithm.
53
54Generating subkeys directly by a strong random process, rather than by
55expansion of a smaller random key, is an expensive and slightly bizarre
56way to get greater cryptographic strength from a cipher algorithm.
57It eliminates attacks on the key schedule, and yields the full strength
58of the core algorithm. However, this is always a lot less strength than
59the amount of subkey material, whereas a normal key schedule is designed
60to yield strength equal to the length of the (much shorter) key. Also,
61any non-randomness in the source of the subkey material is likely to
62lead to a cryptographic weakness, whereas a key schedule conceals any
63non-randomness in the choice of the key.
64
65=cut
66
67package Crypt::Eksblowfish::Subkeyed;
68
69343µs115µs
# spent 15µs within Crypt::Eksblowfish::Subkeyed::BEGIN@69 which was called: # once (15µs+0s) by parent::import at line 69
{ use 5.006; }
# spent 15µs making 1 call to Crypt::Eksblowfish::Subkeyed::BEGIN@69
70221µs222µs
# spent 16µs (9+6) within Crypt::Eksblowfish::Subkeyed::BEGIN@70 which was called: # once (9µs+6µs) by parent::import at line 70
use warnings;
# spent 16µs making 1 call to Crypt::Eksblowfish::Subkeyed::BEGIN@70 # spent 6µs making 1 call to warnings::import
71218µs226µs
# spent 16µs (6+10) within Crypt::Eksblowfish::Subkeyed::BEGIN@71 which was called: # once (6µs+10µs) by parent::import at line 71
use strict;
# spent 16µs making 1 call to Crypt::Eksblowfish::Subkeyed::BEGIN@71 # spent 10µs making 1 call to strict::import
72
732108µs116µs
# spent 16µs within Crypt::Eksblowfish::Subkeyed::BEGIN@73 which was called: # once (16µs+0s) by parent::import at line 73
use XSLoader;
# spent 16µs making 1 call to Crypt::Eksblowfish::Subkeyed::BEGIN@73
74
751500nsour $VERSION = "0.009";
76
77160µs151µsXSLoader::load("Crypt::Eksblowfish", $VERSION);
# spent 51µs making 1 call to XSLoader::load
78
79=head1 CLASS METHODS
80
81=over
82
83=item Crypt::Eksblowfish::Subkeyed->blocksize
84
85Returns 8, indicating the Eksblowfish block size of 8 octets. This method
86may be called on either the class or an instance.
87
88=back
89
90=head1 CONSTRUCTOR
91
92=over
93
94=item Crypt::Eksblowfish::Subkeyed->new_from_subkeys(ROUND_KEYS, SBOXES)
95
96Creates a new Blowfish cipher object encapsulating the supplied subkeys.
97ROUND_KEYS must be a reference to an array of 18 32-bit integers.
98SBOXES must be a reference to an array of four references to 256-element
99arrays of 32-bit integers. These subkeys are used in the standard order
100for Blowfish.
101
102=item Crypt::Eksblowfish::Subkeyed->new_initial
103
104The standard Blowfish key schedule is an iterative process, which uses
105the cipher algorithm to progressively replace subkeys, thus mutating the
106cipher for subsequent iterations of keying. The Eksblowfish key schedule
107works similarly, but with a lot more iterations. In both cases, the
108key setup algorithm begins with a standard set of subkeys, consisting
109of the initial bits of the fractional part of pi. This constructor
110creates and returns a Blowfish block cipher object with that standard
111initial set of subkeys. This is probably useful only to designers of
112novel key schedules.
113
114=back
115
116=head1 METHODS
117
118=over
119
120=item $cipher->blocksize
121
122Returns 8, indicating the Eksblowfish block size of 8 octets. This method
123may be called on either the class or an instance.
124
125=item $cipher->encrypt(PLAINTEXT)
126
127PLAINTEXT must be exactly eight octets. The block is encrypted, and
128the ciphertext is returned.
129
130=item $cipher->decrypt(CIPHERTEXT)
131
132CIPHERTEXT must be exactly eight octets. The block is decrypted, and
133the plaintext is returned.
134
135=item $cipher->p_array
136
137Returns a reference to an 18-element array containing the 32-bit round
138keys used in this cipher object.
139
140=item $cipher->s_boxes
141
142Returns a reference to a 4-element array containing the S-boxes used in
143this cipher object. Each S-box is a 256-element array of 32-bit entries.
144
145=item $cipher->is_weak
146
147Returns a truth value indicating whether this is a weak key. A key is
148considered weak if any S-box contains a pair of identical entries
149(in any positions). When Blowfish is used with such an S-box, certain
150cryptographic attacks are possible that are not possible against most
151keys. The current (as of 2007) cryptanalytic results on Blowfish do
152not include an actual break of the algorithm when weak keys are used,
153but if a break is ever developed then it is likely to be achieved for
154weak keys before it is achieved for the general case.
155
156About one key in every 2^15 is weak (if the keys are randomly selected).
157Because of the complicated key schedule in standard Blowfish it is not
158possible to predict which keys will be weak without first performing the
159full key setup, which is why this is a method on the keyed cipher object.
160In some uses of Blowfish it may be desired to avoid weak keys; if so,
161check using this method and generate a new random key when a weak key
162is detected. Bruce Schneier, the designer of Blowfish, says it is
163probably not worth avoiding weak keys.
164
165=back
166
167=head1 SEE ALSO
168
169L<Crypt::Eksblowfish>,
170L<Crypt::Eksblowfish::Blowfish>,
171L<http://www.schneier.com/paper-blowfish-fse.html>
172
173=head1 AUTHOR
174
175Eksblowfish guts originally by Solar Designer (solar at openwall.com).
176
177Modifications and Perl interface by Andrew Main (Zefram)
178<zefram@fysh.org>.
179
180=head1 COPYRIGHT
181
182Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011
183Andrew Main (Zefram) <zefram@fysh.org>
184
185The original Eksblowfish code (in the form of crypt()) from which
186this module is derived is in the public domain. It may be found at
187L<http://www.openwall.com/crypt/>.
188
189=head1 LICENSE
190
191This module is free software; you can redistribute it and/or modify it
192under the same terms as Perl itself.
193
194=cut
195
19613µs1;