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