@@ -51,186 +51,186 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | class Cipher_3Way extends Cipher |
| 53 | 53 | { |
| 54 | - /** @type integer BYTES_BLOCK The size of the block, in bytes */ |
|
| 55 | - const BYTES_BLOCK = 12; // 96 bits; |
|
| 56 | - |
|
| 57 | - /** @type integer BYTES_KEY The size of the key, in bytes */ |
|
| 58 | - const BYTES_KEY = 12; // 96 bits; |
|
| 59 | - |
|
| 60 | - /** @type integer ROUNDS The number of rounds to implement */ |
|
| 61 | - const ROUNDS = 11; |
|
| 62 | - |
|
| 63 | - /** @type array $_rconst_enc The round constants for encryption */ |
|
| 64 | - private static $_rcon_enc = array(); |
|
| 65 | - |
|
| 66 | - /** @type array $_rconst_enc The round constants for decryption */ |
|
| 67 | - private static $_rcon_dec = array(); |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Constructor |
|
| 72 | - * |
|
| 73 | - * @param string $key The key used for Encryption/Decryption |
|
| 74 | - * @return void |
|
| 75 | - */ |
|
| 76 | - public function __construct($key) |
|
| 77 | - { |
|
| 78 | - // set the key, make sure the required length is set in bytes |
|
| 79 | - parent::__construct(PHP_Crypt::CIPHER_3WAY, $key, self::BYTES_KEY); |
|
| 80 | - |
|
| 81 | - // set the block size |
|
| 82 | - $this->blockSize(self::BYTES_BLOCK); |
|
| 83 | - |
|
| 84 | - // initialize the round constants |
|
| 85 | - $this->initTables(); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Destructor |
|
| 91 | - * |
|
| 92 | - * @return void |
|
| 93 | - */ |
|
| 94 | - public function __destruct() |
|
| 95 | - { |
|
| 96 | - parent::__destruct(); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Encrypt plain text data |
|
| 102 | - * |
|
| 103 | - * @param string $data A 96 bit plain data |
|
| 104 | - * @return boolean Returns true |
|
| 105 | - */ |
|
| 106 | - public function encrypt(&$data) |
|
| 107 | - { |
|
| 108 | - $this->operation(parent::ENCRYPT); |
|
| 109 | - return $this->threeway($data); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Decrypt an encrypted string |
|
| 115 | - * |
|
| 116 | - * @param string $data A 96 bit block encrypted data |
|
| 117 | - * @return boolean Returns true |
|
| 118 | - */ |
|
| 119 | - public function decrypt(&$data) |
|
| 120 | - { |
|
| 121 | - $this->operation(parent::DECRYPT); |
|
| 122 | - return $this->threeway($data); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * The same alorigthm is used for both Encryption, and Decryption |
|
| 128 | - * |
|
| 129 | - * @param string $data A 96 bit block of data |
|
| 130 | - * @return boolean Returns true |
|
| 131 | - */ |
|
| 132 | - private function threeway(&$data) |
|
| 133 | - { |
|
| 134 | - // first split $data into three 32 bit parts |
|
| 135 | - $data = str_split($data, 4); |
|
| 136 | - $data = array_map("parent::str2Dec", $data); |
|
| 137 | - |
|
| 138 | - // split the key into three 32 bit parts |
|
| 139 | - $key = str_split($this->key(), 4); |
|
| 140 | - $key = array_map("parent::str2Dec", $key); |
|
| 141 | - |
|
| 142 | - // determine which round constant to use |
|
| 143 | - if($this->operation() == parent::ENCRYPT) |
|
| 144 | - $rcon = self::$_rcon_enc; |
|
| 145 | - else |
|
| 146 | - $rcon = self::$_rcon_dec; |
|
| 147 | - |
|
| 148 | - if($this->operation() == parent::DECRYPT) |
|
| 149 | - { |
|
| 150 | - $this->theta($key); |
|
| 151 | - $this->invertBits($key); |
|
| 152 | - $this->invertBits($data); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - // 3Way uses 11 rounds |
|
| 156 | - for($i = 0; $i < self::ROUNDS; ++$i) |
|
| 157 | - { |
|
| 158 | - $data[0] = parent::uInt32($data[0] ^ $key[0] ^ ($rcon[$i] << 16)); |
|
| 159 | - $data[1] = parent::uInt32($data[1] ^ $key[1]); |
|
| 160 | - $data[2] = parent::uInt32($data[2] ^ $key[2] ^ $rcon[$i]); |
|
| 161 | - |
|
| 162 | - $this->rho($data); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - $data[0] = parent::uInt32($data[0] ^ $key[0] ^ ($rcon[self::ROUNDS] << 16)); |
|
| 166 | - $data[1] = parent::uInt32($data[1] ^ $key[1]); |
|
| 167 | - $data[2] = parent::uInt32($data[2] ^ $key[2] ^ $rcon[self::ROUNDS]); |
|
| 168 | - |
|
| 169 | - $this->theta($data); |
|
| 170 | - |
|
| 171 | - if($this->operation() == parent::DECRYPT) |
|
| 172 | - $this->invertBits($data); |
|
| 173 | - |
|
| 174 | - // assemble the three 32 bit parts back to a 96 bit string |
|
| 175 | - $data = parent::dec2Str($data[0], 4).parent::dec2Str($data[1], 4). |
|
| 176 | - parent::dec2Str($data[2], 4); |
|
| 177 | - |
|
| 178 | - return true; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * 3-Way's Theta function |
|
| 184 | - * This was translated from mcrypt's 3-Way theta() function |
|
| 185 | - * |
|
| 186 | - * @param array $d A 3 element array of 32 bit integers |
|
| 187 | - * @return void |
|
| 188 | - */ |
|
| 189 | - private function theta(&$d) |
|
| 190 | - { |
|
| 191 | - $tmp = array(); |
|
| 192 | - |
|
| 193 | - $tmp[0] = parent::uInt32( |
|
| 194 | - $d[0] ^ ($d[0] >> 16) ^ ($d[1] << 16) ^ ($d[1] >> 16) ^ ($d[2] << 16) ^ |
|
| 195 | - ($d[1] >> 24) ^ ($d[2] << 8) ^ ($d[2] >> 8) ^ ($d[0] << 24) ^ ($d[2] >> 16) ^ |
|
| 196 | - ($d[0] << 16) ^ ($d[2] >> 24) ^ ($d[0] << 8) |
|
| 197 | - ); |
|
| 198 | - |
|
| 199 | - $tmp[1] = parent::uInt32( |
|
| 200 | - $d[1] ^ ($d[1] >> 16) ^ ($d[2] << 16) ^ ($d[2] >> 16) ^ ($d[0] << 16) ^ |
|
| 201 | - ($d[2] >> 24) ^ ($d[0] << 8) ^ ($d[0] >> 8) ^ ($d[1] << 24) ^ ($d[0] >> 16) ^ |
|
| 202 | - ($d[1] << 16) ^ ($d[0] >> 24) ^ ($d[1] << 8) |
|
| 203 | - ); |
|
| 204 | - |
|
| 205 | - $tmp[2] = parent::uInt32( |
|
| 206 | - $d[2] ^ ($d[2] >> 16) ^ ($d[0] << 16) ^ ($d[0] >> 16) ^ ($d[1] << 16) ^ |
|
| 207 | - ($d[0] >> 24) ^ ($d[1] << 8) ^ ($d[1] >> 8) ^ ($d[2] << 24) ^ ($d[1] >> 16) ^ |
|
| 208 | - ($d[2] << 16) ^ ($d[1] >> 24) ^ ($d[2] << 8) |
|
| 209 | - ); |
|
| 210 | - |
|
| 211 | - $d = $tmp; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * 3-Ways gamma() function |
|
| 217 | - * NOTE: After extensive testing against mcrypt's 3way, it appears |
|
| 218 | - * mcrypt's 3way gamma() function does not modify the array passed into |
|
| 219 | - * it. During testing mcrypt's 3way gamma() function returned the exact |
|
| 220 | - * same values sent into it. I'm confused as to why this is, and |
|
| 221 | - * can't find enough information about 3-Way to know if this is correct |
|
| 222 | - * though I suspect it's not. For compatibility, I am going to make |
|
| 223 | - * phpCrypt's 3way gamma() function leave the values unmodified. I will change |
|
| 224 | - * this at a later date if I find this is incorrect and mcrypt has a bug |
|
| 225 | - * |
|
| 226 | - * This was translated from mcrypt's 3-Way gamma() function |
|
| 227 | - * |
|
| 228 | - * @param array $d A 3 element array of 32 bit integers |
|
| 229 | - * @return void |
|
| 230 | - */ |
|
| 231 | - private function gamma(&$d) |
|
| 232 | - { |
|
| 233 | - /* |
|
| 54 | + /** @type integer BYTES_BLOCK The size of the block, in bytes */ |
|
| 55 | + const BYTES_BLOCK = 12; // 96 bits; |
|
| 56 | + |
|
| 57 | + /** @type integer BYTES_KEY The size of the key, in bytes */ |
|
| 58 | + const BYTES_KEY = 12; // 96 bits; |
|
| 59 | + |
|
| 60 | + /** @type integer ROUNDS The number of rounds to implement */ |
|
| 61 | + const ROUNDS = 11; |
|
| 62 | + |
|
| 63 | + /** @type array $_rconst_enc The round constants for encryption */ |
|
| 64 | + private static $_rcon_enc = array(); |
|
| 65 | + |
|
| 66 | + /** @type array $_rconst_enc The round constants for decryption */ |
|
| 67 | + private static $_rcon_dec = array(); |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Constructor |
|
| 72 | + * |
|
| 73 | + * @param string $key The key used for Encryption/Decryption |
|
| 74 | + * @return void |
|
| 75 | + */ |
|
| 76 | + public function __construct($key) |
|
| 77 | + { |
|
| 78 | + // set the key, make sure the required length is set in bytes |
|
| 79 | + parent::__construct(PHP_Crypt::CIPHER_3WAY, $key, self::BYTES_KEY); |
|
| 80 | + |
|
| 81 | + // set the block size |
|
| 82 | + $this->blockSize(self::BYTES_BLOCK); |
|
| 83 | + |
|
| 84 | + // initialize the round constants |
|
| 85 | + $this->initTables(); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Destructor |
|
| 91 | + * |
|
| 92 | + * @return void |
|
| 93 | + */ |
|
| 94 | + public function __destruct() |
|
| 95 | + { |
|
| 96 | + parent::__destruct(); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Encrypt plain text data |
|
| 102 | + * |
|
| 103 | + * @param string $data A 96 bit plain data |
|
| 104 | + * @return boolean Returns true |
|
| 105 | + */ |
|
| 106 | + public function encrypt(&$data) |
|
| 107 | + { |
|
| 108 | + $this->operation(parent::ENCRYPT); |
|
| 109 | + return $this->threeway($data); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Decrypt an encrypted string |
|
| 115 | + * |
|
| 116 | + * @param string $data A 96 bit block encrypted data |
|
| 117 | + * @return boolean Returns true |
|
| 118 | + */ |
|
| 119 | + public function decrypt(&$data) |
|
| 120 | + { |
|
| 121 | + $this->operation(parent::DECRYPT); |
|
| 122 | + return $this->threeway($data); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * The same alorigthm is used for both Encryption, and Decryption |
|
| 128 | + * |
|
| 129 | + * @param string $data A 96 bit block of data |
|
| 130 | + * @return boolean Returns true |
|
| 131 | + */ |
|
| 132 | + private function threeway(&$data) |
|
| 133 | + { |
|
| 134 | + // first split $data into three 32 bit parts |
|
| 135 | + $data = str_split($data, 4); |
|
| 136 | + $data = array_map("parent::str2Dec", $data); |
|
| 137 | + |
|
| 138 | + // split the key into three 32 bit parts |
|
| 139 | + $key = str_split($this->key(), 4); |
|
| 140 | + $key = array_map("parent::str2Dec", $key); |
|
| 141 | + |
|
| 142 | + // determine which round constant to use |
|
| 143 | + if($this->operation() == parent::ENCRYPT) |
|
| 144 | + $rcon = self::$_rcon_enc; |
|
| 145 | + else |
|
| 146 | + $rcon = self::$_rcon_dec; |
|
| 147 | + |
|
| 148 | + if($this->operation() == parent::DECRYPT) |
|
| 149 | + { |
|
| 150 | + $this->theta($key); |
|
| 151 | + $this->invertBits($key); |
|
| 152 | + $this->invertBits($data); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + // 3Way uses 11 rounds |
|
| 156 | + for($i = 0; $i < self::ROUNDS; ++$i) |
|
| 157 | + { |
|
| 158 | + $data[0] = parent::uInt32($data[0] ^ $key[0] ^ ($rcon[$i] << 16)); |
|
| 159 | + $data[1] = parent::uInt32($data[1] ^ $key[1]); |
|
| 160 | + $data[2] = parent::uInt32($data[2] ^ $key[2] ^ $rcon[$i]); |
|
| 161 | + |
|
| 162 | + $this->rho($data); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + $data[0] = parent::uInt32($data[0] ^ $key[0] ^ ($rcon[self::ROUNDS] << 16)); |
|
| 166 | + $data[1] = parent::uInt32($data[1] ^ $key[1]); |
|
| 167 | + $data[2] = parent::uInt32($data[2] ^ $key[2] ^ $rcon[self::ROUNDS]); |
|
| 168 | + |
|
| 169 | + $this->theta($data); |
|
| 170 | + |
|
| 171 | + if($this->operation() == parent::DECRYPT) |
|
| 172 | + $this->invertBits($data); |
|
| 173 | + |
|
| 174 | + // assemble the three 32 bit parts back to a 96 bit string |
|
| 175 | + $data = parent::dec2Str($data[0], 4).parent::dec2Str($data[1], 4). |
|
| 176 | + parent::dec2Str($data[2], 4); |
|
| 177 | + |
|
| 178 | + return true; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * 3-Way's Theta function |
|
| 184 | + * This was translated from mcrypt's 3-Way theta() function |
|
| 185 | + * |
|
| 186 | + * @param array $d A 3 element array of 32 bit integers |
|
| 187 | + * @return void |
|
| 188 | + */ |
|
| 189 | + private function theta(&$d) |
|
| 190 | + { |
|
| 191 | + $tmp = array(); |
|
| 192 | + |
|
| 193 | + $tmp[0] = parent::uInt32( |
|
| 194 | + $d[0] ^ ($d[0] >> 16) ^ ($d[1] << 16) ^ ($d[1] >> 16) ^ ($d[2] << 16) ^ |
|
| 195 | + ($d[1] >> 24) ^ ($d[2] << 8) ^ ($d[2] >> 8) ^ ($d[0] << 24) ^ ($d[2] >> 16) ^ |
|
| 196 | + ($d[0] << 16) ^ ($d[2] >> 24) ^ ($d[0] << 8) |
|
| 197 | + ); |
|
| 198 | + |
|
| 199 | + $tmp[1] = parent::uInt32( |
|
| 200 | + $d[1] ^ ($d[1] >> 16) ^ ($d[2] << 16) ^ ($d[2] >> 16) ^ ($d[0] << 16) ^ |
|
| 201 | + ($d[2] >> 24) ^ ($d[0] << 8) ^ ($d[0] >> 8) ^ ($d[1] << 24) ^ ($d[0] >> 16) ^ |
|
| 202 | + ($d[1] << 16) ^ ($d[0] >> 24) ^ ($d[1] << 8) |
|
| 203 | + ); |
|
| 204 | + |
|
| 205 | + $tmp[2] = parent::uInt32( |
|
| 206 | + $d[2] ^ ($d[2] >> 16) ^ ($d[0] << 16) ^ ($d[0] >> 16) ^ ($d[1] << 16) ^ |
|
| 207 | + ($d[0] >> 24) ^ ($d[1] << 8) ^ ($d[1] >> 8) ^ ($d[2] << 24) ^ ($d[1] >> 16) ^ |
|
| 208 | + ($d[2] << 16) ^ ($d[1] >> 24) ^ ($d[2] << 8) |
|
| 209 | + ); |
|
| 210 | + |
|
| 211 | + $d = $tmp; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * 3-Ways gamma() function |
|
| 217 | + * NOTE: After extensive testing against mcrypt's 3way, it appears |
|
| 218 | + * mcrypt's 3way gamma() function does not modify the array passed into |
|
| 219 | + * it. During testing mcrypt's 3way gamma() function returned the exact |
|
| 220 | + * same values sent into it. I'm confused as to why this is, and |
|
| 221 | + * can't find enough information about 3-Way to know if this is correct |
|
| 222 | + * though I suspect it's not. For compatibility, I am going to make |
|
| 223 | + * phpCrypt's 3way gamma() function leave the values unmodified. I will change |
|
| 224 | + * this at a later date if I find this is incorrect and mcrypt has a bug |
|
| 225 | + * |
|
| 226 | + * This was translated from mcrypt's 3-Way gamma() function |
|
| 227 | + * |
|
| 228 | + * @param array $d A 3 element array of 32 bit integers |
|
| 229 | + * @return void |
|
| 230 | + */ |
|
| 231 | + private function gamma(&$d) |
|
| 232 | + { |
|
| 233 | + /* |
|
| 234 | 234 | $tmp = array(); |
| 235 | 235 | |
| 236 | 236 | $tmp[0] = parent::uInt32($d[0] ^ ($d[1] | (~$d[2]))); |
@@ -239,102 +239,102 @@ discard block |
||
| 239 | 239 | |
| 240 | 240 | $d = $tmp; |
| 241 | 241 | */ |
| 242 | - } |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * Applies several of 3Way's functions used for encryption and decryption |
|
| 247 | - * NOTE: Please read the comments in the $this->gamma() function. This |
|
| 248 | - * function calls the $this->gamma() function which does not do anything. |
|
| 249 | - * |
|
| 250 | - * @param array $d A 3 element 32 bit integer array |
|
| 251 | - * @return void |
|
| 252 | - */ |
|
| 253 | - private function rho(&$d) |
|
| 254 | - { |
|
| 255 | - $this->theta($d); |
|
| 256 | - $this->pi1($d); |
|
| 257 | - $this->gamma($d); |
|
| 258 | - $this->pi2($d); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * 3Way's PI_1 function |
|
| 264 | - * This was taken from mcrypt's 3-way pi_1() function |
|
| 265 | - * |
|
| 266 | - * @param array $d A 3 element 32 bit integer array |
|
| 267 | - * @return void |
|
| 268 | - */ |
|
| 269 | - private function pi1(&$d) |
|
| 270 | - { |
|
| 271 | - $d[0] = parent::uInt32(($d[0] >> 10) ^ ($d[0] << 22)); |
|
| 272 | - $d[2] = parent::uInt32(($d[2] << 1) ^ ($d[2] >> 31)); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * 3Way's PI_2 function |
|
| 278 | - * This was taken from mcrypt's 3-way pi_2() function |
|
| 279 | - * |
|
| 280 | - * @param array $d A 3 element 32 bit integer array |
|
| 281 | - * @return void |
|
| 282 | - */ |
|
| 283 | - private function pi2(&$d) |
|
| 284 | - { |
|
| 285 | - $d[0] = parent::uInt32(($d[0] << 1) ^ ($d[0] >> 31)); |
|
| 286 | - $d[2] = parent::uInt32(($d[2] >> 10) ^ ($d[2] << 22)); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * Reverse the bits of each element of array $d, and |
|
| 292 | - * reverses the order of array $d, used only during |
|
| 293 | - * decryption |
|
| 294 | - * |
|
| 295 | - * @param array $d A 3 element array of a 32 bit integers |
|
| 296 | - * @return void |
|
| 297 | - */ |
|
| 298 | - private function invertBits(&$d) |
|
| 299 | - { |
|
| 300 | - $d = array_map("parent::dec2Bin", $d); |
|
| 301 | - $d = array_map("strrev", $d); |
|
| 302 | - $d = array_map("parent::bin2Dec", $d); |
|
| 303 | - $d = array_reverse($d); |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * Initialize the tables used in 3Way Encryption. |
|
| 309 | - * |
|
| 310 | - * @return void |
|
| 311 | - */ |
|
| 312 | - private function initTables() |
|
| 313 | - { |
|
| 314 | - // round constants for encryption |
|
| 315 | - self::$_rcon_enc = array( |
|
| 316 | - 0x0B0B, 0x1616, 0x2C2C, 0x5858, |
|
| 317 | - 0xB0B0, 0x7171, 0xE2E2, 0xD5D5, |
|
| 318 | - 0xBBBB, 0x6767, 0xCECE, 0x8D8D |
|
| 319 | - ); |
|
| 320 | - |
|
| 321 | - // round constants for decryption |
|
| 322 | - self::$_rcon_dec = array( |
|
| 323 | - 0xB1B1, 0x7373, 0xE6E6, 0xDDDD, |
|
| 324 | - 0xABAB, 0x4747, 0x8E8E, 0x0D0D, |
|
| 325 | - 0x1A1A, 0x3434, 0x6868, 0xD0D0 |
|
| 326 | - ); |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * Indicates this is a block cipher |
|
| 332 | - * |
|
| 333 | - * @return integer Returns Cipher::BLOCK |
|
| 334 | - */ |
|
| 335 | - public function type() |
|
| 336 | - { |
|
| 337 | - return parent::BLOCK; |
|
| 338 | - } |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * Applies several of 3Way's functions used for encryption and decryption |
|
| 247 | + * NOTE: Please read the comments in the $this->gamma() function. This |
|
| 248 | + * function calls the $this->gamma() function which does not do anything. |
|
| 249 | + * |
|
| 250 | + * @param array $d A 3 element 32 bit integer array |
|
| 251 | + * @return void |
|
| 252 | + */ |
|
| 253 | + private function rho(&$d) |
|
| 254 | + { |
|
| 255 | + $this->theta($d); |
|
| 256 | + $this->pi1($d); |
|
| 257 | + $this->gamma($d); |
|
| 258 | + $this->pi2($d); |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * 3Way's PI_1 function |
|
| 264 | + * This was taken from mcrypt's 3-way pi_1() function |
|
| 265 | + * |
|
| 266 | + * @param array $d A 3 element 32 bit integer array |
|
| 267 | + * @return void |
|
| 268 | + */ |
|
| 269 | + private function pi1(&$d) |
|
| 270 | + { |
|
| 271 | + $d[0] = parent::uInt32(($d[0] >> 10) ^ ($d[0] << 22)); |
|
| 272 | + $d[2] = parent::uInt32(($d[2] << 1) ^ ($d[2] >> 31)); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * 3Way's PI_2 function |
|
| 278 | + * This was taken from mcrypt's 3-way pi_2() function |
|
| 279 | + * |
|
| 280 | + * @param array $d A 3 element 32 bit integer array |
|
| 281 | + * @return void |
|
| 282 | + */ |
|
| 283 | + private function pi2(&$d) |
|
| 284 | + { |
|
| 285 | + $d[0] = parent::uInt32(($d[0] << 1) ^ ($d[0] >> 31)); |
|
| 286 | + $d[2] = parent::uInt32(($d[2] >> 10) ^ ($d[2] << 22)); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * Reverse the bits of each element of array $d, and |
|
| 292 | + * reverses the order of array $d, used only during |
|
| 293 | + * decryption |
|
| 294 | + * |
|
| 295 | + * @param array $d A 3 element array of a 32 bit integers |
|
| 296 | + * @return void |
|
| 297 | + */ |
|
| 298 | + private function invertBits(&$d) |
|
| 299 | + { |
|
| 300 | + $d = array_map("parent::dec2Bin", $d); |
|
| 301 | + $d = array_map("strrev", $d); |
|
| 302 | + $d = array_map("parent::bin2Dec", $d); |
|
| 303 | + $d = array_reverse($d); |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * Initialize the tables used in 3Way Encryption. |
|
| 309 | + * |
|
| 310 | + * @return void |
|
| 311 | + */ |
|
| 312 | + private function initTables() |
|
| 313 | + { |
|
| 314 | + // round constants for encryption |
|
| 315 | + self::$_rcon_enc = array( |
|
| 316 | + 0x0B0B, 0x1616, 0x2C2C, 0x5858, |
|
| 317 | + 0xB0B0, 0x7171, 0xE2E2, 0xD5D5, |
|
| 318 | + 0xBBBB, 0x6767, 0xCECE, 0x8D8D |
|
| 319 | + ); |
|
| 320 | + |
|
| 321 | + // round constants for decryption |
|
| 322 | + self::$_rcon_dec = array( |
|
| 323 | + 0xB1B1, 0x7373, 0xE6E6, 0xDDDD, |
|
| 324 | + 0xABAB, 0x4747, 0x8E8E, 0x0D0D, |
|
| 325 | + 0x1A1A, 0x3434, 0x6868, 0xD0D0 |
|
| 326 | + ); |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * Indicates this is a block cipher |
|
| 332 | + * |
|
| 333 | + * @return integer Returns Cipher::BLOCK |
|
| 334 | + */ |
|
| 335 | + public function type() |
|
| 336 | + { |
|
| 337 | + return parent::BLOCK; |
|
| 338 | + } |
|
| 339 | 339 | } |
| 340 | 340 | ?> |
@@ -40,563 +40,563 @@ |
||
| 40 | 40 | */ |
| 41 | 41 | class Cipher_Blowfish extends Cipher |
| 42 | 42 | { |
| 43 | - /** @type integer BYTES_BLOCK The size of the block, in bytes */ |
|
| 44 | - const BYTES_BLOCK = 8; // 64 bits; |
|
| 43 | + /** @type integer BYTES_BLOCK The size of the block, in bytes */ |
|
| 44 | + const BYTES_BLOCK = 8; // 64 bits; |
|
| 45 | 45 | |
| 46 | - // a variable length key, between 8 - 448 bits |
|
| 47 | - //const BYTES_KEY = 0; |
|
| 46 | + // a variable length key, between 8 - 448 bits |
|
| 47 | + //const BYTES_KEY = 0; |
|
| 48 | 48 | |
| 49 | - /** @type array $_sbox1 S-Box 1 */ |
|
| 50 | - private static $_sbox1 = array(); |
|
| 49 | + /** @type array $_sbox1 S-Box 1 */ |
|
| 50 | + private static $_sbox1 = array(); |
|
| 51 | 51 | |
| 52 | - /** @type string $_sbox2 S-Box 2 */ |
|
| 53 | - private static $_sbox2 = array(); |
|
| 52 | + /** @type string $_sbox2 S-Box 2 */ |
|
| 53 | + private static $_sbox2 = array(); |
|
| 54 | 54 | |
| 55 | - /** @type string $_sbox3 S-Box 3 */ |
|
| 56 | - private static $_sbox3 = array(); |
|
| 55 | + /** @type string $_sbox3 S-Box 3 */ |
|
| 56 | + private static $_sbox3 = array(); |
|
| 57 | 57 | |
| 58 | - /** @type string $_sbox4 S-Box 4 */ |
|
| 59 | - private static $_sbox4 = array(); |
|
| 58 | + /** @type string $_sbox4 S-Box 4 */ |
|
| 59 | + private static $_sbox4 = array(); |
|
| 60 | 60 | |
| 61 | - /** @type array $_p The P-Array, 18 elements long */ |
|
| 62 | - private static $_p = array(); |
|
| 61 | + /** @type array $_p The P-Array, 18 elements long */ |
|
| 62 | + private static $_p = array(); |
|
| 63 | 63 | |
| 64 | - /** @type integer $key_pos Used for keyChunk(), to determine the current |
|
| 64 | + /** @type integer $key_pos Used for keyChunk(), to determine the current |
|
| 65 | 65 | position in the key */ |
| 66 | - private $key_pos = 0; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Constructor |
|
| 70 | - * |
|
| 71 | - * @param string $key The key used for Encryption/Decryption |
|
| 72 | - * @return void |
|
| 73 | - */ |
|
| 74 | - public function __construct($key) |
|
| 75 | - { |
|
| 76 | - // the max length of the key is 448 bits (56 bytes) |
|
| 77 | - $keylen = strlen($key); |
|
| 78 | - if($keylen > 56) |
|
| 79 | - { |
|
| 80 | - $key = substr($key, 0, 56); |
|
| 81 | - $keylen = 56; |
|
| 82 | - } |
|
| 83 | - else if($keylen < 1) |
|
| 84 | - { |
|
| 85 | - $msg = "No key given. The key must be between 1 - 56 bytes."; |
|
| 86 | - trigger_error($msg, E_USER_WARNING); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - // set the key, make sure the required length is set in bits |
|
| 90 | - parent::__construct(PHP_Crypt::CIPHER_BLOWFISH, $key, $keylen); |
|
| 91 | - |
|
| 92 | - // set the block size |
|
| 93 | - $this->blockSize(self::BYTES_BLOCK); |
|
| 94 | - |
|
| 95 | - $this->initTables(); |
|
| 96 | - $this->subKeys(); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Destructor |
|
| 102 | - * |
|
| 103 | - * @return void |
|
| 104 | - */ |
|
| 105 | - public function __destruct() |
|
| 106 | - { |
|
| 107 | - parent::__destruct(); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Encrypt plain text data |
|
| 113 | - * |
|
| 114 | - * @param string $data A 64 bit (8 byte) plain text string |
|
| 115 | - * @return boolean Returns true |
|
| 116 | - */ |
|
| 117 | - public function encrypt(&$data) |
|
| 118 | - { |
|
| 119 | - $this->operation(parent::ENCRYPT); |
|
| 120 | - return $this->blowfish($data); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Decrypt an encrypted string |
|
| 126 | - * |
|
| 127 | - * @param string $data A 64 bit block of Blowfish encrypted data |
|
| 128 | - * @return boolean Returns true |
|
| 129 | - */ |
|
| 130 | - public function decrypt(&$data) |
|
| 131 | - { |
|
| 132 | - $this->operation(parent::DECRYPT); |
|
| 133 | - return $this->blowfish($data); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * The same alorigthm is used for both Encryption, and Decryption |
|
| 139 | - * |
|
| 140 | - * @param string $data A 64 bit block of data |
|
| 141 | - * @return boolean Returns true |
|
| 142 | - */ |
|
| 143 | - private function blowfish(&$data) |
|
| 144 | - { |
|
| 145 | - // divide the data into into two 32 bit halves |
|
| 146 | - $xl = parent::str2Dec(substr($data, 0, 4)); |
|
| 147 | - $xr = parent::str2Dec(substr($data, 4, 4)); |
|
| 148 | - |
|
| 149 | - for($i = 0; $i < 16; ++$i) |
|
| 150 | - { |
|
| 151 | - if($this->operation() == parent::ENCRYPT) |
|
| 152 | - $xl ^= self::$_p[$i]; |
|
| 153 | - else |
|
| 154 | - $xl ^= self::$_p[17-$i]; |
|
| 155 | - |
|
| 156 | - // perform F() on the left half, and XOR with the right half |
|
| 157 | - $xr = $this->F($xl) ^ $xr; |
|
| 158 | - |
|
| 159 | - // swap $xl and $xr |
|
| 160 | - $tmp = $xr; |
|
| 161 | - $xr = $xl; |
|
| 162 | - $xl = $tmp; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // swap $xl and $xr after the 16th round to undo the last swap |
|
| 166 | - $tmp = $xl; |
|
| 167 | - $xl = $xr; |
|
| 168 | - $xr = $tmp; |
|
| 169 | - |
|
| 170 | - // XOR the final two elements of $_p |
|
| 171 | - if($this->operation() == parent::ENCRYPT) |
|
| 172 | - { |
|
| 173 | - $xr ^= self::$_p[16]; |
|
| 174 | - $xl = $xl ^ self::$_p[17]; |
|
| 175 | - } |
|
| 176 | - else // parent::DECRYPT |
|
| 177 | - { |
|
| 178 | - $xr ^= self::$_p[1]; |
|
| 179 | - $xl ^= self::$_p[0]; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - // recombine the two halves, force them to be 4 bytes each |
|
| 183 | - $data = parent::dec2Str($xl, 4).parent::dec2Str($xr, 4); |
|
| 184 | - |
|
| 185 | - return true; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Blowfish's F() function |
|
| 191 | - * |
|
| 192 | - * @param string $i A 32 bit integer |
|
| 193 | - */ |
|
| 194 | - private function F($i) |
|
| 195 | - { |
|
| 196 | - // split the 32 bits into four 8 bit parts |
|
| 197 | - $x[0] = $i & 0xff; // first byte |
|
| 198 | - $x[1] = ($i >> 8) & 0xff; // second byte |
|
| 199 | - $x[2] = ($i >> 16) & 0xff; // third byte |
|
| 200 | - $x[3] = ($i >> 24) & 0xff; // fourth byte |
|
| 201 | - |
|
| 202 | - // perform F(), make sure all values returned are |
|
| 203 | - // unsigned 32 bit |
|
| 204 | - $f = parent::uInt32(self::$_sbox1[$x[3]] + self::$_sbox2[$x[2]]); |
|
| 205 | - $f = parent::uInt32($f ^ self::$_sbox3[$x[1]]); |
|
| 206 | - $f = parent::uInt32($f + self::$_sbox4[$x[0]]); |
|
| 207 | - |
|
| 208 | - return $f; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Generates the subkeys used in Blowfish |
|
| 214 | - * |
|
| 215 | - * @return void |
|
| 216 | - */ |
|
| 217 | - private function subKeys() |
|
| 218 | - { |
|
| 219 | - // now xor each element of $_p with 32 bits from the key |
|
| 220 | - for($i = 0; $i < 18; ++$i) |
|
| 221 | - { |
|
| 222 | - $c = $this->keyChunk(4); |
|
| 223 | - self::$_p[$i] ^= parent::str2Dec($c); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - // start with an 8 byte null string |
|
| 227 | - $zero = "\0\0\0\0\0\0\0\0"; |
|
| 228 | - |
|
| 229 | - // now we loop, each loop replacing elements of $_p, or an $_sbox with the |
|
| 230 | - // repeatedly encrypted zero string |
|
| 231 | - for($i = 0; $i < 1042; $i += 2) |
|
| 232 | - { |
|
| 233 | - // encrypt the 64 bit null string |
|
| 234 | - $this->encrypt($zero); |
|
| 235 | - |
|
| 236 | - // split the encrypted null string into two 32 bit parts |
|
| 237 | - $z0 = parent::str2Dec(substr($zero, 0, 4)); |
|
| 238 | - $z1 = parent::str2Dec(substr($zero, 4, 4)); |
|
| 239 | - |
|
| 240 | - // now fill the $_p, $_sbox1, $_sbox2, $_sbox3, $_sbox4 |
|
| 241 | - // with 4 bytes from the repeatedly encrypted 8 byte null string |
|
| 242 | - if($i < 18) |
|
| 243 | - { |
|
| 244 | - self::$_p[$i] = $z0; |
|
| 245 | - self::$_p[$i + 1] = $z1; |
|
| 246 | - } |
|
| 247 | - else if($i >= 18 && $i < 274) |
|
| 248 | - { |
|
| 249 | - self::$_sbox1[$i - 18] = $z0; |
|
| 250 | - self::$_sbox1[$i - 18 + 1] = $z1; |
|
| 251 | - } |
|
| 252 | - else if($i >= 274 && $i < 530) |
|
| 253 | - { |
|
| 254 | - self::$_sbox2[$i - 274] = $z0; |
|
| 255 | - self::$_sbox2[$i - 274 + 1] = $z1; |
|
| 256 | - } |
|
| 257 | - else if($i >= 530 && $i < 786) |
|
| 258 | - { |
|
| 259 | - self::$_sbox3[$i - 530] = $z0; |
|
| 260 | - self::$_sbox3[$i - 530 + 1] = $z1; |
|
| 261 | - } |
|
| 262 | - else if($i >= 786 && $i < 1042) |
|
| 263 | - { |
|
| 264 | - self::$_sbox4[$i -786] = $z0; |
|
| 265 | - self::$_sbox4[$i - 786 + 1] = $z1; |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * Returns a substring of $this->key. The size of the substring is set in the |
|
| 273 | - * parameter $size. Each call to this function returns a substring starting |
|
| 274 | - * in the position where the last substring ended. Effectively it rotates |
|
| 275 | - * through the key, when it reaches the end, it starts over at the |
|
| 276 | - * beginning of the key and continues on. You can reset the current position |
|
| 277 | - * by setting the parameter $reset=true, which will start the key back at the |
|
| 278 | - * first byte of the $this->key string. |
|
| 279 | - * |
|
| 280 | - * @param integer $size The size of the substring to return, in bytes |
|
| 281 | - * @param bool $reset If set to true, sets the position back to 0, the first |
|
| 282 | - * byte of the key string |
|
| 283 | - * @return string The next substring of the key |
|
| 284 | - */ |
|
| 285 | - private function keyChunk($size = 1, $reset = false) |
|
| 286 | - { |
|
| 287 | - if($reset || $this->key_pos >= $this->keySize()) |
|
| 288 | - $this->key_pos = 0; |
|
| 289 | - |
|
| 290 | - $bytes = substr($this->key(), $this->key_pos, $size); |
|
| 291 | - $len = strlen($bytes); |
|
| 292 | - if($len < $size) |
|
| 293 | - { |
|
| 294 | - $bytes .= substr($this->key(), 0, $size - $len); |
|
| 295 | - $this->key_pos = $size - $len; |
|
| 296 | - } |
|
| 297 | - else |
|
| 298 | - $this->key_pos += $size; |
|
| 299 | - |
|
| 300 | - return $bytes; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * Initialize the tables used in Blowfish Encryption. These |
|
| 306 | - * are calculated from the value of PI. We grabbed |
|
| 307 | - * these from the mcrypt blowfish source, which already had |
|
| 308 | - * these values calculated |
|
| 309 | - * |
|
| 310 | - * @return void |
|
| 311 | - */ |
|
| 312 | - private function initTables() |
|
| 313 | - { |
|
| 314 | - self::$_sbox1 = array( |
|
| 315 | - 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, |
|
| 316 | - 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, |
|
| 317 | - 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, |
|
| 318 | - 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, |
|
| 319 | - 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, |
|
| 320 | - 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, |
|
| 321 | - 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, |
|
| 322 | - 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e, |
|
| 323 | - 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, |
|
| 324 | - 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, |
|
| 325 | - 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, |
|
| 326 | - 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a, |
|
| 327 | - 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, |
|
| 328 | - 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677, |
|
| 329 | - 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, |
|
| 330 | - 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, |
|
| 331 | - 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, |
|
| 332 | - 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239, |
|
| 333 | - 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, |
|
| 334 | - 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0, |
|
| 335 | - 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, |
|
| 336 | - 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, |
|
| 337 | - 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, |
|
| 338 | - 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe, |
|
| 339 | - 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, |
|
| 340 | - 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d, |
|
| 341 | - 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, |
|
| 342 | - 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, |
|
| 343 | - 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, |
|
| 344 | - 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463, |
|
| 345 | - 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, |
|
| 346 | - 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09, |
|
| 347 | - 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, |
|
| 348 | - 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, |
|
| 349 | - 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, |
|
| 350 | - 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8, |
|
| 351 | - 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, |
|
| 352 | - 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82, |
|
| 353 | - 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, |
|
| 354 | - 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, |
|
| 355 | - 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, |
|
| 356 | - 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b, |
|
| 357 | - 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, |
|
| 358 | - 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8, |
|
| 359 | - 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, |
|
| 360 | - 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, |
|
| 361 | - 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, |
|
| 362 | - 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c, |
|
| 363 | - 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, |
|
| 364 | - 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1, |
|
| 365 | - 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, |
|
| 366 | - 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, |
|
| 367 | - 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, |
|
| 368 | - 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf, |
|
| 369 | - 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, |
|
| 370 | - 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af, |
|
| 371 | - 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, |
|
| 372 | - 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, |
|
| 373 | - 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, |
|
| 374 | - 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915, |
|
| 375 | - 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, |
|
| 376 | - 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915, |
|
| 377 | - 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, |
|
| 378 | - 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a |
|
| 379 | - ); |
|
| 380 | - |
|
| 381 | - self::$_sbox2 = array( |
|
| 382 | - 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, |
|
| 383 | - 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, |
|
| 384 | - 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, |
|
| 385 | - 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, |
|
| 386 | - 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, |
|
| 387 | - 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1, |
|
| 388 | - 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, |
|
| 389 | - 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1, |
|
| 390 | - 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, |
|
| 391 | - 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8, |
|
| 392 | - 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, |
|
| 393 | - 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd, |
|
| 394 | - 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, |
|
| 395 | - 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7, |
|
| 396 | - 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, |
|
| 397 | - 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, |
|
| 398 | - 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, |
|
| 399 | - 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af, |
|
| 400 | - 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, |
|
| 401 | - 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87, |
|
| 402 | - 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, |
|
| 403 | - 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, |
|
| 404 | - 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, |
|
| 405 | - 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd, |
|
| 406 | - 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, |
|
| 407 | - 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509, |
|
| 408 | - 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, |
|
| 409 | - 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, |
|
| 410 | - 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, |
|
| 411 | - 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a, |
|
| 412 | - 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, |
|
| 413 | - 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960, |
|
| 414 | - 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, |
|
| 415 | - 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28, |
|
| 416 | - 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, |
|
| 417 | - 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84, |
|
| 418 | - 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, |
|
| 419 | - 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf, |
|
| 420 | - 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, |
|
| 421 | - 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e, |
|
| 422 | - 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, |
|
| 423 | - 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7, |
|
| 424 | - 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, |
|
| 425 | - 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281, |
|
| 426 | - 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, |
|
| 427 | - 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, |
|
| 428 | - 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, |
|
| 429 | - 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73, |
|
| 430 | - 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, |
|
| 431 | - 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0, |
|
| 432 | - 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, |
|
| 433 | - 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, |
|
| 434 | - 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, |
|
| 435 | - 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285, |
|
| 436 | - 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, |
|
| 437 | - 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061, |
|
| 438 | - 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, |
|
| 439 | - 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e, |
|
| 440 | - 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, |
|
| 441 | - 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc, |
|
| 442 | - 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, |
|
| 443 | - 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340, |
|
| 444 | - 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, |
|
| 445 | - 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7 |
|
| 446 | - ); |
|
| 447 | - |
|
| 448 | - self::$_sbox3 = array( |
|
| 449 | - 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, |
|
| 450 | - 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, |
|
| 451 | - 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, |
|
| 452 | - 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, |
|
| 453 | - 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, |
|
| 454 | - 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504, |
|
| 455 | - 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, |
|
| 456 | - 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb, |
|
| 457 | - 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, |
|
| 458 | - 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6, |
|
| 459 | - 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, |
|
| 460 | - 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b, |
|
| 461 | - 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, |
|
| 462 | - 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb, |
|
| 463 | - 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, |
|
| 464 | - 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b, |
|
| 465 | - 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, |
|
| 466 | - 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c, |
|
| 467 | - 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, |
|
| 468 | - 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc, |
|
| 469 | - 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, |
|
| 470 | - 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, |
|
| 471 | - 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, |
|
| 472 | - 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115, |
|
| 473 | - 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, |
|
| 474 | - 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728, |
|
| 475 | - 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, |
|
| 476 | - 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, |
|
| 477 | - 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, |
|
| 478 | - 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d, |
|
| 479 | - 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, |
|
| 480 | - 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b, |
|
| 481 | - 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, |
|
| 482 | - 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb, |
|
| 483 | - 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, |
|
| 484 | - 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c, |
|
| 485 | - 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, |
|
| 486 | - 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9, |
|
| 487 | - 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, |
|
| 488 | - 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe, |
|
| 489 | - 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, |
|
| 490 | - 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc, |
|
| 491 | - 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, |
|
| 492 | - 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61, |
|
| 493 | - 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, |
|
| 494 | - 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9, |
|
| 495 | - 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, |
|
| 496 | - 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c, |
|
| 497 | - 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, |
|
| 498 | - 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633, |
|
| 499 | - 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, |
|
| 500 | - 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, |
|
| 501 | - 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, |
|
| 502 | - 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027, |
|
| 503 | - 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, |
|
| 504 | - 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62, |
|
| 505 | - 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, |
|
| 506 | - 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, |
|
| 507 | - 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, |
|
| 508 | - 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc, |
|
| 509 | - 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, |
|
| 510 | - 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c, |
|
| 511 | - 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, |
|
| 512 | - 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0 |
|
| 513 | - ); |
|
| 514 | - |
|
| 515 | - self::$_sbox4 = array( |
|
| 516 | - 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, |
|
| 517 | - 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe, |
|
| 518 | - 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, |
|
| 519 | - 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, |
|
| 520 | - 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, |
|
| 521 | - 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6, |
|
| 522 | - 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, |
|
| 523 | - 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22, |
|
| 524 | - 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, |
|
| 525 | - 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, |
|
| 526 | - 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, |
|
| 527 | - 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59, |
|
| 528 | - 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, |
|
| 529 | - 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51, |
|
| 530 | - 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, |
|
| 531 | - 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, |
|
| 532 | - 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, |
|
| 533 | - 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28, |
|
| 534 | - 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, |
|
| 535 | - 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd, |
|
| 536 | - 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, |
|
| 537 | - 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, |
|
| 538 | - 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, |
|
| 539 | - 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f, |
|
| 540 | - 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, |
|
| 541 | - 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32, |
|
| 542 | - 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, |
|
| 543 | - 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, |
|
| 544 | - 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, |
|
| 545 | - 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb, |
|
| 546 | - 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, |
|
| 547 | - 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47, |
|
| 548 | - 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, |
|
| 549 | - 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, |
|
| 550 | - 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, |
|
| 551 | - 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048, |
|
| 552 | - 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, |
|
| 553 | - 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd, |
|
| 554 | - 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, |
|
| 555 | - 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, |
|
| 556 | - 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, |
|
| 557 | - 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f, |
|
| 558 | - 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, |
|
| 559 | - 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525, |
|
| 560 | - 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, |
|
| 561 | - 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, |
|
| 562 | - 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, |
|
| 563 | - 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e, |
|
| 564 | - 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, |
|
| 565 | - 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d, |
|
| 566 | - 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, |
|
| 567 | - 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, |
|
| 568 | - 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, |
|
| 569 | - 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc, |
|
| 570 | - 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, |
|
| 571 | - 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a, |
|
| 572 | - 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, |
|
| 573 | - 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, |
|
| 574 | - 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, |
|
| 575 | - 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060, |
|
| 576 | - 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, |
|
| 577 | - 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, |
|
| 578 | - 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, |
|
| 579 | - 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6 |
|
| 580 | - ); |
|
| 581 | - |
|
| 582 | - self::$_p = array( |
|
| 583 | - 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, |
|
| 584 | - 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, |
|
| 585 | - 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, |
|
| 586 | - 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, |
|
| 587 | - 0x9216d5d9, 0x8979fb1b |
|
| 588 | - ); |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - |
|
| 592 | - /** |
|
| 593 | - * Indicates this is a block cipher |
|
| 594 | - * |
|
| 595 | - * @return integer Returns Cipher::BLOCK |
|
| 596 | - */ |
|
| 597 | - public function type() |
|
| 598 | - { |
|
| 599 | - return parent::BLOCK; |
|
| 600 | - } |
|
| 66 | + private $key_pos = 0; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Constructor |
|
| 70 | + * |
|
| 71 | + * @param string $key The key used for Encryption/Decryption |
|
| 72 | + * @return void |
|
| 73 | + */ |
|
| 74 | + public function __construct($key) |
|
| 75 | + { |
|
| 76 | + // the max length of the key is 448 bits (56 bytes) |
|
| 77 | + $keylen = strlen($key); |
|
| 78 | + if($keylen > 56) |
|
| 79 | + { |
|
| 80 | + $key = substr($key, 0, 56); |
|
| 81 | + $keylen = 56; |
|
| 82 | + } |
|
| 83 | + else if($keylen < 1) |
|
| 84 | + { |
|
| 85 | + $msg = "No key given. The key must be between 1 - 56 bytes."; |
|
| 86 | + trigger_error($msg, E_USER_WARNING); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + // set the key, make sure the required length is set in bits |
|
| 90 | + parent::__construct(PHP_Crypt::CIPHER_BLOWFISH, $key, $keylen); |
|
| 91 | + |
|
| 92 | + // set the block size |
|
| 93 | + $this->blockSize(self::BYTES_BLOCK); |
|
| 94 | + |
|
| 95 | + $this->initTables(); |
|
| 96 | + $this->subKeys(); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Destructor |
|
| 102 | + * |
|
| 103 | + * @return void |
|
| 104 | + */ |
|
| 105 | + public function __destruct() |
|
| 106 | + { |
|
| 107 | + parent::__destruct(); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Encrypt plain text data |
|
| 113 | + * |
|
| 114 | + * @param string $data A 64 bit (8 byte) plain text string |
|
| 115 | + * @return boolean Returns true |
|
| 116 | + */ |
|
| 117 | + public function encrypt(&$data) |
|
| 118 | + { |
|
| 119 | + $this->operation(parent::ENCRYPT); |
|
| 120 | + return $this->blowfish($data); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Decrypt an encrypted string |
|
| 126 | + * |
|
| 127 | + * @param string $data A 64 bit block of Blowfish encrypted data |
|
| 128 | + * @return boolean Returns true |
|
| 129 | + */ |
|
| 130 | + public function decrypt(&$data) |
|
| 131 | + { |
|
| 132 | + $this->operation(parent::DECRYPT); |
|
| 133 | + return $this->blowfish($data); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * The same alorigthm is used for both Encryption, and Decryption |
|
| 139 | + * |
|
| 140 | + * @param string $data A 64 bit block of data |
|
| 141 | + * @return boolean Returns true |
|
| 142 | + */ |
|
| 143 | + private function blowfish(&$data) |
|
| 144 | + { |
|
| 145 | + // divide the data into into two 32 bit halves |
|
| 146 | + $xl = parent::str2Dec(substr($data, 0, 4)); |
|
| 147 | + $xr = parent::str2Dec(substr($data, 4, 4)); |
|
| 148 | + |
|
| 149 | + for($i = 0; $i < 16; ++$i) |
|
| 150 | + { |
|
| 151 | + if($this->operation() == parent::ENCRYPT) |
|
| 152 | + $xl ^= self::$_p[$i]; |
|
| 153 | + else |
|
| 154 | + $xl ^= self::$_p[17-$i]; |
|
| 155 | + |
|
| 156 | + // perform F() on the left half, and XOR with the right half |
|
| 157 | + $xr = $this->F($xl) ^ $xr; |
|
| 158 | + |
|
| 159 | + // swap $xl and $xr |
|
| 160 | + $tmp = $xr; |
|
| 161 | + $xr = $xl; |
|
| 162 | + $xl = $tmp; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // swap $xl and $xr after the 16th round to undo the last swap |
|
| 166 | + $tmp = $xl; |
|
| 167 | + $xl = $xr; |
|
| 168 | + $xr = $tmp; |
|
| 169 | + |
|
| 170 | + // XOR the final two elements of $_p |
|
| 171 | + if($this->operation() == parent::ENCRYPT) |
|
| 172 | + { |
|
| 173 | + $xr ^= self::$_p[16]; |
|
| 174 | + $xl = $xl ^ self::$_p[17]; |
|
| 175 | + } |
|
| 176 | + else // parent::DECRYPT |
|
| 177 | + { |
|
| 178 | + $xr ^= self::$_p[1]; |
|
| 179 | + $xl ^= self::$_p[0]; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + // recombine the two halves, force them to be 4 bytes each |
|
| 183 | + $data = parent::dec2Str($xl, 4).parent::dec2Str($xr, 4); |
|
| 184 | + |
|
| 185 | + return true; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Blowfish's F() function |
|
| 191 | + * |
|
| 192 | + * @param string $i A 32 bit integer |
|
| 193 | + */ |
|
| 194 | + private function F($i) |
|
| 195 | + { |
|
| 196 | + // split the 32 bits into four 8 bit parts |
|
| 197 | + $x[0] = $i & 0xff; // first byte |
|
| 198 | + $x[1] = ($i >> 8) & 0xff; // second byte |
|
| 199 | + $x[2] = ($i >> 16) & 0xff; // third byte |
|
| 200 | + $x[3] = ($i >> 24) & 0xff; // fourth byte |
|
| 201 | + |
|
| 202 | + // perform F(), make sure all values returned are |
|
| 203 | + // unsigned 32 bit |
|
| 204 | + $f = parent::uInt32(self::$_sbox1[$x[3]] + self::$_sbox2[$x[2]]); |
|
| 205 | + $f = parent::uInt32($f ^ self::$_sbox3[$x[1]]); |
|
| 206 | + $f = parent::uInt32($f + self::$_sbox4[$x[0]]); |
|
| 207 | + |
|
| 208 | + return $f; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Generates the subkeys used in Blowfish |
|
| 214 | + * |
|
| 215 | + * @return void |
|
| 216 | + */ |
|
| 217 | + private function subKeys() |
|
| 218 | + { |
|
| 219 | + // now xor each element of $_p with 32 bits from the key |
|
| 220 | + for($i = 0; $i < 18; ++$i) |
|
| 221 | + { |
|
| 222 | + $c = $this->keyChunk(4); |
|
| 223 | + self::$_p[$i] ^= parent::str2Dec($c); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + // start with an 8 byte null string |
|
| 227 | + $zero = "\0\0\0\0\0\0\0\0"; |
|
| 228 | + |
|
| 229 | + // now we loop, each loop replacing elements of $_p, or an $_sbox with the |
|
| 230 | + // repeatedly encrypted zero string |
|
| 231 | + for($i = 0; $i < 1042; $i += 2) |
|
| 232 | + { |
|
| 233 | + // encrypt the 64 bit null string |
|
| 234 | + $this->encrypt($zero); |
|
| 235 | + |
|
| 236 | + // split the encrypted null string into two 32 bit parts |
|
| 237 | + $z0 = parent::str2Dec(substr($zero, 0, 4)); |
|
| 238 | + $z1 = parent::str2Dec(substr($zero, 4, 4)); |
|
| 239 | + |
|
| 240 | + // now fill the $_p, $_sbox1, $_sbox2, $_sbox3, $_sbox4 |
|
| 241 | + // with 4 bytes from the repeatedly encrypted 8 byte null string |
|
| 242 | + if($i < 18) |
|
| 243 | + { |
|
| 244 | + self::$_p[$i] = $z0; |
|
| 245 | + self::$_p[$i + 1] = $z1; |
|
| 246 | + } |
|
| 247 | + else if($i >= 18 && $i < 274) |
|
| 248 | + { |
|
| 249 | + self::$_sbox1[$i - 18] = $z0; |
|
| 250 | + self::$_sbox1[$i - 18 + 1] = $z1; |
|
| 251 | + } |
|
| 252 | + else if($i >= 274 && $i < 530) |
|
| 253 | + { |
|
| 254 | + self::$_sbox2[$i - 274] = $z0; |
|
| 255 | + self::$_sbox2[$i - 274 + 1] = $z1; |
|
| 256 | + } |
|
| 257 | + else if($i >= 530 && $i < 786) |
|
| 258 | + { |
|
| 259 | + self::$_sbox3[$i - 530] = $z0; |
|
| 260 | + self::$_sbox3[$i - 530 + 1] = $z1; |
|
| 261 | + } |
|
| 262 | + else if($i >= 786 && $i < 1042) |
|
| 263 | + { |
|
| 264 | + self::$_sbox4[$i -786] = $z0; |
|
| 265 | + self::$_sbox4[$i - 786 + 1] = $z1; |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * Returns a substring of $this->key. The size of the substring is set in the |
|
| 273 | + * parameter $size. Each call to this function returns a substring starting |
|
| 274 | + * in the position where the last substring ended. Effectively it rotates |
|
| 275 | + * through the key, when it reaches the end, it starts over at the |
|
| 276 | + * beginning of the key and continues on. You can reset the current position |
|
| 277 | + * by setting the parameter $reset=true, which will start the key back at the |
|
| 278 | + * first byte of the $this->key string. |
|
| 279 | + * |
|
| 280 | + * @param integer $size The size of the substring to return, in bytes |
|
| 281 | + * @param bool $reset If set to true, sets the position back to 0, the first |
|
| 282 | + * byte of the key string |
|
| 283 | + * @return string The next substring of the key |
|
| 284 | + */ |
|
| 285 | + private function keyChunk($size = 1, $reset = false) |
|
| 286 | + { |
|
| 287 | + if($reset || $this->key_pos >= $this->keySize()) |
|
| 288 | + $this->key_pos = 0; |
|
| 289 | + |
|
| 290 | + $bytes = substr($this->key(), $this->key_pos, $size); |
|
| 291 | + $len = strlen($bytes); |
|
| 292 | + if($len < $size) |
|
| 293 | + { |
|
| 294 | + $bytes .= substr($this->key(), 0, $size - $len); |
|
| 295 | + $this->key_pos = $size - $len; |
|
| 296 | + } |
|
| 297 | + else |
|
| 298 | + $this->key_pos += $size; |
|
| 299 | + |
|
| 300 | + return $bytes; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * Initialize the tables used in Blowfish Encryption. These |
|
| 306 | + * are calculated from the value of PI. We grabbed |
|
| 307 | + * these from the mcrypt blowfish source, which already had |
|
| 308 | + * these values calculated |
|
| 309 | + * |
|
| 310 | + * @return void |
|
| 311 | + */ |
|
| 312 | + private function initTables() |
|
| 313 | + { |
|
| 314 | + self::$_sbox1 = array( |
|
| 315 | + 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, |
|
| 316 | + 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, |
|
| 317 | + 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, |
|
| 318 | + 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, |
|
| 319 | + 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, |
|
| 320 | + 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, |
|
| 321 | + 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, |
|
| 322 | + 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e, |
|
| 323 | + 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, |
|
| 324 | + 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, |
|
| 325 | + 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, |
|
| 326 | + 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a, |
|
| 327 | + 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, |
|
| 328 | + 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677, |
|
| 329 | + 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, |
|
| 330 | + 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, |
|
| 331 | + 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, |
|
| 332 | + 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239, |
|
| 333 | + 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, |
|
| 334 | + 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0, |
|
| 335 | + 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, |
|
| 336 | + 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, |
|
| 337 | + 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, |
|
| 338 | + 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe, |
|
| 339 | + 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, |
|
| 340 | + 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d, |
|
| 341 | + 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, |
|
| 342 | + 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, |
|
| 343 | + 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, |
|
| 344 | + 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463, |
|
| 345 | + 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, |
|
| 346 | + 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09, |
|
| 347 | + 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, |
|
| 348 | + 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, |
|
| 349 | + 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, |
|
| 350 | + 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8, |
|
| 351 | + 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, |
|
| 352 | + 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82, |
|
| 353 | + 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, |
|
| 354 | + 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, |
|
| 355 | + 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, |
|
| 356 | + 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b, |
|
| 357 | + 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, |
|
| 358 | + 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8, |
|
| 359 | + 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, |
|
| 360 | + 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, |
|
| 361 | + 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, |
|
| 362 | + 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c, |
|
| 363 | + 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, |
|
| 364 | + 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1, |
|
| 365 | + 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, |
|
| 366 | + 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, |
|
| 367 | + 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, |
|
| 368 | + 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf, |
|
| 369 | + 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, |
|
| 370 | + 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af, |
|
| 371 | + 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, |
|
| 372 | + 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, |
|
| 373 | + 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, |
|
| 374 | + 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915, |
|
| 375 | + 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, |
|
| 376 | + 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915, |
|
| 377 | + 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, |
|
| 378 | + 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a |
|
| 379 | + ); |
|
| 380 | + |
|
| 381 | + self::$_sbox2 = array( |
|
| 382 | + 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, |
|
| 383 | + 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, |
|
| 384 | + 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, |
|
| 385 | + 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, |
|
| 386 | + 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, |
|
| 387 | + 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1, |
|
| 388 | + 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, |
|
| 389 | + 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1, |
|
| 390 | + 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, |
|
| 391 | + 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8, |
|
| 392 | + 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, |
|
| 393 | + 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd, |
|
| 394 | + 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, |
|
| 395 | + 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7, |
|
| 396 | + 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, |
|
| 397 | + 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, |
|
| 398 | + 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, |
|
| 399 | + 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af, |
|
| 400 | + 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, |
|
| 401 | + 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87, |
|
| 402 | + 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, |
|
| 403 | + 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, |
|
| 404 | + 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, |
|
| 405 | + 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd, |
|
| 406 | + 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, |
|
| 407 | + 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509, |
|
| 408 | + 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, |
|
| 409 | + 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, |
|
| 410 | + 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, |
|
| 411 | + 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a, |
|
| 412 | + 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, |
|
| 413 | + 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960, |
|
| 414 | + 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, |
|
| 415 | + 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28, |
|
| 416 | + 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, |
|
| 417 | + 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84, |
|
| 418 | + 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, |
|
| 419 | + 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf, |
|
| 420 | + 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, |
|
| 421 | + 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e, |
|
| 422 | + 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, |
|
| 423 | + 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7, |
|
| 424 | + 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, |
|
| 425 | + 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281, |
|
| 426 | + 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, |
|
| 427 | + 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, |
|
| 428 | + 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, |
|
| 429 | + 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73, |
|
| 430 | + 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, |
|
| 431 | + 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0, |
|
| 432 | + 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, |
|
| 433 | + 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, |
|
| 434 | + 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, |
|
| 435 | + 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285, |
|
| 436 | + 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, |
|
| 437 | + 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061, |
|
| 438 | + 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, |
|
| 439 | + 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e, |
|
| 440 | + 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, |
|
| 441 | + 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc, |
|
| 442 | + 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, |
|
| 443 | + 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340, |
|
| 444 | + 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, |
|
| 445 | + 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7 |
|
| 446 | + ); |
|
| 447 | + |
|
| 448 | + self::$_sbox3 = array( |
|
| 449 | + 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, |
|
| 450 | + 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, |
|
| 451 | + 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, |
|
| 452 | + 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, |
|
| 453 | + 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, |
|
| 454 | + 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504, |
|
| 455 | + 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, |
|
| 456 | + 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb, |
|
| 457 | + 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, |
|
| 458 | + 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6, |
|
| 459 | + 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, |
|
| 460 | + 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b, |
|
| 461 | + 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, |
|
| 462 | + 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb, |
|
| 463 | + 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, |
|
| 464 | + 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b, |
|
| 465 | + 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, |
|
| 466 | + 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c, |
|
| 467 | + 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, |
|
| 468 | + 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc, |
|
| 469 | + 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, |
|
| 470 | + 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, |
|
| 471 | + 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, |
|
| 472 | + 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115, |
|
| 473 | + 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, |
|
| 474 | + 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728, |
|
| 475 | + 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, |
|
| 476 | + 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, |
|
| 477 | + 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, |
|
| 478 | + 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d, |
|
| 479 | + 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, |
|
| 480 | + 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b, |
|
| 481 | + 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, |
|
| 482 | + 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb, |
|
| 483 | + 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, |
|
| 484 | + 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c, |
|
| 485 | + 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, |
|
| 486 | + 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9, |
|
| 487 | + 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, |
|
| 488 | + 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe, |
|
| 489 | + 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, |
|
| 490 | + 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc, |
|
| 491 | + 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, |
|
| 492 | + 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61, |
|
| 493 | + 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, |
|
| 494 | + 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9, |
|
| 495 | + 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, |
|
| 496 | + 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c, |
|
| 497 | + 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, |
|
| 498 | + 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633, |
|
| 499 | + 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, |
|
| 500 | + 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, |
|
| 501 | + 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, |
|
| 502 | + 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027, |
|
| 503 | + 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, |
|
| 504 | + 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62, |
|
| 505 | + 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, |
|
| 506 | + 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, |
|
| 507 | + 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, |
|
| 508 | + 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc, |
|
| 509 | + 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, |
|
| 510 | + 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c, |
|
| 511 | + 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, |
|
| 512 | + 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0 |
|
| 513 | + ); |
|
| 514 | + |
|
| 515 | + self::$_sbox4 = array( |
|
| 516 | + 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, |
|
| 517 | + 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe, |
|
| 518 | + 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, |
|
| 519 | + 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, |
|
| 520 | + 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, |
|
| 521 | + 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6, |
|
| 522 | + 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, |
|
| 523 | + 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22, |
|
| 524 | + 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, |
|
| 525 | + 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, |
|
| 526 | + 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, |
|
| 527 | + 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59, |
|
| 528 | + 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, |
|
| 529 | + 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51, |
|
| 530 | + 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, |
|
| 531 | + 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, |
|
| 532 | + 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, |
|
| 533 | + 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28, |
|
| 534 | + 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, |
|
| 535 | + 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd, |
|
| 536 | + 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, |
|
| 537 | + 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, |
|
| 538 | + 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, |
|
| 539 | + 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f, |
|
| 540 | + 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, |
|
| 541 | + 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32, |
|
| 542 | + 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, |
|
| 543 | + 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, |
|
| 544 | + 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, |
|
| 545 | + 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb, |
|
| 546 | + 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, |
|
| 547 | + 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47, |
|
| 548 | + 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, |
|
| 549 | + 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, |
|
| 550 | + 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, |
|
| 551 | + 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048, |
|
| 552 | + 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, |
|
| 553 | + 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd, |
|
| 554 | + 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, |
|
| 555 | + 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, |
|
| 556 | + 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, |
|
| 557 | + 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f, |
|
| 558 | + 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, |
|
| 559 | + 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525, |
|
| 560 | + 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, |
|
| 561 | + 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, |
|
| 562 | + 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, |
|
| 563 | + 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e, |
|
| 564 | + 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, |
|
| 565 | + 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d, |
|
| 566 | + 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, |
|
| 567 | + 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, |
|
| 568 | + 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, |
|
| 569 | + 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc, |
|
| 570 | + 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, |
|
| 571 | + 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a, |
|
| 572 | + 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, |
|
| 573 | + 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, |
|
| 574 | + 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, |
|
| 575 | + 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060, |
|
| 576 | + 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, |
|
| 577 | + 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, |
|
| 578 | + 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, |
|
| 579 | + 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6 |
|
| 580 | + ); |
|
| 581 | + |
|
| 582 | + self::$_p = array( |
|
| 583 | + 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, |
|
| 584 | + 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, |
|
| 585 | + 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, |
|
| 586 | + 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, |
|
| 587 | + 0x9216d5d9, 0x8979fb1b |
|
| 588 | + ); |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + |
|
| 592 | + /** |
|
| 593 | + * Indicates this is a block cipher |
|
| 594 | + * |
|
| 595 | + * @return integer Returns Cipher::BLOCK |
|
| 596 | + */ |
|
| 597 | + public function type() |
|
| 598 | + { |
|
| 599 | + return parent::BLOCK; |
|
| 600 | + } |
|
| 601 | 601 | } |
| 602 | 602 | ?> |
@@ -38,35 +38,35 @@ |
||
| 38 | 38 | */ |
| 39 | 39 | class Cipher_AES_192 extends Cipher_Rijndael_128 |
| 40 | 40 | { |
| 41 | - /** @type integer BYTES_BLOCK The size of the block, in bytes */ |
|
| 42 | - const BYTES_BLOCK = 16; // 128 bits; |
|
| 41 | + /** @type integer BYTES_BLOCK The size of the block, in bytes */ |
|
| 42 | + const BYTES_BLOCK = 16; // 128 bits; |
|
| 43 | 43 | |
| 44 | - /** @type integer BYTES_KEY The size of the key, in bytes */ |
|
| 45 | - const BYTES_KEY = 24; // 192 bits; |
|
| 44 | + /** @type integer BYTES_KEY The size of the key, in bytes */ |
|
| 45 | + const BYTES_KEY = 24; // 192 bits; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Constructor |
|
| 49 | - * Sets the key used for encryption. |
|
| 50 | - * |
|
| 51 | - * @param string $key string containing the user supplied encryption key |
|
| 52 | - * @return void |
|
| 53 | - */ |
|
| 54 | - public function __construct($key) |
|
| 55 | - { |
|
| 56 | - // Setup AES by calling the second constructor in Rijndael_128 |
|
| 57 | - // The block size is set here too, since all AES implementations use 128 bit blocks |
|
| 58 | - parent::__construct1(PHP_Crypt::CIPHER_AES_192, $key, self::BYTES_KEY); |
|
| 59 | - } |
|
| 47 | + /** |
|
| 48 | + * Constructor |
|
| 49 | + * Sets the key used for encryption. |
|
| 50 | + * |
|
| 51 | + * @param string $key string containing the user supplied encryption key |
|
| 52 | + * @return void |
|
| 53 | + */ |
|
| 54 | + public function __construct($key) |
|
| 55 | + { |
|
| 56 | + // Setup AES by calling the second constructor in Rijndael_128 |
|
| 57 | + // The block size is set here too, since all AES implementations use 128 bit blocks |
|
| 58 | + parent::__construct1(PHP_Crypt::CIPHER_AES_192, $key, self::BYTES_KEY); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Destructor |
|
| 64 | - * |
|
| 65 | - * @return void |
|
| 66 | - */ |
|
| 67 | - public function __destruct() |
|
| 68 | - { |
|
| 69 | - parent::__destruct(); |
|
| 70 | - } |
|
| 62 | + /** |
|
| 63 | + * Destructor |
|
| 64 | + * |
|
| 65 | + * @return void |
|
| 66 | + */ |
|
| 67 | + public function __destruct() |
|
| 68 | + { |
|
| 69 | + parent::__destruct(); |
|
| 70 | + } |
|
| 71 | 71 | } |
| 72 | 72 | ?> |
@@ -38,61 +38,61 @@ |
||
| 38 | 38 | */ |
| 39 | 39 | class Cipher_Rijndael_128 extends Cipher_Rijndael |
| 40 | 40 | { |
| 41 | - /** @type integer BITS_BLOCK The size of the block, in bits */ |
|
| 42 | - const BYTES_BLOCK = 16; |
|
| 41 | + /** @type integer BITS_BLOCK The size of the block, in bits */ |
|
| 42 | + const BYTES_BLOCK = 16; |
|
| 43 | 43 | |
| 44 | - //const BITS_KEY = 0; |
|
| 44 | + //const BITS_KEY = 0; |
|
| 45 | 45 | |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Constructor |
|
| 49 | - * Sets the key used for encryption. Also sets the requied block size |
|
| 50 | - * This should only be used when calling this class directly, for classes |
|
| 51 | - * that extend this class, they should call __construct1() |
|
| 52 | - * |
|
| 53 | - * @param string $key string containing the user supplied encryption key |
|
| 54 | - * @return void |
|
| 55 | - */ |
|
| 56 | - public function __construct($key) |
|
| 57 | - { |
|
| 58 | - // Set up the key |
|
| 59 | - parent::__construct(PHP_Crypt::CIPHER_RIJNDAEL_128, $key); |
|
| 47 | + /** |
|
| 48 | + * Constructor |
|
| 49 | + * Sets the key used for encryption. Also sets the requied block size |
|
| 50 | + * This should only be used when calling this class directly, for classes |
|
| 51 | + * that extend this class, they should call __construct1() |
|
| 52 | + * |
|
| 53 | + * @param string $key string containing the user supplied encryption key |
|
| 54 | + * @return void |
|
| 55 | + */ |
|
| 56 | + public function __construct($key) |
|
| 57 | + { |
|
| 58 | + // Set up the key |
|
| 59 | + parent::__construct(PHP_Crypt::CIPHER_RIJNDAEL_128, $key); |
|
| 60 | 60 | |
| 61 | - // required block size in bits |
|
| 62 | - $this->blockSize(self::BYTES_BLOCK); |
|
| 61 | + // required block size in bits |
|
| 62 | + $this->blockSize(self::BYTES_BLOCK); |
|
| 63 | 63 | |
| 64 | - // expand the key |
|
| 65 | - $this->expandKey(); |
|
| 66 | - } |
|
| 64 | + // expand the key |
|
| 65 | + $this->expandKey(); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Constructor, used only by classes that extend this class |
|
| 71 | - * |
|
| 72 | - * @param string $cipher_name The pre-defined cipher name of the child class |
|
| 73 | - * @param string $key The key used for encryption/decryption |
|
| 74 | - * @param integer $req_key_len The required key length, in bits |
|
| 75 | - * @return void |
|
| 76 | - */ |
|
| 77 | - protected function __construct1($cipher_name, $key, $req_key_len) |
|
| 78 | - { |
|
| 79 | - parent::__construct($cipher_name, $key, $req_key_len); |
|
| 69 | + /** |
|
| 70 | + * Constructor, used only by classes that extend this class |
|
| 71 | + * |
|
| 72 | + * @param string $cipher_name The pre-defined cipher name of the child class |
|
| 73 | + * @param string $key The key used for encryption/decryption |
|
| 74 | + * @param integer $req_key_len The required key length, in bits |
|
| 75 | + * @return void |
|
| 76 | + */ |
|
| 77 | + protected function __construct1($cipher_name, $key, $req_key_len) |
|
| 78 | + { |
|
| 79 | + parent::__construct($cipher_name, $key, $req_key_len); |
|
| 80 | 80 | |
| 81 | - // required block size in bits |
|
| 82 | - $this->blockSize(self::BYTES_BLOCK); |
|
| 81 | + // required block size in bits |
|
| 82 | + $this->blockSize(self::BYTES_BLOCK); |
|
| 83 | 83 | |
| 84 | - // expand the key |
|
| 85 | - $this->expandKey(); |
|
| 86 | - } |
|
| 84 | + // expand the key |
|
| 85 | + $this->expandKey(); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Destructor |
|
| 91 | - * |
|
| 92 | - * @return void |
|
| 93 | - */ |
|
| 94 | - public function __destruct() |
|
| 95 | - { |
|
| 96 | - parent::__destruct(); |
|
| 97 | - } |
|
| 89 | + /** |
|
| 90 | + * Destructor |
|
| 91 | + * |
|
| 92 | + * @return void |
|
| 93 | + */ |
|
| 94 | + public function __destruct() |
|
| 95 | + { |
|
| 96 | + parent::__destruct(); |
|
| 97 | + } |
|
| 98 | 98 | } |
@@ -38,1173 +38,1173 @@ |
||
| 38 | 38 | */ |
| 39 | 39 | class Cipher_CAST_128 extends Cipher |
| 40 | 40 | { |
| 41 | - /** @type integer BYTES_BLOCK The size of the block, in bytes */ |
|
| 42 | - const BYTES_BLOCK = 8; // 64 bits; |
|
| 43 | - |
|
| 44 | - //const BYTES_KEY = 0; // between 40 - 128 bits |
|
| 45 | - |
|
| 46 | - const BYTES_KEY_SMALL = 10; |
|
| 47 | - const BYTES_KEY_MAX = 16; |
|
| 48 | - const BYTES_KEY_MIN = 5; |
|
| 49 | - |
|
| 50 | - /** @type array $_s1 An array of 256 unsigned integers */ |
|
| 51 | - private static $_s1 = array(); |
|
| 52 | - |
|
| 53 | - /** @type array $_s2 An array of 256 unsigned integers */ |
|
| 54 | - private static $_s2 = array(); |
|
| 55 | - |
|
| 56 | - /** @type array $_s3 An array of 256 unsigned integers */ |
|
| 57 | - private static $_s3 = array(); |
|
| 58 | - |
|
| 59 | - /** @type array $_s4 An array of 256 unsigned integers */ |
|
| 60 | - private static $_s4 = array(); |
|
| 61 | - |
|
| 62 | - /** @type array $_s5 An array of 256 unsigned integers */ |
|
| 63 | - private static $_s5 = array(); |
|
| 64 | - |
|
| 65 | - /** @type array $_s6 An array of 256 unsigned integers */ |
|
| 66 | - private static $_s6 = array(); |
|
| 67 | - |
|
| 68 | - /** @type array $_s7 An array of 256 unsigned integers */ |
|
| 69 | - private static $_s7 = array(); |
|
| 70 | - |
|
| 71 | - /** @type array $_s8 An array of 256 unsigned integers */ |
|
| 72 | - private static $_s8 = array(); |
|
| 73 | - |
|
| 74 | - /** @type string $_mkey The 16 byte masking subkey */ |
|
| 75 | - private $_mkey = ""; |
|
| 76 | - |
|
| 77 | - /** @type string $_rkey The 16 byte rotate subkey */ |
|
| 78 | - private $_rkey = ""; |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Constructor |
|
| 83 | - * |
|
| 84 | - * @param string $key The key used for Encryption/Decryption |
|
| 85 | - * @return void |
|
| 86 | - */ |
|
| 87 | - public function __construct($key) |
|
| 88 | - { |
|
| 89 | - // the length of the key is is between 5 - 16 bytes (40 - 128 bits) |
|
| 90 | - $keylen = strlen($key); |
|
| 91 | - if($keylen > self::BYTES_KEY_MAX) |
|
| 92 | - { |
|
| 93 | - $key = substr($key, 0, self::BYTES_KEY_MAX); |
|
| 94 | - $keylen = self::BYTES_KEY_MAX; |
|
| 95 | - } |
|
| 96 | - else if($keylen < self::BYTES_KEY_MIN) |
|
| 97 | - { |
|
| 98 | - $msg = PHP_Crypt::CIPHER_CAST_128." requires a key size between "; |
|
| 99 | - $msg .= "5 - 16 bytes."; |
|
| 100 | - trigger_error($msg, E_USER_WARNING); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - // set the key, make sure the required length is set in bytes |
|
| 104 | - parent::__construct(PHP_Crypt::CIPHER_CAST_128, $key, $keylen); |
|
| 105 | - |
|
| 106 | - // set the block size |
|
| 107 | - $this->blockSize(self::BYTES_BLOCK); |
|
| 108 | - |
|
| 109 | - // initialize the sboxes constants |
|
| 110 | - $this->initTables(); |
|
| 111 | - |
|
| 112 | - // create the sub keys using the sboxes |
|
| 113 | - $this->createSubKeys(); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Destructor |
|
| 119 | - * |
|
| 120 | - * @return void |
|
| 121 | - */ |
|
| 122 | - public function __destruct() |
|
| 123 | - { |
|
| 124 | - parent::__destruct(); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Encrypt plain text data |
|
| 130 | - * |
|
| 131 | - * @param string $data A block of plain data |
|
| 132 | - * @return boolean Returns true |
|
| 133 | - */ |
|
| 134 | - public function encrypt(&$data) |
|
| 135 | - { |
|
| 136 | - $this->operation(parent::ENCRYPT); |
|
| 137 | - |
|
| 138 | - // split the block in half, left and right |
|
| 139 | - $l = parent::str2Dec(substr($data, 0, 4)); |
|
| 140 | - $r = parent::str2Dec(substr($data, 4, 4)); |
|
| 141 | - |
|
| 142 | - // We do only 12 rounds if we have a key 10 bytes or less. |
|
| 143 | - // If we have a key greater than 10 bytes, we do the 12 rounds |
|
| 144 | - // then proceed to the additional 4 rounds for a total of 16 |
|
| 145 | - for($i = 0; $i < 12; $i += 3) |
|
| 146 | - { |
|
| 147 | - // f1 |
|
| 148 | - $tmp = $r; |
|
| 149 | - $r = $l ^ $this->f1($r, $i); |
|
| 150 | - $l = $tmp; |
|
| 151 | - |
|
| 152 | - // f2 |
|
| 153 | - $tmp = $r; |
|
| 154 | - $r = $l ^ $this->f2($r, $i + 1); |
|
| 155 | - $l = $tmp; |
|
| 156 | - |
|
| 157 | - // f3 |
|
| 158 | - $tmp = $r; |
|
| 159 | - $r = $l ^ $this->f3($r, $i + 2); |
|
| 160 | - $l = $tmp; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - // only do the full 16 rounds if the key is longer than |
|
| 164 | - // 10 bytes (80 bits) |
|
| 165 | - if($this->keySize() > self::BYTES_KEY_SMALL) |
|
| 166 | - { |
|
| 167 | - // f1 |
|
| 168 | - $tmp = $r; |
|
| 169 | - $r = $l ^ $this->f1($r, 12); |
|
| 170 | - $l = $tmp; |
|
| 171 | - |
|
| 172 | - // f2 |
|
| 173 | - $tmp = $r; |
|
| 174 | - $r = $l ^ $this->f2($r, 13); |
|
| 175 | - $l = $tmp; |
|
| 176 | - |
|
| 177 | - // f3 |
|
| 178 | - $tmp = $r; |
|
| 179 | - $r = $l ^ $this->f3($r, 14); |
|
| 180 | - $l = $tmp; |
|
| 181 | - |
|
| 182 | - // f1 |
|
| 183 | - $tmp = $r; |
|
| 184 | - $r = $l ^ $this->f1($r, 15); |
|
| 185 | - $l = $tmp; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - // swap the two halfs |
|
| 189 | - $data = parent::dec2Str($r, 4).parent::dec2Str($l, 4); |
|
| 190 | - |
|
| 191 | - return true; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Decrypt an encrypted string, it does all the steps of encryption, |
|
| 197 | - * but in reverse. |
|
| 198 | - * |
|
| 199 | - * @param string $data A block of encrypted data |
|
| 200 | - * @return boolean Returns true |
|
| 201 | - */ |
|
| 202 | - public function decrypt(&$data) |
|
| 203 | - { |
|
| 204 | - $this->operation(parent::DECRYPT); |
|
| 205 | - |
|
| 206 | - // split the block in half, left and right |
|
| 207 | - $l = parent::str2Dec(substr($data, 0, 4)); |
|
| 208 | - $r = parent::str2Dec(substr($data, 4, 4)); |
|
| 209 | - |
|
| 210 | - // only do the full 16 rounds if the key is longer than |
|
| 211 | - // 10 bytes (80 bits) |
|
| 212 | - if($this->keySize() > self::BYTES_KEY_SMALL) |
|
| 213 | - { |
|
| 214 | - // f1 |
|
| 215 | - $tmp = $r; |
|
| 216 | - $r = $l ^ $this->f1($r, 15); |
|
| 217 | - $l = $tmp; |
|
| 218 | - |
|
| 219 | - // f3 |
|
| 220 | - $tmp = $r; |
|
| 221 | - $r = $l ^ $this->f3($r, 14); |
|
| 222 | - $l = $tmp; |
|
| 223 | - |
|
| 224 | - // f2 |
|
| 225 | - $tmp = $r; |
|
| 226 | - $r = $l ^ $this->f2($r, 13); |
|
| 227 | - $l = $tmp; |
|
| 228 | - |
|
| 229 | - // f1 |
|
| 230 | - $tmp = $r; |
|
| 231 | - $r = $l ^ $this->f1($r, 12); |
|
| 232 | - $l = $tmp; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - // We do only 12 rounds if we have a key 10 bytes or less. |
|
| 236 | - for($i = 11; $i >= 2; $i -= 3) |
|
| 237 | - { |
|
| 238 | - // f3 |
|
| 239 | - $tmp = $r; |
|
| 240 | - $r = $l ^ $this->f3($r, $i); |
|
| 241 | - $l = $tmp; |
|
| 242 | - |
|
| 243 | - // f2 |
|
| 244 | - $tmp = $r; |
|
| 245 | - $r = $l ^ $this->f2($r, $i - 1); |
|
| 246 | - $l = $tmp; |
|
| 247 | - |
|
| 248 | - // f1 |
|
| 249 | - $tmp = $r; |
|
| 250 | - $r = $l ^ $this->f1($r, $i - 2); |
|
| 251 | - $l = $tmp; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - // swap the two halfs |
|
| 255 | - $data = parent::dec2Str($r, 4).parent::dec2Str($l, 4); |
|
| 256 | - |
|
| 257 | - return true; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * Cast 128 F1 function |
|
| 263 | - * |
|
| 264 | - * @param $r integer The right half of the data being encrypted in cast_128() |
|
| 265 | - * @param $i integer The round number (1-16) in cast_128() |
|
| 266 | - * @return integer The value after the F1 transformation |
|
| 267 | - */ |
|
| 268 | - private function f1($r, $i) |
|
| 269 | - { |
|
| 270 | - $n = $this->_mkey[$i] + $r; |
|
| 271 | - $n = parent::uInt32(parent::rotBitsLeft32($n, $this->_rkey[$i])); |
|
| 272 | - $n = parent::dec2Str($n, 4); |
|
| 273 | - |
|
| 274 | - $f = parent::uInt32( |
|
| 275 | - ((self::$_s1[ord($n[0])] ^ self::$_s2[ord($n[1])]) - |
|
| 276 | - self::$_s3[ord($n[2])]) + self::$_s4[ord($n[3])] |
|
| 277 | - ); |
|
| 278 | - |
|
| 279 | - return $f; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * Cast 128 F2 function |
|
| 285 | - * |
|
| 286 | - * @param $r integer The right half of the data being encrypted in cast_128() |
|
| 287 | - * @param $i integer The round number (1-16) in cast_128() |
|
| 288 | - * @return integer The value after the F2 transformation |
|
| 289 | - */ |
|
| 290 | - private function f2($r, $i) |
|
| 291 | - { |
|
| 292 | - $n = $this->_mkey[$i] ^ $r; |
|
| 293 | - $n = parent::uInt32(parent::rotBitsLeft32($n, $this->_rkey[$i])); |
|
| 294 | - $n = parent::dec2Str($n, 4); |
|
| 295 | - |
|
| 296 | - $f = parent::uInt32( |
|
| 297 | - ((self::$_s1[ord($n[0])] - self::$_s2[ord($n[1])]) + |
|
| 298 | - self::$_s3[ord($n[2])]) ^ self::$_s4[ord($n[3])] |
|
| 299 | - ); |
|
| 300 | - |
|
| 301 | - return $f; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * Cast 128 F3 function |
|
| 307 | - * |
|
| 308 | - * @param $r integer The right half of the data being encrypted in cast_128() |
|
| 309 | - * @param $i integer The round number (1-16) in cast_128() |
|
| 310 | - * @return integer The value after the F3 transformation |
|
| 311 | - */ |
|
| 312 | - private function f3($r, $i) |
|
| 313 | - { |
|
| 314 | - $n = $this->_mkey[$i] - $r; |
|
| 315 | - $n = parent::uInt32(parent::rotBitsLeft32($n, $this->_rkey[$i])); |
|
| 316 | - $n = parent::dec2Str($n, 4); |
|
| 317 | - |
|
| 318 | - $f = parent::uInt32( |
|
| 319 | - ((self::$_s1[ord($n[0])] + self::$_s2[ord($n[1])]) ^ |
|
| 320 | - self::$_s3[ord($n[2])]) - self::$_s4[ord($n[3])] |
|
| 321 | - ); |
|
| 322 | - |
|
| 323 | - return $f; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * Creates the subkeys $_mkey (the masking key) and |
|
| 329 | - * $_rkey (the rotate key) which are 16 bytes each. These are |
|
| 330 | - * created from the original key. The original key is null |
|
| 331 | - * padded up to 16 bytes and expanded to 32 bytes. It is then |
|
| 332 | - * split in half to create $_mkey and $_rkey |
|
| 333 | - * |
|
| 334 | - * @return void |
|
| 335 | - */ |
|
| 336 | - private function createSubKeys() |
|
| 337 | - { |
|
| 338 | - $x = $this->key(); |
|
| 339 | - $z = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; // init to 16 bytes |
|
| 340 | - $skey = array(); |
|
| 341 | - |
|
| 342 | - // the max length of the key is 16 bytes, however if it is |
|
| 343 | - // less, pad it with null to get ito to 16 bytes |
|
| 344 | - if($this->keySize() < self::BYTES_KEY_MAX) |
|
| 345 | - $x = str_pad($x, self::BYTES_KEY_MAX, "\0", STR_PAD_RIGHT); |
|
| 346 | - |
|
| 347 | - /* |
|
| 41 | + /** @type integer BYTES_BLOCK The size of the block, in bytes */ |
|
| 42 | + const BYTES_BLOCK = 8; // 64 bits; |
|
| 43 | + |
|
| 44 | + //const BYTES_KEY = 0; // between 40 - 128 bits |
|
| 45 | + |
|
| 46 | + const BYTES_KEY_SMALL = 10; |
|
| 47 | + const BYTES_KEY_MAX = 16; |
|
| 48 | + const BYTES_KEY_MIN = 5; |
|
| 49 | + |
|
| 50 | + /** @type array $_s1 An array of 256 unsigned integers */ |
|
| 51 | + private static $_s1 = array(); |
|
| 52 | + |
|
| 53 | + /** @type array $_s2 An array of 256 unsigned integers */ |
|
| 54 | + private static $_s2 = array(); |
|
| 55 | + |
|
| 56 | + /** @type array $_s3 An array of 256 unsigned integers */ |
|
| 57 | + private static $_s3 = array(); |
|
| 58 | + |
|
| 59 | + /** @type array $_s4 An array of 256 unsigned integers */ |
|
| 60 | + private static $_s4 = array(); |
|
| 61 | + |
|
| 62 | + /** @type array $_s5 An array of 256 unsigned integers */ |
|
| 63 | + private static $_s5 = array(); |
|
| 64 | + |
|
| 65 | + /** @type array $_s6 An array of 256 unsigned integers */ |
|
| 66 | + private static $_s6 = array(); |
|
| 67 | + |
|
| 68 | + /** @type array $_s7 An array of 256 unsigned integers */ |
|
| 69 | + private static $_s7 = array(); |
|
| 70 | + |
|
| 71 | + /** @type array $_s8 An array of 256 unsigned integers */ |
|
| 72 | + private static $_s8 = array(); |
|
| 73 | + |
|
| 74 | + /** @type string $_mkey The 16 byte masking subkey */ |
|
| 75 | + private $_mkey = ""; |
|
| 76 | + |
|
| 77 | + /** @type string $_rkey The 16 byte rotate subkey */ |
|
| 78 | + private $_rkey = ""; |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Constructor |
|
| 83 | + * |
|
| 84 | + * @param string $key The key used for Encryption/Decryption |
|
| 85 | + * @return void |
|
| 86 | + */ |
|
| 87 | + public function __construct($key) |
|
| 88 | + { |
|
| 89 | + // the length of the key is is between 5 - 16 bytes (40 - 128 bits) |
|
| 90 | + $keylen = strlen($key); |
|
| 91 | + if($keylen > self::BYTES_KEY_MAX) |
|
| 92 | + { |
|
| 93 | + $key = substr($key, 0, self::BYTES_KEY_MAX); |
|
| 94 | + $keylen = self::BYTES_KEY_MAX; |
|
| 95 | + } |
|
| 96 | + else if($keylen < self::BYTES_KEY_MIN) |
|
| 97 | + { |
|
| 98 | + $msg = PHP_Crypt::CIPHER_CAST_128." requires a key size between "; |
|
| 99 | + $msg .= "5 - 16 bytes."; |
|
| 100 | + trigger_error($msg, E_USER_WARNING); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + // set the key, make sure the required length is set in bytes |
|
| 104 | + parent::__construct(PHP_Crypt::CIPHER_CAST_128, $key, $keylen); |
|
| 105 | + |
|
| 106 | + // set the block size |
|
| 107 | + $this->blockSize(self::BYTES_BLOCK); |
|
| 108 | + |
|
| 109 | + // initialize the sboxes constants |
|
| 110 | + $this->initTables(); |
|
| 111 | + |
|
| 112 | + // create the sub keys using the sboxes |
|
| 113 | + $this->createSubKeys(); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Destructor |
|
| 119 | + * |
|
| 120 | + * @return void |
|
| 121 | + */ |
|
| 122 | + public function __destruct() |
|
| 123 | + { |
|
| 124 | + parent::__destruct(); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Encrypt plain text data |
|
| 130 | + * |
|
| 131 | + * @param string $data A block of plain data |
|
| 132 | + * @return boolean Returns true |
|
| 133 | + */ |
|
| 134 | + public function encrypt(&$data) |
|
| 135 | + { |
|
| 136 | + $this->operation(parent::ENCRYPT); |
|
| 137 | + |
|
| 138 | + // split the block in half, left and right |
|
| 139 | + $l = parent::str2Dec(substr($data, 0, 4)); |
|
| 140 | + $r = parent::str2Dec(substr($data, 4, 4)); |
|
| 141 | + |
|
| 142 | + // We do only 12 rounds if we have a key 10 bytes or less. |
|
| 143 | + // If we have a key greater than 10 bytes, we do the 12 rounds |
|
| 144 | + // then proceed to the additional 4 rounds for a total of 16 |
|
| 145 | + for($i = 0; $i < 12; $i += 3) |
|
| 146 | + { |
|
| 147 | + // f1 |
|
| 148 | + $tmp = $r; |
|
| 149 | + $r = $l ^ $this->f1($r, $i); |
|
| 150 | + $l = $tmp; |
|
| 151 | + |
|
| 152 | + // f2 |
|
| 153 | + $tmp = $r; |
|
| 154 | + $r = $l ^ $this->f2($r, $i + 1); |
|
| 155 | + $l = $tmp; |
|
| 156 | + |
|
| 157 | + // f3 |
|
| 158 | + $tmp = $r; |
|
| 159 | + $r = $l ^ $this->f3($r, $i + 2); |
|
| 160 | + $l = $tmp; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + // only do the full 16 rounds if the key is longer than |
|
| 164 | + // 10 bytes (80 bits) |
|
| 165 | + if($this->keySize() > self::BYTES_KEY_SMALL) |
|
| 166 | + { |
|
| 167 | + // f1 |
|
| 168 | + $tmp = $r; |
|
| 169 | + $r = $l ^ $this->f1($r, 12); |
|
| 170 | + $l = $tmp; |
|
| 171 | + |
|
| 172 | + // f2 |
|
| 173 | + $tmp = $r; |
|
| 174 | + $r = $l ^ $this->f2($r, 13); |
|
| 175 | + $l = $tmp; |
|
| 176 | + |
|
| 177 | + // f3 |
|
| 178 | + $tmp = $r; |
|
| 179 | + $r = $l ^ $this->f3($r, 14); |
|
| 180 | + $l = $tmp; |
|
| 181 | + |
|
| 182 | + // f1 |
|
| 183 | + $tmp = $r; |
|
| 184 | + $r = $l ^ $this->f1($r, 15); |
|
| 185 | + $l = $tmp; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + // swap the two halfs |
|
| 189 | + $data = parent::dec2Str($r, 4).parent::dec2Str($l, 4); |
|
| 190 | + |
|
| 191 | + return true; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Decrypt an encrypted string, it does all the steps of encryption, |
|
| 197 | + * but in reverse. |
|
| 198 | + * |
|
| 199 | + * @param string $data A block of encrypted data |
|
| 200 | + * @return boolean Returns true |
|
| 201 | + */ |
|
| 202 | + public function decrypt(&$data) |
|
| 203 | + { |
|
| 204 | + $this->operation(parent::DECRYPT); |
|
| 205 | + |
|
| 206 | + // split the block in half, left and right |
|
| 207 | + $l = parent::str2Dec(substr($data, 0, 4)); |
|
| 208 | + $r = parent::str2Dec(substr($data, 4, 4)); |
|
| 209 | + |
|
| 210 | + // only do the full 16 rounds if the key is longer than |
|
| 211 | + // 10 bytes (80 bits) |
|
| 212 | + if($this->keySize() > self::BYTES_KEY_SMALL) |
|
| 213 | + { |
|
| 214 | + // f1 |
|
| 215 | + $tmp = $r; |
|
| 216 | + $r = $l ^ $this->f1($r, 15); |
|
| 217 | + $l = $tmp; |
|
| 218 | + |
|
| 219 | + // f3 |
|
| 220 | + $tmp = $r; |
|
| 221 | + $r = $l ^ $this->f3($r, 14); |
|
| 222 | + $l = $tmp; |
|
| 223 | + |
|
| 224 | + // f2 |
|
| 225 | + $tmp = $r; |
|
| 226 | + $r = $l ^ $this->f2($r, 13); |
|
| 227 | + $l = $tmp; |
|
| 228 | + |
|
| 229 | + // f1 |
|
| 230 | + $tmp = $r; |
|
| 231 | + $r = $l ^ $this->f1($r, 12); |
|
| 232 | + $l = $tmp; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + // We do only 12 rounds if we have a key 10 bytes or less. |
|
| 236 | + for($i = 11; $i >= 2; $i -= 3) |
|
| 237 | + { |
|
| 238 | + // f3 |
|
| 239 | + $tmp = $r; |
|
| 240 | + $r = $l ^ $this->f3($r, $i); |
|
| 241 | + $l = $tmp; |
|
| 242 | + |
|
| 243 | + // f2 |
|
| 244 | + $tmp = $r; |
|
| 245 | + $r = $l ^ $this->f2($r, $i - 1); |
|
| 246 | + $l = $tmp; |
|
| 247 | + |
|
| 248 | + // f1 |
|
| 249 | + $tmp = $r; |
|
| 250 | + $r = $l ^ $this->f1($r, $i - 2); |
|
| 251 | + $l = $tmp; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + // swap the two halfs |
|
| 255 | + $data = parent::dec2Str($r, 4).parent::dec2Str($l, 4); |
|
| 256 | + |
|
| 257 | + return true; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Cast 128 F1 function |
|
| 263 | + * |
|
| 264 | + * @param $r integer The right half of the data being encrypted in cast_128() |
|
| 265 | + * @param $i integer The round number (1-16) in cast_128() |
|
| 266 | + * @return integer The value after the F1 transformation |
|
| 267 | + */ |
|
| 268 | + private function f1($r, $i) |
|
| 269 | + { |
|
| 270 | + $n = $this->_mkey[$i] + $r; |
|
| 271 | + $n = parent::uInt32(parent::rotBitsLeft32($n, $this->_rkey[$i])); |
|
| 272 | + $n = parent::dec2Str($n, 4); |
|
| 273 | + |
|
| 274 | + $f = parent::uInt32( |
|
| 275 | + ((self::$_s1[ord($n[0])] ^ self::$_s2[ord($n[1])]) - |
|
| 276 | + self::$_s3[ord($n[2])]) + self::$_s4[ord($n[3])] |
|
| 277 | + ); |
|
| 278 | + |
|
| 279 | + return $f; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * Cast 128 F2 function |
|
| 285 | + * |
|
| 286 | + * @param $r integer The right half of the data being encrypted in cast_128() |
|
| 287 | + * @param $i integer The round number (1-16) in cast_128() |
|
| 288 | + * @return integer The value after the F2 transformation |
|
| 289 | + */ |
|
| 290 | + private function f2($r, $i) |
|
| 291 | + { |
|
| 292 | + $n = $this->_mkey[$i] ^ $r; |
|
| 293 | + $n = parent::uInt32(parent::rotBitsLeft32($n, $this->_rkey[$i])); |
|
| 294 | + $n = parent::dec2Str($n, 4); |
|
| 295 | + |
|
| 296 | + $f = parent::uInt32( |
|
| 297 | + ((self::$_s1[ord($n[0])] - self::$_s2[ord($n[1])]) + |
|
| 298 | + self::$_s3[ord($n[2])]) ^ self::$_s4[ord($n[3])] |
|
| 299 | + ); |
|
| 300 | + |
|
| 301 | + return $f; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * Cast 128 F3 function |
|
| 307 | + * |
|
| 308 | + * @param $r integer The right half of the data being encrypted in cast_128() |
|
| 309 | + * @param $i integer The round number (1-16) in cast_128() |
|
| 310 | + * @return integer The value after the F3 transformation |
|
| 311 | + */ |
|
| 312 | + private function f3($r, $i) |
|
| 313 | + { |
|
| 314 | + $n = $this->_mkey[$i] - $r; |
|
| 315 | + $n = parent::uInt32(parent::rotBitsLeft32($n, $this->_rkey[$i])); |
|
| 316 | + $n = parent::dec2Str($n, 4); |
|
| 317 | + |
|
| 318 | + $f = parent::uInt32( |
|
| 319 | + ((self::$_s1[ord($n[0])] + self::$_s2[ord($n[1])]) ^ |
|
| 320 | + self::$_s3[ord($n[2])]) - self::$_s4[ord($n[3])] |
|
| 321 | + ); |
|
| 322 | + |
|
| 323 | + return $f; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * Creates the subkeys $_mkey (the masking key) and |
|
| 329 | + * $_rkey (the rotate key) which are 16 bytes each. These are |
|
| 330 | + * created from the original key. The original key is null |
|
| 331 | + * padded up to 16 bytes and expanded to 32 bytes. It is then |
|
| 332 | + * split in half to create $_mkey and $_rkey |
|
| 333 | + * |
|
| 334 | + * @return void |
|
| 335 | + */ |
|
| 336 | + private function createSubKeys() |
|
| 337 | + { |
|
| 338 | + $x = $this->key(); |
|
| 339 | + $z = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; // init to 16 bytes |
|
| 340 | + $skey = array(); |
|
| 341 | + |
|
| 342 | + // the max length of the key is 16 bytes, however if it is |
|
| 343 | + // less, pad it with null to get ito to 16 bytes |
|
| 344 | + if($this->keySize() < self::BYTES_KEY_MAX) |
|
| 345 | + $x = str_pad($x, self::BYTES_KEY_MAX, "\0", STR_PAD_RIGHT); |
|
| 346 | + |
|
| 347 | + /* |
|
| 348 | 348 | * NOW FOR THE UGLY PART, THIS IS TAKEN FROM PAGE 3-4 OF |
| 349 | 349 | * http://tools.ietf.org/html/rfc2144 |
| 350 | 350 | */ |
| 351 | 351 | |
| 352 | - // two loops, each loop does 16 bytes for a total of 32 bytes |
|
| 353 | - for($i = 0; $i < 2; ++$i) |
|
| 354 | - { |
|
| 355 | - // z0z1z2z3 = x0x1x2x3 ^ S5[xD] ^ S6[xF] ^ S7[xC] ^ S8[xE] ^ S7[x8] |
|
| 356 | - $tmp = substr($x, 0x00, 4); |
|
| 357 | - $tmp = parent::dec2Str( |
|
| 358 | - parent::uInt32( |
|
| 359 | - parent::str2Dec($tmp) ^ self::$_s5[ord($x[0x0d])] ^ |
|
| 360 | - self::$_s6[ord($x[0x0f])] ^ self::$_s7[ord($x[0x0c])] ^ |
|
| 361 | - self::$_s8[ord($x[0x0e])] ^ self::$_s7[ord($x[0x08])] |
|
| 362 | - ), 4); |
|
| 363 | - $z = substr_replace($z, $tmp, 0x00, 4); |
|
| 364 | - |
|
| 365 | - //print "Z0: ".parent::str2Hex($z)." (".strlen($z).")\n"; |
|
| 366 | - |
|
| 367 | - // z4z5z6z7 = x8x9xAxB ^ S5[z0] ^ S6[z2] ^ S7[z1] ^ S8[z3] ^ S8[xA] |
|
| 368 | - $tmp = substr($x, 0x08, 4); |
|
| 369 | - $tmp = parent::dec2Str( |
|
| 370 | - parent::uInt32( |
|
| 371 | - parent::str2Dec($tmp) ^ self::$_s5[ord($z[0x00])] ^ |
|
| 372 | - self::$_s6[ord($z[0x02])] ^ self::$_s7[ord($z[0x01])] ^ |
|
| 373 | - self::$_s8[ord($z[0x03])] ^ self::$_s8[ord($x[0x0a])] |
|
| 374 | - ), 4); |
|
| 375 | - $z = substr_replace($z, $tmp, 0x04, 4); |
|
| 376 | - |
|
| 377 | - // z8z9zAzB = xCxDxExF ^ S5[z7] ^ S6[z6] ^ S7[z5] ^ S8[z4] ^ S5[x9] |
|
| 378 | - $tmp = substr($x, 0x0c, 4); |
|
| 379 | - $tmp = parent::dec2Str( |
|
| 380 | - parent::uInt32( |
|
| 381 | - parent::str2Dec($tmp) ^ self::$_s5[ord($z[0x07])] ^ |
|
| 382 | - self::$_s6[ord($z[0x06])] ^ self::$_s7[ord($z[0x05])] ^ |
|
| 383 | - self::$_s8[ord($z[0x04])] ^ self::$_s5[ord($x[0x09])] |
|
| 384 | - ), 4); |
|
| 385 | - $z = substr_replace($z, $tmp, 0x08, 4); |
|
| 386 | - |
|
| 387 | - // zCzDzEzF = x4x5x6x7 ^ S5[zA] ^ S6[z9] ^ S7[zB] ^ S8[z8] ^ S6[xB] |
|
| 388 | - $tmp = substr($x, 0x04, 4); |
|
| 389 | - $tmp = parent::dec2Str( |
|
| 390 | - parent::uInt32( |
|
| 391 | - parent::str2Dec($tmp) ^ self::$_s5[ord($z[0x0a])] ^ |
|
| 392 | - self::$_s6[ord($z[0x09])] ^ self::$_s7[ord($z[0x0b])] ^ |
|
| 393 | - self::$_s8[ord($z[0x08])] ^ self::$_s6[ord($x[0x0b])] |
|
| 394 | - ), 4); |
|
| 395 | - $z = substr_replace($z, $tmp, 0x0c, 4); |
|
| 396 | - |
|
| 397 | - //print "Z: ".parent::str2Hex($z)." (".strlen($z).")\n"; |
|
| 398 | - |
|
| 399 | - // K1 = S5[z8] ^ S6[z9] ^ S7[z7] ^ S8[z6] ^ S5[z2] |
|
| 400 | - $skey[] = parent::uInt32(self::$_s5[ord($z[0x08])] ^ self::$_s6[ord($z[0x09])] ^ |
|
| 401 | - self::$_s7[ord($z[0x07])] ^ self::$_s8[ord($z[0x06])] ^ |
|
| 402 | - self::$_s5[ord($z[0x02])] |
|
| 403 | - ); |
|
| 404 | - |
|
| 405 | - // K2 = S5[zA] ^ S6[zB] ^ S7[z5] ^ S8[z4] ^ S6[z6] |
|
| 406 | - $skey[] = parent::uInt32( |
|
| 407 | - self::$_s5[ord($z[0x0a])] ^ self::$_s6[ord($z[0x0b])] ^ |
|
| 408 | - self::$_s7[ord($z[0x05])] ^ self::$_s8[ord($z[0x04])] ^ |
|
| 409 | - self::$_s6[ord($z[0x06])] |
|
| 410 | - ); |
|
| 411 | - |
|
| 412 | - // K3 = S5[zC] ^ S6[zD] ^ S7[z3] ^ S8[z2] ^ S7[z9] |
|
| 413 | - $skey[] = parent::uInt32( |
|
| 414 | - self::$_s5[ord($z[0x0c])] ^ self::$_s6[ord($z[0x0d])] ^ |
|
| 415 | - self::$_s7[ord($z[0x03])] ^ self::$_s8[ord($z[0x02])] ^ |
|
| 416 | - self::$_s7[ord($z[0x09])] |
|
| 417 | - ); |
|
| 418 | - |
|
| 419 | - // K4 = S5[zE] ^ S6[zF] ^ S7[z1] ^ S8[z0] ^ S8[zC] |
|
| 420 | - $skey[] = parent::uInt32( |
|
| 421 | - self::$_s5[ord($z[0x0e])] ^ self::$_s6[ord($z[0x0f])] ^ |
|
| 422 | - self::$_s7[ord($z[0x01])] ^ self::$_s8[ord($z[0x00])] ^ |
|
| 423 | - self::$_s8[ord($z[0x0c])] |
|
| 424 | - ); |
|
| 425 | - |
|
| 426 | - // x0x1x2x3 = z8z9zAzB ^ S5[z5] ^ S6[z7] ^ S7[z4] ^ S8[z6] ^ S7[z0] |
|
| 427 | - $tmp = substr($z, 0x08, 4); |
|
| 428 | - $tmp = parent::dec2Str( |
|
| 429 | - parent::uInt32( |
|
| 430 | - parent::str2Dec($tmp) ^ self::$_s5[ord($z[0x05])] ^ |
|
| 431 | - self::$_s6[ord($z[0x07])] ^ self::$_s7[ord($z[0x04])] ^ |
|
| 432 | - self::$_s8[ord($z[0x06])] ^ self::$_s7[ord($z[0x00])] |
|
| 433 | - ), 4); |
|
| 434 | - $x = substr_replace($x, $tmp, 0x00, 4); |
|
| 435 | - |
|
| 436 | - // x4x5x6x7 = z0z1z2z3 ^ S5[x0] ^ S6[x2] ^ S7[x1] ^ S8[x3] ^ S8[z2] |
|
| 437 | - $tmp = substr($z, 0x00, 4); |
|
| 438 | - $tmp = parent::dec2Str( |
|
| 439 | - parent::uInt32( |
|
| 440 | - parent::str2Dec($tmp) ^ self::$_s5[ord($x[0x00])] ^ |
|
| 441 | - self::$_s6[ord($x[0x02])] ^ self::$_s7[ord($x[0x01])] ^ |
|
| 442 | - self::$_s8[ord($x[0x03])] ^ self::$_s8[ord($z[0x02])] |
|
| 443 | - ), 4); |
|
| 444 | - $x = substr_replace($x, $tmp, 0x04, 4); |
|
| 445 | - |
|
| 446 | - // x8x9xAxB = z4z5z6z7 ^ S5[x7] ^ S6[x6] ^ S7[x5] ^ S8[x4] ^ S5[z1] |
|
| 447 | - $tmp = substr($z, 0x04, 4); |
|
| 448 | - $tmp = parent::dec2Str( |
|
| 449 | - parent::uInt32( |
|
| 450 | - parent::str2Dec($tmp) ^ self::$_s5[ord($x[0x07])] ^ |
|
| 451 | - self::$_s6[ord($x[0x06])] ^ self::$_s7[ord($x[0x05])] ^ |
|
| 452 | - self::$_s8[ord($x[0x04])] ^ self::$_s5[ord($z[0x01])] |
|
| 453 | - ), 4); |
|
| 454 | - $x = substr_replace($x, $tmp, 0x08, 4); |
|
| 455 | - |
|
| 456 | - // xCxDxExF = zCzDzEzF ^ S5[xA] ^ S6[x9] ^ S7[xB] ^ S8[x8] ^ S6[z3] |
|
| 457 | - $tmp = substr($z, 0x0c, 4); |
|
| 458 | - $tmp = parent::dec2Str( |
|
| 459 | - parent::uInt32( |
|
| 460 | - parent::str2Dec($tmp) ^ self::$_s5[ord($x[0x0a])] ^ |
|
| 461 | - self::$_s6[ord($x[0x09])] ^ self::$_s7[ord($x[0x0b])] ^ |
|
| 462 | - self::$_s8[ord($x[0x08])] ^ self::$_s6[ord($z[0x03])] |
|
| 463 | - ), 4); |
|
| 464 | - $x = substr_replace($x, $tmp, 0x0c, 4); |
|
| 465 | - |
|
| 466 | - // K5 = S5[x3] ^ S6[x2] ^ S7[xC] ^ S8[xD] ^ S5[x8] |
|
| 467 | - $skey[] = parent::uInt32( |
|
| 468 | - self::$_s5[ord($x[0x03])] ^ self::$_s6[ord($x[0x02])] ^ |
|
| 469 | - self::$_s7[ord($x[0x0c])] ^ self::$_s8[ord($x[0x0d])] ^ |
|
| 470 | - self::$_s5[ord($x[0x08])] |
|
| 471 | - ); |
|
| 472 | - |
|
| 473 | - // K6 = S5[x1] ^ S6[x0] ^ S7[xE] ^ S8[xF] ^ S6[xD] |
|
| 474 | - $skey[] = parent::uInt32( |
|
| 475 | - self::$_s5[ord($x[0x01])] ^ self::$_s6[ord($x[0x00])] ^ |
|
| 476 | - self::$_s7[ord($x[0x0e])] ^ self::$_s8[ord($x[0x0f])] ^ |
|
| 477 | - self::$_s6[ord($x[0x0d])] |
|
| 478 | - ); |
|
| 479 | - |
|
| 480 | - // K7 = S5[x7] ^ S6[x6] ^ S7[x8] ^ S8[x9] ^ S7[x3] |
|
| 481 | - $skey[] = parent::uInt32( |
|
| 482 | - self::$_s5[ord($x[0x07])] ^ self::$_s6[ord($x[0x06])] ^ |
|
| 483 | - self::$_s7[ord($x[0x08])] ^ self::$_s8[ord($x[0x09])] ^ |
|
| 484 | - self::$_s7[ord($x[0x03])] |
|
| 485 | - ); |
|
| 486 | - |
|
| 487 | - // K8 = S5[x5] ^ S6[x4] ^ S7[xA] ^ S8[xB] ^ S8[x7] |
|
| 488 | - $skey[] = parent::uInt32( |
|
| 489 | - self::$_s5[ord($x[0x05])] ^ self::$_s6[ord($x[0x04])] ^ |
|
| 490 | - self::$_s7[ord($x[0x0a])] ^ self::$_s8[ord($x[0x0b])] ^ |
|
| 491 | - self::$_s8[ord($x[0x07])] |
|
| 492 | - ); |
|
| 493 | - |
|
| 494 | - // z0z1z2z3 = x0x1x2x3 ^ S5[xD] ^ S6[xF] ^ S7[xC] ^ S8[xE] ^ S7[x8] |
|
| 495 | - $tmp = substr($x, 0x00, 4); |
|
| 496 | - $tmp = parent::dec2Str( |
|
| 497 | - parent::uInt32( |
|
| 498 | - parent::str2Dec($tmp) ^ self::$_s5[ord($x[0x0d])] ^ |
|
| 499 | - self::$_s6[ord($x[0x0f])] ^ self::$_s7[ord($x[0x0c])] ^ |
|
| 500 | - self::$_s8[ord($x[0x0e])] ^ self::$_s7[ord($x[0x08])] |
|
| 501 | - ), 4); |
|
| 502 | - $z = substr_replace($z, $tmp, 0x00, 4); |
|
| 503 | - |
|
| 504 | - // z4z5z6z7 = x8x9xAxB ^ S5[z0] ^ S6[z2] ^ S7[z1] ^ S8[z3] ^ S8[xA] |
|
| 505 | - $tmp = substr($x, 0x08, 4); |
|
| 506 | - $tmp = parent::dec2Str( |
|
| 507 | - parent::uInt32( |
|
| 508 | - parent::str2Dec($tmp) ^ self::$_s5[ord($z[0x00])] ^ |
|
| 509 | - self::$_s6[ord($z[0x02])] ^ self::$_s7[ord($z[0x01])] ^ |
|
| 510 | - self::$_s8[ord($z[0x03])] ^ self::$_s8[ord($x[0x0a])] |
|
| 511 | - ), 4); |
|
| 512 | - $z = substr_replace($z, $tmp, 0x04, 4); |
|
| 513 | - |
|
| 514 | - // z8z9zAzB = xCxDxExF ^ S5[z7] ^ S6[z6] ^ S7[z5] ^ S8[z4] ^ S5[x9] |
|
| 515 | - $tmp = substr($x, 0x0c, 4); |
|
| 516 | - $tmp = parent::dec2Str( |
|
| 517 | - parent::uInt32( |
|
| 518 | - parent::str2Dec($tmp) ^ self::$_s5[ord($z[0x07])] ^ |
|
| 519 | - self::$_s6[ord($z[0x06])] ^ self::$_s7[ord($z[0x05])] ^ |
|
| 520 | - self::$_s8[ord($z[0x04])] ^ self::$_s5[ord($x[0x09])] |
|
| 521 | - ), 4); |
|
| 522 | - $z = substr_replace($z, $tmp, 0x08, 4); |
|
| 523 | - |
|
| 524 | - // zCzDzEzF = x4x5x6x7 ^ S5[zA] ^ S6[z9] ^ S7[zB] ^ S8[z8] ^ S6[xB] |
|
| 525 | - $tmp = substr($x, 0x04, 4); |
|
| 526 | - $tmp = parent::dec2Str( |
|
| 527 | - parent::uInt32( |
|
| 528 | - parent::str2Dec($tmp) ^ self::$_s5[ord($z[0x0a])] ^ |
|
| 529 | - self::$_s6[ord($z[0x09])] ^ self::$_s7[ord($z[0x0b])] ^ |
|
| 530 | - self::$_s8[ord($z[0x08])] ^ self::$_s6[ord($x[0x0b])] |
|
| 531 | - ), 4); |
|
| 532 | - $z = substr_replace($z, $tmp, 0x0c, 4); |
|
| 533 | - |
|
| 534 | - // K9 = S5[z3] ^ S6[z2] ^ S7[zC] ^ S8[zD] ^ S5[z9] |
|
| 535 | - $skey[] = parent::uInt32( |
|
| 536 | - self::$_s5[ord($z[0x03])] ^ self::$_s6[ord($z[0x02])] ^ |
|
| 537 | - self::$_s7[ord($z[0x0c])] ^ self::$_s8[ord($z[0x0d])] ^ |
|
| 538 | - self::$_s5[ord($z[0x09])] |
|
| 539 | - ); |
|
| 540 | - |
|
| 541 | - // K10 = S5[z1] ^ S6[z0] ^ S7[zE] ^ S8[zF] ^ S6[zC] |
|
| 542 | - $skey[] = parent::uInt32( |
|
| 543 | - self::$_s5[ord($z[0x01])] ^ self::$_s6[ord($z[0x00])] ^ |
|
| 544 | - self::$_s7[ord($z[0x0e])] ^ self::$_s8[ord($z[0x0f])] ^ |
|
| 545 | - self::$_s6[ord($z[0x0c])] |
|
| 546 | - ); |
|
| 547 | - |
|
| 548 | - // K11 = S5[z7] ^ S6[z6] ^ S7[z8] ^ S8[z9] ^ S7[z2] |
|
| 549 | - $skey[] = parent::uInt32( |
|
| 550 | - self::$_s5[ord($z[0x07])] ^ self::$_s6[ord($z[0x06])] ^ |
|
| 551 | - self::$_s7[ord($z[0x08])] ^ self::$_s8[ord($z[0x09])] ^ |
|
| 552 | - self::$_s7[ord($z[0x02])] |
|
| 553 | - ); |
|
| 554 | - |
|
| 555 | - // K12 = S5[z5] ^ S6[z4] ^ S7[zA] ^ S8[zB] ^ S8[z6] |
|
| 556 | - $skey[] = parent::uInt32( |
|
| 557 | - self::$_s5[ord($z[0x05])] ^ self::$_s6[ord($z[0x04])] ^ |
|
| 558 | - self::$_s7[ord($z[0x0a])] ^ self::$_s8[ord($z[0x0b])] ^ |
|
| 559 | - self::$_s8[ord($z[0x06])] |
|
| 560 | - ); |
|
| 561 | - |
|
| 562 | - // x0x1x2x3 = z8z9zAzB ^ S5[z5] ^ S6[z7] ^ S7[z4] ^ S8[z6] ^ S7[z0] |
|
| 563 | - $tmp = substr($z, 0x08, 4); |
|
| 564 | - $tmp = parent::dec2Str( |
|
| 565 | - parent::uInt32( |
|
| 566 | - parent::str2Dec($tmp) ^ self::$_s5[ord($z[0x05])] ^ |
|
| 567 | - self::$_s6[ord($z[0x07])] ^ self::$_s7[ord($z[0x04])] ^ |
|
| 568 | - self::$_s8[ord($z[0x06])] ^ self::$_s7[ord($z[0x00])] |
|
| 569 | - ), 4); |
|
| 570 | - $x = substr_replace($x, $tmp, 0x00, 4); |
|
| 571 | - |
|
| 572 | - // x4x5x6x7 = z0z1z2z3 ^ S5[x0] ^ S6[x2] ^ S7[x1] ^ S8[x3] ^ S8[z2] |
|
| 573 | - $tmp = substr($z, 0x00, 4); |
|
| 574 | - $tmp = parent::dec2Str( |
|
| 575 | - parent::uInt32( |
|
| 576 | - parent::str2Dec($tmp) ^ self::$_s5[ord($x[0x00])] ^ |
|
| 577 | - self::$_s6[ord($x[0x02])] ^ self::$_s7[ord($x[0x01])] ^ |
|
| 578 | - self::$_s8[ord($x[0x03])] ^ self::$_s8[ord($z[0x02])] |
|
| 579 | - ), 4); |
|
| 580 | - $x = substr_replace($x, $tmp, 0x04, 4); |
|
| 581 | - |
|
| 582 | - // x8x9xAxB = z4z5z6z7 ^ S5[x7] ^ S6[x6] ^ S7[x5] ^ S8[x4] ^ S5[z1] |
|
| 583 | - $tmp = substr($z, 0x04, 4); |
|
| 584 | - $tmp = parent::dec2Str( |
|
| 585 | - parent::uInt32( |
|
| 586 | - parent::str2Dec($tmp) ^ self::$_s5[ord($x[0x07])] ^ |
|
| 587 | - self::$_s6[ord($x[0x06])] ^ self::$_s7[ord($x[0x05])] ^ |
|
| 588 | - self::$_s8[ord($x[0x04])] ^ self::$_s5[ord($z[0x01])] |
|
| 589 | - ), 4); |
|
| 590 | - $x = substr_replace($x, $tmp, 0x08, 4); |
|
| 591 | - |
|
| 592 | - // xCxDxExF = zCzDzEzF ^ S5[xA] ^ S6[x9] ^ S7[xB] ^ S8[x8] ^ S6[z3] |
|
| 593 | - $tmp = substr($z, 0x0c, 4); |
|
| 594 | - $tmp = parent::dec2Str( |
|
| 595 | - parent::uInt32( |
|
| 596 | - parent::str2Dec($tmp) ^ self::$_s5[ord($x[0x0a])] ^ |
|
| 597 | - self::$_s6[ord($x[0x09])] ^ self::$_s7[ord($x[0x0b])] ^ |
|
| 598 | - self::$_s8[ord($x[0x08])] ^ self::$_s6[ord($z[0x03])] |
|
| 599 | - ), 4); |
|
| 600 | - $x = substr_replace($x, $tmp, 0x0c, 4); |
|
| 601 | - |
|
| 602 | - // K13 = S5[x8] ^ S6[x9] ^ S7[x7] ^ S8[x6] ^ S5[x3] |
|
| 603 | - $skey[] = parent::uInt32( |
|
| 604 | - self::$_s5[ord($x[0x08])] ^ self::$_s6[ord($x[0x09])] ^ |
|
| 605 | - self::$_s7[ord($x[0x07])] ^ self::$_s8[ord($x[0x06])] ^ |
|
| 606 | - self::$_s5[ord($x[0x03])] |
|
| 607 | - ); |
|
| 608 | - |
|
| 609 | - // K14 = S5[xA] ^ S6[xB] ^ S7[x5] ^ S8[x4] ^ S6[x7] |
|
| 610 | - $skey[] = parent::uInt32( |
|
| 611 | - self::$_s5[ord($x[0x0a])] ^ self::$_s6[ord($x[0x0b])] ^ |
|
| 612 | - self::$_s7[ord($x[0x05])] ^ self::$_s8[ord($x[0x04])] ^ |
|
| 613 | - self::$_s6[ord($x[0x07])] |
|
| 614 | - ); |
|
| 615 | - |
|
| 616 | - // K15 = S5[xC] ^ S6[xD] ^ S7[x3] ^ S8[x2] ^ S7[x8] |
|
| 617 | - $skey[] = parent::uInt32( |
|
| 618 | - self::$_s5[ord($x[0x0c])] ^ self::$_s6[ord($x[0x0d])] ^ |
|
| 619 | - self::$_s7[ord($x[0x03])] ^ self::$_s8[ord($x[0x02])] ^ |
|
| 620 | - self::$_s7[ord($x[0x08])] |
|
| 621 | - ); |
|
| 622 | - |
|
| 623 | - // K16 = S5[xE] ^ S6[xF] ^ S7[x1] ^ S8[x0] ^ S8[xD] |
|
| 624 | - $skey[] = parent::uInt32( |
|
| 625 | - self::$_s5[ord($x[0x0e])] ^ self::$_s6[ord($x[0x0f])] ^ |
|
| 626 | - self::$_s7[ord($x[0x01])] ^ self::$_s8[ord($x[0x00])] ^ |
|
| 627 | - self::$_s8[ord($x[0x0d])] |
|
| 628 | - ); |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - // create the 16 byte masking and rotate subkeys |
|
| 632 | - $this->_mkey = array_slice($skey, 0, 16); |
|
| 633 | - $this->_rkey = array_slice($skey, 16, 16); |
|
| 634 | - |
|
| 635 | - // $_rkey only uses the least significant 5 bits |
|
| 636 | - $this->_rkey = array_map(function($v) { |
|
| 637 | - return $v &= 31; |
|
| 638 | - }, $this->_rkey); |
|
| 639 | - |
|
| 640 | - // there is 4kb in the s5 - s8 sboxes, which are not needed after we |
|
| 641 | - // create the subkeys, so free up the memory. unset() doesn't work here |
|
| 642 | - for($i = 5; $i <= 8; ++$i) |
|
| 643 | - self::${"_s$i"} = null; |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - |
|
| 647 | - /** |
|
| 648 | - * Initialize the tables. |
|
| 649 | - * |
|
| 650 | - * @return void |
|
| 651 | - */ |
|
| 652 | - private function initTables() |
|
| 653 | - { |
|
| 654 | - // 256 unsigned 32 bit integers |
|
| 655 | - self::$_s1 = array( |
|
| 656 | - 0x30FB40D4, 0x9FA0FF0B, 0x6BECCD2F, 0x3F258C7A, |
|
| 657 | - 0x1E213F2F, 0x9C004DD3, 0x6003E540, 0xCF9FC949, |
|
| 658 | - 0xBFD4AF27, 0x88BBBDB5, 0xE2034090, 0x98D09675, |
|
| 659 | - 0x6E63A0E0, 0x15C361D2, 0xC2E7661D, 0x22D4FF8E, |
|
| 660 | - 0x28683B6F, 0xC07FD059, 0xFF2379C8, 0x775F50E2, |
|
| 661 | - 0x43C340D3, 0xDF2F8656, 0x887CA41A, 0xA2D2BD2D, |
|
| 662 | - 0xA1C9E0D6, 0x346C4819, 0x61B76D87, 0x22540F2F, |
|
| 663 | - 0x2ABE32E1, 0xAA54166B, 0x22568E3A, 0xA2D341D0, |
|
| 664 | - 0x66DB40C8, 0xA784392F, 0x004DFF2F, 0x2DB9D2DE, |
|
| 665 | - 0x97943FAC, 0x4A97C1D8, 0x527644B7, 0xB5F437A7, |
|
| 666 | - 0xB82CBAEF, 0xD751D159, 0x6FF7F0ED, 0x5A097A1F, |
|
| 667 | - 0x827B68D0, 0x90ECF52E, 0x22B0C054, 0xBC8E5935, |
|
| 668 | - 0x4B6D2F7F, 0x50BB64A2, 0xD2664910, 0xBEE5812D, |
|
| 669 | - 0xB7332290, 0xE93B159F, 0xB48EE411, 0x4BFF345D, |
|
| 670 | - 0xFD45C240, 0xAD31973F, 0xC4F6D02E, 0x55FC8165, |
|
| 671 | - 0xD5B1CAAD, 0xA1AC2DAE, 0xA2D4B76D, 0xC19B0C50, |
|
| 672 | - 0x882240F2, 0x0C6E4F38, 0xA4E4BFD7, 0x4F5BA272, |
|
| 673 | - 0x564C1D2F, 0xC59C5319, 0xB949E354, 0xB04669FE, |
|
| 674 | - 0xB1B6AB8A, 0xC71358DD, 0x6385C545, 0x110F935D, |
|
| 675 | - 0x57538AD5, 0x6A390493, 0xE63D37E0, 0x2A54F6B3, |
|
| 676 | - 0x3A787D5F, 0x6276A0B5, 0x19A6FCDF, 0x7A42206A, |
|
| 677 | - 0x29F9D4D5, 0xF61B1891, 0xBB72275E, 0xAA508167, |
|
| 678 | - 0x38901091, 0xC6B505EB, 0x84C7CB8C, 0x2AD75A0F, |
|
| 679 | - 0x874A1427, 0xA2D1936B, 0x2AD286AF, 0xAA56D291, |
|
| 680 | - 0xD7894360, 0x425C750D, 0x93B39E26, 0x187184C9, |
|
| 681 | - 0x6C00B32D, 0x73E2BB14, 0xA0BEBC3C, 0x54623779, |
|
| 682 | - 0x64459EAB, 0x3F328B82, 0x7718CF82, 0x59A2CEA6, |
|
| 683 | - 0x04EE002E, 0x89FE78E6, 0x3FAB0950, 0x325FF6C2, |
|
| 684 | - 0x81383F05, 0x6963C5C8, 0x76CB5AD6, 0xD49974C9, |
|
| 685 | - 0xCA180DCF, 0x380782D5, 0xC7FA5CF6, 0x8AC31511, |
|
| 686 | - 0x35E79E13, 0x47DA91D0, 0xF40F9086, 0xA7E2419E, |
|
| 687 | - 0x31366241, 0x051EF495, 0xAA573B04, 0x4A805D8D, |
|
| 688 | - 0x548300D0, 0x00322A3C, 0xBF64CDDF, 0xBA57A68E, |
|
| 689 | - 0x75C6372B, 0x50AFD341, 0xA7C13275, 0x915A0BF5, |
|
| 690 | - 0x6B54BFAB, 0x2B0B1426, 0xAB4CC9D7, 0x449CCD82, |
|
| 691 | - 0xF7FBF265, 0xAB85C5F3, 0x1B55DB94, 0xAAD4E324, |
|
| 692 | - 0xCFA4BD3F, 0x2DEAA3E2, 0x9E204D02, 0xC8BD25AC, |
|
| 693 | - 0xEADF55B3, 0xD5BD9E98, 0xE31231B2, 0x2AD5AD6C, |
|
| 694 | - 0x954329DE, 0xADBE4528, 0xD8710F69, 0xAA51C90F, |
|
| 695 | - 0xAA786BF6, 0x22513F1E, 0xAA51A79B, 0x2AD344CC, |
|
| 696 | - 0x7B5A41F0, 0xD37CFBAD, 0x1B069505, 0x41ECE491, |
|
| 697 | - 0xB4C332E6, 0x032268D4, 0xC9600ACC, 0xCE387E6D, |
|
| 698 | - 0xBF6BB16C, 0x6A70FB78, 0x0D03D9C9, 0xD4DF39DE, |
|
| 699 | - 0xE01063DA, 0x4736F464, 0x5AD328D8, 0xB347CC96, |
|
| 700 | - 0x75BB0FC3, 0x98511BFB, 0x4FFBCC35, 0xB58BCF6A, |
|
| 701 | - 0xE11F0ABC, 0xBFC5FE4A, 0xA70AEC10, 0xAC39570A, |
|
| 702 | - 0x3F04442F, 0x6188B153, 0xE0397A2E, 0x5727CB79, |
|
| 703 | - 0x9CEB418F, 0x1CACD68D, 0x2AD37C96, 0x0175CB9D, |
|
| 704 | - 0xC69DFF09, 0xC75B65F0, 0xD9DB40D8, 0xEC0E7779, |
|
| 705 | - 0x4744EAD4, 0xB11C3274, 0xDD24CB9E, 0x7E1C54BD, |
|
| 706 | - 0xF01144F9, 0xD2240EB1, 0x9675B3FD, 0xA3AC3755, |
|
| 707 | - 0xD47C27AF, 0x51C85F4D, 0x56907596, 0xA5BB15E6, |
|
| 708 | - 0x580304F0, 0xCA042CF1, 0x011A37EA, 0x8DBFAADB, |
|
| 709 | - 0x35BA3E4A, 0x3526FFA0, 0xC37B4D09, 0xBC306ED9, |
|
| 710 | - 0x98A52666, 0x5648F725, 0xFF5E569D, 0x0CED63D0, |
|
| 711 | - 0x7C63B2CF, 0x700B45E1, 0xD5EA50F1, 0x85A92872, |
|
| 712 | - 0xAF1FBDA7, 0xD4234870, 0xA7870BF3, 0x2D3B4D79, |
|
| 713 | - 0x42E04198, 0x0CD0EDE7, 0x26470DB8, 0xF881814C, |
|
| 714 | - 0x474D6AD7, 0x7C0C5E5C, 0xD1231959, 0x381B7298, |
|
| 715 | - 0xF5D2F4DB, 0xAB838653, 0x6E2F1E23, 0x83719C9E, |
|
| 716 | - 0xBD91E046, 0x9A56456E, 0xDC39200C, 0x20C8C571, |
|
| 717 | - 0x962BDA1C, 0xE1E696FF, 0xB141AB08, 0x7CCA89B9, |
|
| 718 | - 0x1A69E783, 0x02CC4843, 0xA2F7C579, 0x429EF47D, |
|
| 719 | - 0x427B169C, 0x5AC9F049, 0xDD8F0F00, 0x5C8165BF |
|
| 720 | - ); |
|
| 721 | - |
|
| 722 | - // 256 unsigned 32 bit integers |
|
| 723 | - self::$_s2 = array( |
|
| 724 | - 0x1F201094, 0xEF0BA75B, 0x69E3CF7E, 0x393F4380, |
|
| 725 | - 0xFE61CF7A, 0xEEC5207A, 0x55889C94, 0x72FC0651, |
|
| 726 | - 0xADA7EF79, 0x4E1D7235, 0xD55A63CE, 0xDE0436BA, |
|
| 727 | - 0x99C430EF, 0x5F0C0794, 0x18DCDB7D, 0xA1D6EFF3, |
|
| 728 | - 0xA0B52F7B, 0x59E83605, 0xEE15B094, 0xE9FFD909, |
|
| 729 | - 0xDC440086, 0xEF944459, 0xBA83CCB3, 0xE0C3CDFB, |
|
| 730 | - 0xD1DA4181, 0x3B092AB1, 0xF997F1C1, 0xA5E6CF7B, |
|
| 731 | - 0x01420DDB, 0xE4E7EF5B, 0x25A1FF41, 0xE180F806, |
|
| 732 | - 0x1FC41080, 0x179BEE7A, 0xD37AC6A9, 0xFE5830A4, |
|
| 733 | - 0x98DE8B7F, 0x77E83F4E, 0x79929269, 0x24FA9F7B, |
|
| 734 | - 0xE113C85B, 0xACC40083, 0xD7503525, 0xF7EA615F, |
|
| 735 | - 0x62143154, 0x0D554B63, 0x5D681121, 0xC866C359, |
|
| 736 | - 0x3D63CF73, 0xCEE234C0, 0xD4D87E87, 0x5C672B21, |
|
| 737 | - 0x071F6181, 0x39F7627F, 0x361E3084, 0xE4EB573B, |
|
| 738 | - 0x602F64A4, 0xD63ACD9C, 0x1BBC4635, 0x9E81032D, |
|
| 739 | - 0x2701F50C, 0x99847AB4, 0xA0E3DF79, 0xBA6CF38C, |
|
| 740 | - 0x10843094, 0x2537A95E, 0xF46F6FFE, 0xA1FF3B1F, |
|
| 741 | - 0x208CFB6A, 0x8F458C74, 0xD9E0A227, 0x4EC73A34, |
|
| 742 | - 0xFC884F69, 0x3E4DE8DF, 0xEF0E0088, 0x3559648D, |
|
| 743 | - 0x8A45388C, 0x1D804366, 0x721D9BFD, 0xA58684BB, |
|
| 744 | - 0xE8256333, 0x844E8212, 0x128D8098, 0xFED33FB4, |
|
| 745 | - 0xCE280AE1, 0x27E19BA5, 0xD5A6C252, 0xE49754BD, |
|
| 746 | - 0xC5D655DD, 0xEB667064, 0x77840B4D, 0xA1B6A801, |
|
| 747 | - 0x84DB26A9, 0xE0B56714, 0x21F043B7, 0xE5D05860, |
|
| 748 | - 0x54F03084, 0x066FF472, 0xA31AA153, 0xDADC4755, |
|
| 749 | - 0xB5625DBF, 0x68561BE6, 0x83CA6B94, 0x2D6ED23B, |
|
| 750 | - 0xECCF01DB, 0xA6D3D0BA, 0xB6803D5C, 0xAF77A709, |
|
| 751 | - 0x33B4A34C, 0x397BC8D6, 0x5EE22B95, 0x5F0E5304, |
|
| 752 | - 0x81ED6F61, 0x20E74364, 0xB45E1378, 0xDE18639B, |
|
| 753 | - 0x881CA122, 0xB96726D1, 0x8049A7E8, 0x22B7DA7B, |
|
| 754 | - 0x5E552D25, 0x5272D237, 0x79D2951C, 0xC60D894C, |
|
| 755 | - 0x488CB402, 0x1BA4FE5B, 0xA4B09F6B, 0x1CA815CF, |
|
| 756 | - 0xA20C3005, 0x8871DF63, 0xB9DE2FCB, 0x0CC6C9E9, |
|
| 757 | - 0x0BEEFF53, 0xE3214517, 0xB4542835, 0x9F63293C, |
|
| 758 | - 0xEE41E729, 0x6E1D2D7C, 0x50045286, 0x1E6685F3, |
|
| 759 | - 0xF33401C6, 0x30A22C95, 0x31A70850, 0x60930F13, |
|
| 760 | - 0x73F98417, 0xA1269859, 0xEC645C44, 0x52C877A9, |
|
| 761 | - 0xCDFF33A6, 0xA02B1741, 0x7CBAD9A2, 0x2180036F, |
|
| 762 | - 0x50D99C08, 0xCB3F4861, 0xC26BD765, 0x64A3F6AB, |
|
| 763 | - 0x80342676, 0x25A75E7B, 0xE4E6D1FC, 0x20C710E6, |
|
| 764 | - 0xCDF0B680, 0x17844D3B, 0x31EEF84D, 0x7E0824E4, |
|
| 765 | - 0x2CCB49EB, 0x846A3BAE, 0x8FF77888, 0xEE5D60F6, |
|
| 766 | - 0x7AF75673, 0x2FDD5CDB, 0xA11631C1, 0x30F66F43, |
|
| 767 | - 0xB3FAEC54, 0x157FD7FA, 0xEF8579CC, 0xD152DE58, |
|
| 768 | - 0xDB2FFD5E, 0x8F32CE19, 0x306AF97A, 0x02F03EF8, |
|
| 769 | - 0x99319AD5, 0xC242FA0F, 0xA7E3EBB0, 0xC68E4906, |
|
| 770 | - 0xB8DA230C, 0x80823028, 0xDCDEF3C8, 0xD35FB171, |
|
| 771 | - 0x088A1BC8, 0xBEC0C560, 0x61A3C9E8, 0xBCA8F54D, |
|
| 772 | - 0xC72FEFFA, 0x22822E99, 0x82C570B4, 0xD8D94E89, |
|
| 773 | - 0x8B1C34BC, 0x301E16E6, 0x273BE979, 0xB0FFEAA6, |
|
| 774 | - 0x61D9B8C6, 0x00B24869, 0xB7FFCE3F, 0x08DC283B, |
|
| 775 | - 0x43DAF65A, 0xF7E19798, 0x7619B72F, 0x8F1C9BA4, |
|
| 776 | - 0xDC8637A0, 0x16A7D3B1, 0x9FC393B7, 0xA7136EEB, |
|
| 777 | - 0xC6BCC63E, 0x1A513742, 0xEF6828BC, 0x520365D6, |
|
| 778 | - 0x2D6A77AB, 0x3527ED4B, 0x821FD216, 0x095C6E2E, |
|
| 779 | - 0xDB92F2FB, 0x5EEA29CB, 0x145892F5, 0x91584F7F, |
|
| 780 | - 0x5483697B, 0x2667A8CC, 0x85196048, 0x8C4BACEA, |
|
| 781 | - 0x833860D4, 0x0D23E0F9, 0x6C387E8A, 0x0AE6D249, |
|
| 782 | - 0xB284600C, 0xD835731D, 0xDCB1C647, 0xAC4C56EA, |
|
| 783 | - 0x3EBD81B3, 0x230EABB0, 0x6438BC87, 0xF0B5B1FA, |
|
| 784 | - 0x8F5EA2B3, 0xFC184642, 0x0A036B7A, 0x4FB089BD, |
|
| 785 | - 0x649DA589, 0xA345415E, 0x5C038323, 0x3E5D3BB9, |
|
| 786 | - 0x43D79572, 0x7E6DD07C, 0x06DFDF1E, 0x6C6CC4EF, |
|
| 787 | - 0x7160A539, 0x73BFBE70, 0x83877605, 0x4523ECF1 |
|
| 788 | - ); |
|
| 789 | - |
|
| 790 | - // 256 unsigned 32 bit integers |
|
| 791 | - self::$_s3 = array( |
|
| 792 | - 0x8DEFC240, 0x25FA5D9F, 0xEB903DBF, 0xE810C907, |
|
| 793 | - 0x47607FFF, 0x369FE44B, 0x8C1FC644, 0xAECECA90, |
|
| 794 | - 0xBEB1F9BF, 0xEEFBCAEA, 0xE8CF1950, 0x51DF07AE, |
|
| 795 | - 0x920E8806, 0xF0AD0548, 0xE13C8D83, 0x927010D5, |
|
| 796 | - 0x11107D9F, 0x07647DB9, 0xB2E3E4D4, 0x3D4F285E, |
|
| 797 | - 0xB9AFA820, 0xFADE82E0, 0xA067268B, 0x8272792E, |
|
| 798 | - 0x553FB2C0, 0x489AE22B, 0xD4EF9794, 0x125E3FBC, |
|
| 799 | - 0x21FFFCEE, 0x825B1BFD, 0x9255C5ED, 0x1257A240, |
|
| 800 | - 0x4E1A8302, 0xBAE07FFF, 0x528246E7, 0x8E57140E, |
|
| 801 | - 0x3373F7BF, 0x8C9F8188, 0xA6FC4EE8, 0xC982B5A5, |
|
| 802 | - 0xA8C01DB7, 0x579FC264, 0x67094F31, 0xF2BD3F5F, |
|
| 803 | - 0x40FFF7C1, 0x1FB78DFC, 0x8E6BD2C1, 0x437BE59B, |
|
| 804 | - 0x99B03DBF, 0xB5DBC64B, 0x638DC0E6, 0x55819D99, |
|
| 805 | - 0xA197C81C, 0x4A012D6E, 0xC5884A28, 0xCCC36F71, |
|
| 806 | - 0xB843C213, 0x6C0743F1, 0x8309893C, 0x0FEDDD5F, |
|
| 807 | - 0x2F7FE850, 0xD7C07F7E, 0x02507FBF, 0x5AFB9A04, |
|
| 808 | - 0xA747D2D0, 0x1651192E, 0xAF70BF3E, 0x58C31380, |
|
| 809 | - 0x5F98302E, 0x727CC3C4, 0x0A0FB402, 0x0F7FEF82, |
|
| 810 | - 0x8C96FDAD, 0x5D2C2AAE, 0x8EE99A49, 0x50DA88B8, |
|
| 811 | - 0x8427F4A0, 0x1EAC5790, 0x796FB449, 0x8252DC15, |
|
| 812 | - 0xEFBD7D9B, 0xA672597D, 0xADA840D8, 0x45F54504, |
|
| 813 | - 0xFA5D7403, 0xE83EC305, 0x4F91751A, 0x925669C2, |
|
| 814 | - 0x23EFE941, 0xA903F12E, 0x60270DF2, 0x0276E4B6, |
|
| 815 | - 0x94FD6574, 0x927985B2, 0x8276DBCB, 0x02778176, |
|
| 816 | - 0xF8AF918D, 0x4E48F79E, 0x8F616DDF, 0xE29D840E, |
|
| 817 | - 0x842F7D83, 0x340CE5C8, 0x96BBB682, 0x93B4B148, |
|
| 818 | - 0xEF303CAB, 0x984FAF28, 0x779FAF9B, 0x92DC560D, |
|
| 819 | - 0x224D1E20, 0x8437AA88, 0x7D29DC96, 0x2756D3DC, |
|
| 820 | - 0x8B907CEE, 0xB51FD240, 0xE7C07CE3, 0xE566B4A1, |
|
| 821 | - 0xC3E9615E, 0x3CF8209D, 0x6094D1E3, 0xCD9CA341, |
|
| 822 | - 0x5C76460E, 0x00EA983B, 0xD4D67881, 0xFD47572C, |
|
| 823 | - 0xF76CEDD9, 0xBDA8229C, 0x127DADAA, 0x438A074E, |
|
| 824 | - 0x1F97C090, 0x081BDB8A, 0x93A07EBE, 0xB938CA15, |
|
| 825 | - 0x97B03CFF, 0x3DC2C0F8, 0x8D1AB2EC, 0x64380E51, |
|
| 826 | - 0x68CC7BFB, 0xD90F2788, 0x12490181, 0x5DE5FFD4, |
|
| 827 | - 0xDD7EF86A, 0x76A2E214, 0xB9A40368, 0x925D958F, |
|
| 828 | - 0x4B39FFFA, 0xBA39AEE9, 0xA4FFD30B, 0xFAF7933B, |
|
| 829 | - 0x6D498623, 0x193CBCFA, 0x27627545, 0x825CF47A, |
|
| 830 | - 0x61BD8BA0, 0xD11E42D1, 0xCEAD04F4, 0x127EA392, |
|
| 831 | - 0x10428DB7, 0x8272A972, 0x9270C4A8, 0x127DE50B, |
|
| 832 | - 0x285BA1C8, 0x3C62F44F, 0x35C0EAA5, 0xE805D231, |
|
| 833 | - 0x428929FB, 0xB4FCDF82, 0x4FB66A53, 0x0E7DC15B, |
|
| 834 | - 0x1F081FAB, 0x108618AE, 0xFCFD086D, 0xF9FF2889, |
|
| 835 | - 0x694BCC11, 0x236A5CAE, 0x12DECA4D, 0x2C3F8CC5, |
|
| 836 | - 0xD2D02DFE, 0xF8EF5896, 0xE4CF52DA, 0x95155B67, |
|
| 837 | - 0x494A488C, 0xB9B6A80C, 0x5C8F82BC, 0x89D36B45, |
|
| 838 | - 0x3A609437, 0xEC00C9A9, 0x44715253, 0x0A874B49, |
|
| 839 | - 0xD773BC40, 0x7C34671C, 0x02717EF6, 0x4FEB5536, |
|
| 840 | - 0xA2D02FFF, 0xD2BF60C4, 0xD43F03C0, 0x50B4EF6D, |
|
| 841 | - 0x07478CD1, 0x006E1888, 0xA2E53F55, 0xB9E6D4BC, |
|
| 842 | - 0xA2048016, 0x97573833, 0xD7207D67, 0xDE0F8F3D, |
|
| 843 | - 0x72F87B33, 0xABCC4F33, 0x7688C55D, 0x7B00A6B0, |
|
| 844 | - 0x947B0001, 0x570075D2, 0xF9BB88F8, 0x8942019E, |
|
| 845 | - 0x4264A5FF, 0x856302E0, 0x72DBD92B, 0xEE971B69, |
|
| 846 | - 0x6EA22FDE, 0x5F08AE2B, 0xAF7A616D, 0xE5C98767, |
|
| 847 | - 0xCF1FEBD2, 0x61EFC8C2, 0xF1AC2571, 0xCC8239C2, |
|
| 848 | - 0x67214CB8, 0xB1E583D1, 0xB7DC3E62, 0x7F10BDCE, |
|
| 849 | - 0xF90A5C38, 0x0FF0443D, 0x606E6DC6, 0x60543A49, |
|
| 850 | - 0x5727C148, 0x2BE98A1D, 0x8AB41738, 0x20E1BE24, |
|
| 851 | - 0xAF96DA0F, 0x68458425, 0x99833BE5, 0x600D457D, |
|
| 852 | - 0x282F9350, 0x8334B362, 0xD91D1120, 0x2B6D8DA0, |
|
| 853 | - 0x642B1E31, 0x9C305A00, 0x52BCE688, 0x1B03588A, |
|
| 854 | - 0xF7BAEFD5, 0x4142ED9C, 0xA4315C11, 0x83323EC5, |
|
| 855 | - 0xDFEF4636, 0xA133C501, 0xE9D3531C, 0xEE353783 |
|
| 856 | - ); |
|
| 857 | - |
|
| 858 | - // 256 unsigned 32 bit integers |
|
| 859 | - self::$_s4 = array( |
|
| 860 | - 0x9DB30420, 0x1FB6E9DE, 0xA7BE7BEF, 0xD273A298, |
|
| 861 | - 0x4A4F7BDB, 0x64AD8C57, 0x85510443, 0xFA020ED1, |
|
| 862 | - 0x7E287AFF, 0xE60FB663, 0x095F35A1, 0x79EBF120, |
|
| 863 | - 0xFD059D43, 0x6497B7B1, 0xF3641F63, 0x241E4ADF, |
|
| 864 | - 0x28147F5F, 0x4FA2B8CD, 0xC9430040, 0x0CC32220, |
|
| 865 | - 0xFDD30B30, 0xC0A5374F, 0x1D2D00D9, 0x24147B15, |
|
| 866 | - 0xEE4D111A, 0x0FCA5167, 0x71FF904C, 0x2D195FFE, |
|
| 867 | - 0x1A05645F, 0x0C13FEFE, 0x081B08CA, 0x05170121, |
|
| 868 | - 0x80530100, 0xE83E5EFE, 0xAC9AF4F8, 0x7FE72701, |
|
| 869 | - 0xD2B8EE5F, 0x06DF4261, 0xBB9E9B8A, 0x7293EA25, |
|
| 870 | - 0xCE84FFDF, 0xF5718801, 0x3DD64B04, 0xA26F263B, |
|
| 871 | - 0x7ED48400, 0x547EEBE6, 0x446D4CA0, 0x6CF3D6F5, |
|
| 872 | - 0x2649ABDF, 0xAEA0C7F5, 0x36338CC1, 0x503F7E93, |
|
| 873 | - 0xD3772061, 0x11B638E1, 0x72500E03, 0xF80EB2BB, |
|
| 874 | - 0xABE0502E, 0xEC8D77DE, 0x57971E81, 0xE14F6746, |
|
| 875 | - 0xC9335400, 0x6920318F, 0x081DBB99, 0xFFC304A5, |
|
| 876 | - 0x4D351805, 0x7F3D5CE3, 0xA6C866C6, 0x5D5BCCA9, |
|
| 877 | - 0xDAEC6FEA, 0x9F926F91, 0x9F46222F, 0x3991467D, |
|
| 878 | - 0xA5BF6D8E, 0x1143C44F, 0x43958302, 0xD0214EEB, |
|
| 879 | - 0x022083B8, 0x3FB6180C, 0x18F8931E, 0x281658E6, |
|
| 880 | - 0x26486E3E, 0x8BD78A70, 0x7477E4C1, 0xB506E07C, |
|
| 881 | - 0xF32D0A25, 0x79098B02, 0xE4EABB81, 0x28123B23, |
|
| 882 | - 0x69DEAD38, 0x1574CA16, 0xDF871B62, 0x211C40B7, |
|
| 883 | - 0xA51A9EF9, 0x0014377B, 0x041E8AC8, 0x09114003, |
|
| 884 | - 0xBD59E4D2, 0xE3D156D5, 0x4FE876D5, 0x2F91A340, |
|
| 885 | - 0x557BE8DE, 0x00EAE4A7, 0x0CE5C2EC, 0x4DB4BBA6, |
|
| 886 | - 0xE756BDFF, 0xDD3369AC, 0xEC17B035, 0x06572327, |
|
| 887 | - 0x99AFC8B0, 0x56C8C391, 0x6B65811C, 0x5E146119, |
|
| 888 | - 0x6E85CB75, 0xBE07C002, 0xC2325577, 0x893FF4EC, |
|
| 889 | - 0x5BBFC92D, 0xD0EC3B25, 0xB7801AB7, 0x8D6D3B24, |
|
| 890 | - 0x20C763EF, 0xC366A5FC, 0x9C382880, 0x0ACE3205, |
|
| 891 | - 0xAAC9548A, 0xECA1D7C7, 0x041AFA32, 0x1D16625A, |
|
| 892 | - 0x6701902C, 0x9B757A54, 0x31D477F7, 0x9126B031, |
|
| 893 | - 0x36CC6FDB, 0xC70B8B46, 0xD9E66A48, 0x56E55A79, |
|
| 894 | - 0x026A4CEB, 0x52437EFF, 0x2F8F76B4, 0x0DF980A5, |
|
| 895 | - 0x8674CDE3, 0xEDDA04EB, 0x17A9BE04, 0x2C18F4DF, |
|
| 896 | - 0xB7747F9D, 0xAB2AF7B4, 0xEFC34D20, 0x2E096B7C, |
|
| 897 | - 0x1741A254, 0xE5B6A035, 0x213D42F6, 0x2C1C7C26, |
|
| 898 | - 0x61C2F50F, 0x6552DAF9, 0xD2C231F8, 0x25130F69, |
|
| 899 | - 0xD8167FA2, 0x0418F2C8, 0x001A96A6, 0x0D1526AB, |
|
| 900 | - 0x63315C21, 0x5E0A72EC, 0x49BAFEFD, 0x187908D9, |
|
| 901 | - 0x8D0DBD86, 0x311170A7, 0x3E9B640C, 0xCC3E10D7, |
|
| 902 | - 0xD5CAD3B6, 0x0CAEC388, 0xF73001E1, 0x6C728AFF, |
|
| 903 | - 0x71EAE2A1, 0x1F9AF36E, 0xCFCBD12F, 0xC1DE8417, |
|
| 904 | - 0xAC07BE6B, 0xCB44A1D8, 0x8B9B0F56, 0x013988C3, |
|
| 905 | - 0xB1C52FCA, 0xB4BE31CD, 0xD8782806, 0x12A3A4E2, |
|
| 906 | - 0x6F7DE532, 0x58FD7EB6, 0xD01EE900, 0x24ADFFC2, |
|
| 907 | - 0xF4990FC5, 0x9711AAC5, 0x001D7B95, 0x82E5E7D2, |
|
| 908 | - 0x109873F6, 0x00613096, 0xC32D9521, 0xADA121FF, |
|
| 909 | - 0x29908415, 0x7FBB977F, 0xAF9EB3DB, 0x29C9ED2A, |
|
| 910 | - 0x5CE2A465, 0xA730F32C, 0xD0AA3FE8, 0x8A5CC091, |
|
| 911 | - 0xD49E2CE7, 0x0CE454A9, 0xD60ACD86, 0x015F1919, |
|
| 912 | - 0x77079103, 0xDEA03AF6, 0x78A8565E, 0xDEE356DF, |
|
| 913 | - 0x21F05CBE, 0x8B75E387, 0xB3C50651, 0xB8A5C3EF, |
|
| 914 | - 0xD8EEB6D2, 0xE523BE77, 0xC2154529, 0x2F69EFDF, |
|
| 915 | - 0xAFE67AFB, 0xF470C4B2, 0xF3E0EB5B, 0xD6CC9876, |
|
| 916 | - 0x39E4460C, 0x1FDA8538, 0x1987832F, 0xCA007367, |
|
| 917 | - 0xA99144F8, 0x296B299E, 0x492FC295, 0x9266BEAB, |
|
| 918 | - 0xB5676E69, 0x9BD3DDDA, 0xDF7E052F, 0xDB25701C, |
|
| 919 | - 0x1B5E51EE, 0xF65324E6, 0x6AFCE36C, 0x0316CC04, |
|
| 920 | - 0x8644213E, 0xB7DC59D0, 0x7965291F, 0xCCD6FD43, |
|
| 921 | - 0x41823979, 0x932BCDF6, 0xB657C34D, 0x4EDFD282, |
|
| 922 | - 0x7AE5290C, 0x3CB9536B, 0x851E20FE, 0x9833557E, |
|
| 923 | - 0x13ECF0B0, 0xD3FFB372, 0x3F85C5C1, 0x0AEF7ED2 |
|
| 924 | - ); |
|
| 925 | - |
|
| 926 | - // 256 unsigned 32 bit integers |
|
| 927 | - self::$_s5 = array( |
|
| 928 | - 0x7EC90C04, 0x2C6E74B9, 0x9B0E66DF, 0xA6337911, |
|
| 929 | - 0xB86A7FFF, 0x1DD358F5, 0x44DD9D44, 0x1731167F, |
|
| 930 | - 0x08FBF1FA, 0xE7F511CC, 0xD2051B00, 0x735ABA00, |
|
| 931 | - 0x2AB722D8, 0x386381CB, 0xACF6243A, 0x69BEFD7A, |
|
| 932 | - 0xE6A2E77F, 0xF0C720CD, 0xC4494816, 0xCCF5C180, |
|
| 933 | - 0x38851640, 0x15B0A848, 0xE68B18CB, 0x4CAADEFF, |
|
| 934 | - 0x5F480A01, 0x0412B2AA, 0x259814FC, 0x41D0EFE2, |
|
| 935 | - 0x4E40B48D, 0x248EB6FB, 0x8DBA1CFE, 0x41A99B02, |
|
| 936 | - 0x1A550A04, 0xBA8F65CB, 0x7251F4E7, 0x95A51725, |
|
| 937 | - 0xC106ECD7, 0x97A5980A, 0xC539B9AA, 0x4D79FE6A, |
|
| 938 | - 0xF2F3F763, 0x68AF8040, 0xED0C9E56, 0x11B4958B, |
|
| 939 | - 0xE1EB5A88, 0x8709E6B0, 0xD7E07156, 0x4E29FEA7, |
|
| 940 | - 0x6366E52D, 0x02D1C000, 0xC4AC8E05, 0x9377F571, |
|
| 941 | - 0x0C05372A, 0x578535F2, 0x2261BE02, 0xD642A0C9, |
|
| 942 | - 0xDF13A280, 0x74B55BD2, 0x682199C0, 0xD421E5EC, |
|
| 943 | - 0x53FB3CE8, 0xC8ADEDB3, 0x28A87FC9, 0x3D959981, |
|
| 944 | - 0x5C1FF900, 0xFE38D399, 0x0C4EFF0B, 0x062407EA, |
|
| 945 | - 0xAA2F4FB1, 0x4FB96976, 0x90C79505, 0xB0A8A774, |
|
| 946 | - 0xEF55A1FF, 0xE59CA2C2, 0xA6B62D27, 0xE66A4263, |
|
| 947 | - 0xDF65001F, 0x0EC50966, 0xDFDD55BC, 0x29DE0655, |
|
| 948 | - 0x911E739A, 0x17AF8975, 0x32C7911C, 0x89F89468, |
|
| 949 | - 0x0D01E980, 0x524755F4, 0x03B63CC9, 0x0CC844B2, |
|
| 950 | - 0xBCF3F0AA, 0x87AC36E9, 0xE53A7426, 0x01B3D82B, |
|
| 951 | - 0x1A9E7449, 0x64EE2D7E, 0xCDDBB1DA, 0x01C94910, |
|
| 952 | - 0xB868BF80, 0x0D26F3FD, 0x9342EDE7, 0x04A5C284, |
|
| 953 | - 0x636737B6, 0x50F5B616, 0xF24766E3, 0x8ECA36C1, |
|
| 954 | - 0x136E05DB, 0xFEF18391, 0xFB887A37, 0xD6E7F7D4, |
|
| 955 | - 0xC7FB7DC9, 0x3063FCDF, 0xB6F589DE, 0xEC2941DA, |
|
| 956 | - 0x26E46695, 0xB7566419, 0xF654EFC5, 0xD08D58B7, |
|
| 957 | - 0x48925401, 0xC1BACB7F, 0xE5FF550F, 0xB6083049, |
|
| 958 | - 0x5BB5D0E8, 0x87D72E5A, 0xAB6A6EE1, 0x223A66CE, |
|
| 959 | - 0xC62BF3CD, 0x9E0885F9, 0x68CB3E47, 0x086C010F, |
|
| 960 | - 0xA21DE820, 0xD18B69DE, 0xF3F65777, 0xFA02C3F6, |
|
| 961 | - 0x407EDAC3, 0xCBB3D550, 0x1793084D, 0xB0D70EBA, |
|
| 962 | - 0x0AB378D5, 0xD951FB0C, 0xDED7DA56, 0x4124BBE4, |
|
| 963 | - 0x94CA0B56, 0x0F5755D1, 0xE0E1E56E, 0x6184B5BE, |
|
| 964 | - 0x580A249F, 0x94F74BC0, 0xE327888E, 0x9F7B5561, |
|
| 965 | - 0xC3DC0280, 0x05687715, 0x646C6BD7, 0x44904DB3, |
|
| 966 | - 0x66B4F0A3, 0xC0F1648A, 0x697ED5AF, 0x49E92FF6, |
|
| 967 | - 0x309E374F, 0x2CB6356A, 0x85808573, 0x4991F840, |
|
| 968 | - 0x76F0AE02, 0x083BE84D, 0x28421C9A, 0x44489406, |
|
| 969 | - 0x736E4CB8, 0xC1092910, 0x8BC95FC6, 0x7D869CF4, |
|
| 970 | - 0x134F616F, 0x2E77118D, 0xB31B2BE1, 0xAA90B472, |
|
| 971 | - 0x3CA5D717, 0x7D161BBA, 0x9CAD9010, 0xAF462BA2, |
|
| 972 | - 0x9FE459D2, 0x45D34559, 0xD9F2DA13, 0xDBC65487, |
|
| 973 | - 0xF3E4F94E, 0x176D486F, 0x097C13EA, 0x631DA5C7, |
|
| 974 | - 0x445F7382, 0x175683F4, 0xCDC66A97, 0x70BE0288, |
|
| 975 | - 0xB3CDCF72, 0x6E5DD2F3, 0x20936079, 0x459B80A5, |
|
| 976 | - 0xBE60E2DB, 0xA9C23101, 0xEBA5315C, 0x224E42F2, |
|
| 977 | - 0x1C5C1572, 0xF6721B2C, 0x1AD2FFF3, 0x8C25404E, |
|
| 978 | - 0x324ED72F, 0x4067B7FD, 0x0523138E, 0x5CA3BC78, |
|
| 979 | - 0xDC0FD66E, 0x75922283, 0x784D6B17, 0x58EBB16E, |
|
| 980 | - 0x44094F85, 0x3F481D87, 0xFCFEAE7B, 0x77B5FF76, |
|
| 981 | - 0x8C2302BF, 0xAAF47556, 0x5F46B02A, 0x2B092801, |
|
| 982 | - 0x3D38F5F7, 0x0CA81F36, 0x52AF4A8A, 0x66D5E7C0, |
|
| 983 | - 0xDF3B0874, 0x95055110, 0x1B5AD7A8, 0xF61ED5AD, |
|
| 984 | - 0x6CF6E479, 0x20758184, 0xD0CEFA65, 0x88F7BE58, |
|
| 985 | - 0x4A046826, 0x0FF6F8F3, 0xA09C7F70, 0x5346ABA0, |
|
| 986 | - 0x5CE96C28, 0xE176EDA3, 0x6BAC307F, 0x376829D2, |
|
| 987 | - 0x85360FA9, 0x17E3FE2A, 0x24B79767, 0xF5A96B20, |
|
| 988 | - 0xD6CD2595, 0x68FF1EBF, 0x7555442C, 0xF19F06BE, |
|
| 989 | - 0xF9E0659A, 0xEEB9491D, 0x34010718, 0xBB30CAB8, |
|
| 990 | - 0xE822FE15, 0x88570983, 0x750E6249, 0xDA627E55, |
|
| 991 | - 0x5E76FFA8, 0xB1534546, 0x6D47DE08, 0xEFE9E7D4 |
|
| 992 | - ); |
|
| 993 | - |
|
| 994 | - // 256 unsigned 32 bit integers |
|
| 995 | - self::$_s6 = array( |
|
| 996 | - 0xF6FA8F9D, 0x2CAC6CE1, 0x4CA34867, 0xE2337F7C, |
|
| 997 | - 0x95DB08E7, 0x016843B4, 0xECED5CBC, 0x325553AC, |
|
| 998 | - 0xBF9F0960, 0xDFA1E2ED, 0x83F0579D, 0x63ED86B9, |
|
| 999 | - 0x1AB6A6B8, 0xDE5EBE39, 0xF38FF732, 0x8989B138, |
|
| 1000 | - 0x33F14961, 0xC01937BD, 0xF506C6DA, 0xE4625E7E, |
|
| 1001 | - 0xA308EA99, 0x4E23E33C, 0x79CBD7CC, 0x48A14367, |
|
| 1002 | - 0xA3149619, 0xFEC94BD5, 0xA114174A, 0xEAA01866, |
|
| 1003 | - 0xA084DB2D, 0x09A8486F, 0xA888614A, 0x2900AF98, |
|
| 1004 | - 0x01665991, 0xE1992863, 0xC8F30C60, 0x2E78EF3C, |
|
| 1005 | - 0xD0D51932, 0xCF0FEC14, 0xF7CA07D2, 0xD0A82072, |
|
| 1006 | - 0xFD41197E, 0x9305A6B0, 0xE86BE3DA, 0x74BED3CD, |
|
| 1007 | - 0x372DA53C, 0x4C7F4448, 0xDAB5D440, 0x6DBA0EC3, |
|
| 1008 | - 0x083919A7, 0x9FBAEED9, 0x49DBCFB0, 0x4E670C53, |
|
| 1009 | - 0x5C3D9C01, 0x64BDB941, 0x2C0E636A, 0xBA7DD9CD, |
|
| 1010 | - 0xEA6F7388, 0xE70BC762, 0x35F29ADB, 0x5C4CDD8D, |
|
| 1011 | - 0xF0D48D8C, 0xB88153E2, 0x08A19866, 0x1AE2EAC8, |
|
| 1012 | - 0x284CAF89, 0xAA928223, 0x9334BE53, 0x3B3A21BF, |
|
| 1013 | - 0x16434BE3, 0x9AEA3906, 0xEFE8C36E, 0xF890CDD9, |
|
| 1014 | - 0x80226DAE, 0xC340A4A3, 0xDF7E9C09, 0xA694A807, |
|
| 1015 | - 0x5B7C5ECC, 0x221DB3A6, 0x9A69A02F, 0x68818A54, |
|
| 1016 | - 0xCEB2296F, 0x53C0843A, 0xFE893655, 0x25BFE68A, |
|
| 1017 | - 0xB4628ABC, 0xCF222EBF, 0x25AC6F48, 0xA9A99387, |
|
| 1018 | - 0x53BDDB65, 0xE76FFBE7, 0xE967FD78, 0x0BA93563, |
|
| 1019 | - 0x8E342BC1, 0xE8A11BE9, 0x4980740D, 0xC8087DFC, |
|
| 1020 | - 0x8DE4BF99, 0xA11101A0, 0x7FD37975, 0xDA5A26C0, |
|
| 1021 | - 0xE81F994F, 0x9528CD89, 0xFD339FED, 0xB87834BF, |
|
| 1022 | - 0x5F04456D, 0x22258698, 0xC9C4C83B, 0x2DC156BE, |
|
| 1023 | - 0x4F628DAA, 0x57F55EC5, 0xE2220ABE, 0xD2916EBF, |
|
| 1024 | - 0x4EC75B95, 0x24F2C3C0, 0x42D15D99, 0xCD0D7FA0, |
|
| 1025 | - 0x7B6E27FF, 0xA8DC8AF0, 0x7345C106, 0xF41E232F, |
|
| 1026 | - 0x35162386, 0xE6EA8926, 0x3333B094, 0x157EC6F2, |
|
| 1027 | - 0x372B74AF, 0x692573E4, 0xE9A9D848, 0xF3160289, |
|
| 1028 | - 0x3A62EF1D, 0xA787E238, 0xF3A5F676, 0x74364853, |
|
| 1029 | - 0x20951063, 0x4576698D, 0xB6FAD407, 0x592AF950, |
|
| 1030 | - 0x36F73523, 0x4CFB6E87, 0x7DA4CEC0, 0x6C152DAA, |
|
| 1031 | - 0xCB0396A8, 0xC50DFE5D, 0xFCD707AB, 0x0921C42F, |
|
| 1032 | - 0x89DFF0BB, 0x5FE2BE78, 0x448F4F33, 0x754613C9, |
|
| 1033 | - 0x2B05D08D, 0x48B9D585, 0xDC049441, 0xC8098F9B, |
|
| 1034 | - 0x7DEDE786, 0xC39A3373, 0x42410005, 0x6A091751, |
|
| 1035 | - 0x0EF3C8A6, 0x890072D6, 0x28207682, 0xA9A9F7BE, |
|
| 1036 | - 0xBF32679D, 0xD45B5B75, 0xB353FD00, 0xCBB0E358, |
|
| 1037 | - 0x830F220A, 0x1F8FB214, 0xD372CF08, 0xCC3C4A13, |
|
| 1038 | - 0x8CF63166, 0x061C87BE, 0x88C98F88, 0x6062E397, |
|
| 1039 | - 0x47CF8E7A, 0xB6C85283, 0x3CC2ACFB, 0x3FC06976, |
|
| 1040 | - 0x4E8F0252, 0x64D8314D, 0xDA3870E3, 0x1E665459, |
|
| 1041 | - 0xC10908F0, 0x513021A5, 0x6C5B68B7, 0x822F8AA0, |
|
| 1042 | - 0x3007CD3E, 0x74719EEF, 0xDC872681, 0x073340D4, |
|
| 1043 | - 0x7E432FD9, 0x0C5EC241, 0x8809286C, 0xF592D891, |
|
| 1044 | - 0x08A930F6, 0x957EF305, 0xB7FBFFBD, 0xC266E96F, |
|
| 1045 | - 0x6FE4AC98, 0xB173ECC0, 0xBC60B42A, 0x953498DA, |
|
| 1046 | - 0xFBA1AE12, 0x2D4BD736, 0x0F25FAAB, 0xA4F3FCEB, |
|
| 1047 | - 0xE2969123, 0x257F0C3D, 0x9348AF49, 0x361400BC, |
|
| 1048 | - 0xE8816F4A, 0x3814F200, 0xA3F94043, 0x9C7A54C2, |
|
| 1049 | - 0xBC704F57, 0xDA41E7F9, 0xC25AD33A, 0x54F4A084, |
|
| 1050 | - 0xB17F5505, 0x59357CBE, 0xEDBD15C8, 0x7F97C5AB, |
|
| 1051 | - 0xBA5AC7B5, 0xB6F6DEAF, 0x3A479C3A, 0x5302DA25, |
|
| 1052 | - 0x653D7E6A, 0x54268D49, 0x51A477EA, 0x5017D55B, |
|
| 1053 | - 0xD7D25D88, 0x44136C76, 0x0404A8C8, 0xB8E5A121, |
|
| 1054 | - 0xB81A928A, 0x60ED5869, 0x97C55B96, 0xEAEC991B, |
|
| 1055 | - 0x29935913, 0x01FDB7F1, 0x088E8DFA, 0x9AB6F6F5, |
|
| 1056 | - 0x3B4CBF9F, 0x4A5DE3AB, 0xE6051D35, 0xA0E1D855, |
|
| 1057 | - 0xD36B4CF1, 0xF544EDEB, 0xB0E93524, 0xBEBB8FBD, |
|
| 1058 | - 0xA2D762CF, 0x49C92F54, 0x38B5F331, 0x7128A454, |
|
| 1059 | - 0x48392905, 0xA65B1DB8, 0x851C97BD, 0xD675CF2F |
|
| 1060 | - ); |
|
| 1061 | - |
|
| 1062 | - // 256 unsigned 32 bit integers |
|
| 1063 | - self::$_s7 = array( |
|
| 1064 | - 0x85E04019, 0x332BF567, 0x662DBFFF, 0xCFC65693, |
|
| 1065 | - 0x2A8D7F6F, 0xAB9BC912, 0xDE6008A1, 0x2028DA1F, |
|
| 1066 | - 0x0227BCE7, 0x4D642916, 0x18FAC300, 0x50F18B82, |
|
| 1067 | - 0x2CB2CB11, 0xB232E75C, 0x4B3695F2, 0xB28707DE, |
|
| 1068 | - 0xA05FBCF6, 0xCD4181E9, 0xE150210C, 0xE24EF1BD, |
|
| 1069 | - 0xB168C381, 0xFDE4E789, 0x5C79B0D8, 0x1E8BFD43, |
|
| 1070 | - 0x4D495001, 0x38BE4341, 0x913CEE1D, 0x92A79C3F, |
|
| 1071 | - 0x089766BE, 0xBAEEADF4, 0x1286BECF, 0xB6EACB19, |
|
| 1072 | - 0x2660C200, 0x7565BDE4, 0x64241F7A, 0x8248DCA9, |
|
| 1073 | - 0xC3B3AD66, 0x28136086, 0x0BD8DFA8, 0x356D1CF2, |
|
| 1074 | - 0x107789BE, 0xB3B2E9CE, 0x0502AA8F, 0x0BC0351E, |
|
| 1075 | - 0x166BF52A, 0xEB12FF82, 0xE3486911, 0xD34D7516, |
|
| 1076 | - 0x4E7B3AFF, 0x5F43671B, 0x9CF6E037, 0x4981AC83, |
|
| 1077 | - 0x334266CE, 0x8C9341B7, 0xD0D854C0, 0xCB3A6C88, |
|
| 1078 | - 0x47BC2829, 0x4725BA37, 0xA66AD22B, 0x7AD61F1E, |
|
| 1079 | - 0x0C5CBAFA, 0x4437F107, 0xB6E79962, 0x42D2D816, |
|
| 1080 | - 0x0A961288, 0xE1A5C06E, 0x13749E67, 0x72FC081A, |
|
| 1081 | - 0xB1D139F7, 0xF9583745, 0xCF19DF58, 0xBEC3F756, |
|
| 1082 | - 0xC06EBA30, 0x07211B24, 0x45C28829, 0xC95E317F, |
|
| 1083 | - 0xBC8EC511, 0x38BC46E9, 0xC6E6FA14, 0xBAE8584A, |
|
| 1084 | - 0xAD4EBC46, 0x468F508B, 0x7829435F, 0xF124183B, |
|
| 1085 | - 0x821DBA9F, 0xAFF60FF4, 0xEA2C4E6D, 0x16E39264, |
|
| 1086 | - 0x92544A8B, 0x009B4FC3, 0xABA68CED, 0x9AC96F78, |
|
| 1087 | - 0x06A5B79A, 0xB2856E6E, 0x1AEC3CA9, 0xBE838688, |
|
| 1088 | - 0x0E0804E9, 0x55F1BE56, 0xE7E5363B, 0xB3A1F25D, |
|
| 1089 | - 0xF7DEBB85, 0x61FE033C, 0x16746233, 0x3C034C28, |
|
| 1090 | - 0xDA6D0C74, 0x79AAC56C, 0x3CE4E1AD, 0x51F0C802, |
|
| 1091 | - 0x98F8F35A, 0x1626A49F, 0xEED82B29, 0x1D382FE3, |
|
| 1092 | - 0x0C4FB99A, 0xBB325778, 0x3EC6D97B, 0x6E77A6A9, |
|
| 1093 | - 0xCB658B5C, 0xD45230C7, 0x2BD1408B, 0x60C03EB7, |
|
| 1094 | - 0xB9068D78, 0xA33754F4, 0xF430C87D, 0xC8A71302, |
|
| 1095 | - 0xB96D8C32, 0xEBD4E7BE, 0xBE8B9D2D, 0x7979FB06, |
|
| 1096 | - 0xE7225308, 0x8B75CF77, 0x11EF8DA4, 0xE083C858, |
|
| 1097 | - 0x8D6B786F, 0x5A6317A6, 0xFA5CF7A0, 0x5DDA0033, |
|
| 1098 | - 0xF28EBFB0, 0xF5B9C310, 0xA0EAC280, 0x08B9767A, |
|
| 1099 | - 0xA3D9D2B0, 0x79D34217, 0x021A718D, 0x9AC6336A, |
|
| 1100 | - 0x2711FD60, 0x438050E3, 0x069908A8, 0x3D7FEDC4, |
|
| 1101 | - 0x826D2BEF, 0x4EEB8476, 0x488DCF25, 0x36C9D566, |
|
| 1102 | - 0x28E74E41, 0xC2610ACA, 0x3D49A9CF, 0xBAE3B9DF, |
|
| 1103 | - 0xB65F8DE6, 0x92AEAF64, 0x3AC7D5E6, 0x9EA80509, |
|
| 1104 | - 0xF22B017D, 0xA4173F70, 0xDD1E16C3, 0x15E0D7F9, |
|
| 1105 | - 0x50B1B887, 0x2B9F4FD5, 0x625ABA82, 0x6A017962, |
|
| 1106 | - 0x2EC01B9C, 0x15488AA9, 0xD716E740, 0x40055A2C, |
|
| 1107 | - 0x93D29A22, 0xE32DBF9A, 0x058745B9, 0x3453DC1E, |
|
| 1108 | - 0xD699296E, 0x496CFF6F, 0x1C9F4986, 0xDFE2ED07, |
|
| 1109 | - 0xB87242D1, 0x19DE7EAE, 0x053E561A, 0x15AD6F8C, |
|
| 1110 | - 0x66626C1C, 0x7154C24C, 0xEA082B2A, 0x93EB2939, |
|
| 1111 | - 0x17DCB0F0, 0x58D4F2AE, 0x9EA294FB, 0x52CF564C, |
|
| 1112 | - 0x9883FE66, 0x2EC40581, 0x763953C3, 0x01D6692E, |
|
| 1113 | - 0xD3A0C108, 0xA1E7160E, 0xE4F2DFA6, 0x693ED285, |
|
| 1114 | - 0x74904698, 0x4C2B0EDD, 0x4F757656, 0x5D393378, |
|
| 1115 | - 0xA132234F, 0x3D321C5D, 0xC3F5E194, 0x4B269301, |
|
| 1116 | - 0xC79F022F, 0x3C997E7E, 0x5E4F9504, 0x3FFAFBBD, |
|
| 1117 | - 0x76F7AD0E, 0x296693F4, 0x3D1FCE6F, 0xC61E45BE, |
|
| 1118 | - 0xD3B5AB34, 0xF72BF9B7, 0x1B0434C0, 0x4E72B567, |
|
| 1119 | - 0x5592A33D, 0xB5229301, 0xCFD2A87F, 0x60AEB767, |
|
| 1120 | - 0x1814386B, 0x30BCC33D, 0x38A0C07D, 0xFD1606F2, |
|
| 1121 | - 0xC363519B, 0x589DD390, 0x5479F8E6, 0x1CB8D647, |
|
| 1122 | - 0x97FD61A9, 0xEA7759F4, 0x2D57539D, 0x569A58CF, |
|
| 1123 | - 0xE84E63AD, 0x462E1B78, 0x6580F87E, 0xF3817914, |
|
| 1124 | - 0x91DA55F4, 0x40A230F3, 0xD1988F35, 0xB6E318D2, |
|
| 1125 | - 0x3FFA50BC, 0x3D40F021, 0xC3C0BDAE, 0x4958C24C, |
|
| 1126 | - 0x518F36B2, 0x84B1D370, 0x0FEDCE83, 0x878DDADA, |
|
| 1127 | - 0xF2A279C7, 0x94E01BE8, 0x90716F4B, 0x954B8AA3 |
|
| 1128 | - ); |
|
| 1129 | - |
|
| 1130 | - // 256 unsigned 32 bit integers |
|
| 1131 | - self::$_s8 = array( |
|
| 1132 | - 0xE216300D, 0xBBDDFFFC, 0xA7EBDABD, 0x35648095, |
|
| 1133 | - 0x7789F8B7, 0xE6C1121B, 0x0E241600, 0x052CE8B5, |
|
| 1134 | - 0x11A9CFB0, 0xE5952F11, 0xECE7990A, 0x9386D174, |
|
| 1135 | - 0x2A42931C, 0x76E38111, 0xB12DEF3A, 0x37DDDDFC, |
|
| 1136 | - 0xDE9ADEB1, 0x0A0CC32C, 0xBE197029, 0x84A00940, |
|
| 1137 | - 0xBB243A0F, 0xB4D137CF, 0xB44E79F0, 0x049EEDFD, |
|
| 1138 | - 0x0B15A15D, 0x480D3168, 0x8BBBDE5A, 0x669DED42, |
|
| 1139 | - 0xC7ECE831, 0x3F8F95E7, 0x72DF191B, 0x7580330D, |
|
| 1140 | - 0x94074251, 0x5C7DCDFA, 0xABBE6D63, 0xAA402164, |
|
| 1141 | - 0xB301D40A, 0x02E7D1CA, 0x53571DAE, 0x7A3182A2, |
|
| 1142 | - 0x12A8DDEC, 0xFDAA335D, 0x176F43E8, 0x71FB46D4, |
|
| 1143 | - 0x38129022, 0xCE949AD4, 0xB84769AD, 0x965BD862, |
|
| 1144 | - 0x82F3D055, 0x66FB9767, 0x15B80B4E, 0x1D5B47A0, |
|
| 1145 | - 0x4CFDE06F, 0xC28EC4B8, 0x57E8726E, 0x647A78FC, |
|
| 1146 | - 0x99865D44, 0x608BD593, 0x6C200E03, 0x39DC5FF6, |
|
| 1147 | - 0x5D0B00A3, 0xAE63AFF2, 0x7E8BD632, 0x70108C0C, |
|
| 1148 | - 0xBBD35049, 0x2998DF04, 0x980CF42A, 0x9B6DF491, |
|
| 1149 | - 0x9E7EDD53, 0x06918548, 0x58CB7E07, 0x3B74EF2E, |
|
| 1150 | - 0x522FFFB1, 0xD24708CC, 0x1C7E27CD, 0xA4EB215B, |
|
| 1151 | - 0x3CF1D2E2, 0x19B47A38, 0x424F7618, 0x35856039, |
|
| 1152 | - 0x9D17DEE7, 0x27EB35E6, 0xC9AFF67B, 0x36BAF5B8, |
|
| 1153 | - 0x09C467CD, 0xC18910B1, 0xE11DBF7B, 0x06CD1AF8, |
|
| 1154 | - 0x7170C608, 0x2D5E3354, 0xD4DE495A, 0x64C6D006, |
|
| 1155 | - 0xBCC0C62C, 0x3DD00DB3, 0x708F8F34, 0x77D51B42, |
|
| 1156 | - 0x264F620F, 0x24B8D2BF, 0x15C1B79E, 0x46A52564, |
|
| 1157 | - 0xF8D7E54E, 0x3E378160, 0x7895CDA5, 0x859C15A5, |
|
| 1158 | - 0xE6459788, 0xC37BC75F, 0xDB07BA0C, 0x0676A3AB, |
|
| 1159 | - 0x7F229B1E, 0x31842E7B, 0x24259FD7, 0xF8BEF472, |
|
| 1160 | - 0x835FFCB8, 0x6DF4C1F2, 0x96F5B195, 0xFD0AF0FC, |
|
| 1161 | - 0xB0FE134C, 0xE2506D3D, 0x4F9B12EA, 0xF215F225, |
|
| 1162 | - 0xA223736F, 0x9FB4C428, 0x25D04979, 0x34C713F8, |
|
| 1163 | - 0xC4618187, 0xEA7A6E98, 0x7CD16EFC, 0x1436876C, |
|
| 1164 | - 0xF1544107, 0xBEDEEE14, 0x56E9AF27, 0xA04AA441, |
|
| 1165 | - 0x3CF7C899, 0x92ECBAE6, 0xDD67016D, 0x151682EB, |
|
| 1166 | - 0xA842EEDF, 0xFDBA60B4, 0xF1907B75, 0x20E3030F, |
|
| 1167 | - 0x24D8C29E, 0xE139673B, 0xEFA63FB8, 0x71873054, |
|
| 1168 | - 0xB6F2CF3B, 0x9F326442, 0xCB15A4CC, 0xB01A4504, |
|
| 1169 | - 0xF1E47D8D, 0x844A1BE5, 0xBAE7DFDC, 0x42CBDA70, |
|
| 1170 | - 0xCD7DAE0A, 0x57E85B7A, 0xD53F5AF6, 0x20CF4D8C, |
|
| 1171 | - 0xCEA4D428, 0x79D130A4, 0x3486EBFB, 0x33D3CDDC, |
|
| 1172 | - 0x77853B53, 0x37EFFCB5, 0xC5068778, 0xE580B3E6, |
|
| 1173 | - 0x4E68B8F4, 0xC5C8B37E, 0x0D809EA2, 0x398FEB7C, |
|
| 1174 | - 0x132A4F94, 0x43B7950E, 0x2FEE7D1C, 0x223613BD, |
|
| 1175 | - 0xDD06CAA2, 0x37DF932B, 0xC4248289, 0xACF3EBC3, |
|
| 1176 | - 0x5715F6B7, 0xEF3478DD, 0xF267616F, 0xC148CBE4, |
|
| 1177 | - 0x9052815E, 0x5E410FAB, 0xB48A2465, 0x2EDA7FA4, |
|
| 1178 | - 0xE87B40E4, 0xE98EA084, 0x5889E9E1, 0xEFD390FC, |
|
| 1179 | - 0xDD07D35B, 0xDB485694, 0x38D7E5B2, 0x57720101, |
|
| 1180 | - 0x730EDEBC, 0x5B643113, 0x94917E4F, 0x503C2FBA, |
|
| 1181 | - 0x646F1282, 0x7523D24A, 0xE0779695, 0xF9C17A8F, |
|
| 1182 | - 0x7A5B2121, 0xD187B896, 0x29263A4D, 0xBA510CDF, |
|
| 1183 | - 0x81F47C9F, 0xAD1163ED, 0xEA7B5965, 0x1A00726E, |
|
| 1184 | - 0x11403092, 0x00DA6D77, 0x4A0CDD61, 0xAD1F4603, |
|
| 1185 | - 0x605BDFB0, 0x9EEDC364, 0x22EBE6A8, 0xCEE7D28A, |
|
| 1186 | - 0xA0E736A0, 0x5564A6B9, 0x10853209, 0xC7EB8F37, |
|
| 1187 | - 0x2DE705CA, 0x8951570F, 0xDF09822B, 0xBD691A6C, |
|
| 1188 | - 0xAA12E4F2, 0x87451C0F, 0xE0F6A27A, 0x3ADA4819, |
|
| 1189 | - 0x4CF1764F, 0x0D771C2B, 0x67CDB156, 0x350D8384, |
|
| 1190 | - 0x5938FA0F, 0x42399EF3, 0x36997B07, 0x0E84093D, |
|
| 1191 | - 0x4AA93E61, 0x8360D87B, 0x1FA98B0C, 0x1149382C, |
|
| 1192 | - 0xE97625A5, 0x0614D1B7, 0x0E25244B, 0x0C768347, |
|
| 1193 | - 0x589E8D82, 0x0D2059D1, 0xA466BB1E, 0xF8DA0A82, |
|
| 1194 | - 0x04F19130, 0xBA6E4EC0, 0x99265164, 0x1EE7230D, |
|
| 1195 | - 0x50B2AD80, 0xEAEE6801, 0x8DB2A283, 0xEA8BF59E |
|
| 1196 | - ); |
|
| 1197 | - } |
|
| 1198 | - |
|
| 1199 | - |
|
| 1200 | - /** |
|
| 1201 | - * Indicates this is a block cipher |
|
| 1202 | - * |
|
| 1203 | - * @return integer Returns Cipher::BLOCK |
|
| 1204 | - */ |
|
| 1205 | - public function type() |
|
| 1206 | - { |
|
| 1207 | - return parent::BLOCK; |
|
| 1208 | - } |
|
| 352 | + // two loops, each loop does 16 bytes for a total of 32 bytes |
|
| 353 | + for($i = 0; $i < 2; ++$i) |
|
| 354 | + { |
|
| 355 | + // z0z1z2z3 = x0x1x2x3 ^ S5[xD] ^ S6[xF] ^ S7[xC] ^ S8[xE] ^ S7[x8] |
|
| 356 | + $tmp = substr($x, 0x00, 4); |
|
| 357 | + $tmp = parent::dec2Str( |
|
| 358 | + parent::uInt32( |
|
| 359 | + parent::str2Dec($tmp) ^ self::$_s5[ord($x[0x0d])] ^ |
|
| 360 | + self::$_s6[ord($x[0x0f])] ^ self::$_s7[ord($x[0x0c])] ^ |
|
| 361 | + self::$_s8[ord($x[0x0e])] ^ self::$_s7[ord($x[0x08])] |
|
| 362 | + ), 4); |
|
| 363 | + $z = substr_replace($z, $tmp, 0x00, 4); |
|
| 364 | + |
|
| 365 | + //print "Z0: ".parent::str2Hex($z)." (".strlen($z).")\n"; |
|
| 366 | + |
|
| 367 | + // z4z5z6z7 = x8x9xAxB ^ S5[z0] ^ S6[z2] ^ S7[z1] ^ S8[z3] ^ S8[xA] |
|
| 368 | + $tmp = substr($x, 0x08, 4); |
|
| 369 | + $tmp = parent::dec2Str( |
|
| 370 | + parent::uInt32( |
|
| 371 | + parent::str2Dec($tmp) ^ self::$_s5[ord($z[0x00])] ^ |
|
| 372 | + self::$_s6[ord($z[0x02])] ^ self::$_s7[ord($z[0x01])] ^ |
|
| 373 | + self::$_s8[ord($z[0x03])] ^ self::$_s8[ord($x[0x0a])] |
|
| 374 | + ), 4); |
|
| 375 | + $z = substr_replace($z, $tmp, 0x04, 4); |
|
| 376 | + |
|
| 377 | + // z8z9zAzB = xCxDxExF ^ S5[z7] ^ S6[z6] ^ S7[z5] ^ S8[z4] ^ S5[x9] |
|
| 378 | + $tmp = substr($x, 0x0c, 4); |
|
| 379 | + $tmp = parent::dec2Str( |
|
| 380 | + parent::uInt32( |
|
| 381 | + parent::str2Dec($tmp) ^ self::$_s5[ord($z[0x07])] ^ |
|
| 382 | + self::$_s6[ord($z[0x06])] ^ self::$_s7[ord($z[0x05])] ^ |
|
| 383 | + self::$_s8[ord($z[0x04])] ^ self::$_s5[ord($x[0x09])] |
|
| 384 | + ), 4); |
|
| 385 | + $z = substr_replace($z, $tmp, 0x08, 4); |
|
| 386 | + |
|
| 387 | + // zCzDzEzF = x4x5x6x7 ^ S5[zA] ^ S6[z9] ^ S7[zB] ^ S8[z8] ^ S6[xB] |
|
| 388 | + $tmp = substr($x, 0x04, 4); |
|
| 389 | + $tmp = parent::dec2Str( |
|
| 390 | + parent::uInt32( |
|
| 391 | + parent::str2Dec($tmp) ^ self::$_s5[ord($z[0x0a])] ^ |
|
| 392 | + self::$_s6[ord($z[0x09])] ^ self::$_s7[ord($z[0x0b])] ^ |
|
| 393 | + self::$_s8[ord($z[0x08])] ^ self::$_s6[ord($x[0x0b])] |
|
| 394 | + ), 4); |
|
| 395 | + $z = substr_replace($z, $tmp, 0x0c, 4); |
|
| 396 | + |
|
| 397 | + //print "Z: ".parent::str2Hex($z)." (".strlen($z).")\n"; |
|
| 398 | + |
|
| 399 | + // K1 = S5[z8] ^ S6[z9] ^ S7[z7] ^ S8[z6] ^ S5[z2] |
|
| 400 | + $skey[] = parent::uInt32(self::$_s5[ord($z[0x08])] ^ self::$_s6[ord($z[0x09])] ^ |
|
| 401 | + self::$_s7[ord($z[0x07])] ^ self::$_s8[ord($z[0x06])] ^ |
|
| 402 | + self::$_s5[ord($z[0x02])] |
|
| 403 | + ); |
|
| 404 | + |
|
| 405 | + // K2 = S5[zA] ^ S6[zB] ^ S7[z5] ^ S8[z4] ^ S6[z6] |
|
| 406 | + $skey[] = parent::uInt32( |
|
| 407 | + self::$_s5[ord($z[0x0a])] ^ self::$_s6[ord($z[0x0b])] ^ |
|
| 408 | + self::$_s7[ord($z[0x05])] ^ self::$_s8[ord($z[0x04])] ^ |
|
| 409 | + self::$_s6[ord($z[0x06])] |
|
| 410 | + ); |
|
| 411 | + |
|
| 412 | + // K3 = S5[zC] ^ S6[zD] ^ S7[z3] ^ S8[z2] ^ S7[z9] |
|
| 413 | + $skey[] = parent::uInt32( |
|
| 414 | + self::$_s5[ord($z[0x0c])] ^ self::$_s6[ord($z[0x0d])] ^ |
|
| 415 | + self::$_s7[ord($z[0x03])] ^ self::$_s8[ord($z[0x02])] ^ |
|
| 416 | + self::$_s7[ord($z[0x09])] |
|
| 417 | + ); |
|
| 418 | + |
|
| 419 | + // K4 = S5[zE] ^ S6[zF] ^ S7[z1] ^ S8[z0] ^ S8[zC] |
|
| 420 | + $skey[] = parent::uInt32( |
|
| 421 | + self::$_s5[ord($z[0x0e])] ^ self::$_s6[ord($z[0x0f])] ^ |
|
| 422 | + self::$_s7[ord($z[0x01])] ^ self::$_s8[ord($z[0x00])] ^ |
|
| 423 | + self::$_s8[ord($z[0x0c])] |
|
| 424 | + ); |
|
| 425 | + |
|
| 426 | + // x0x1x2x3 = z8z9zAzB ^ S5[z5] ^ S6[z7] ^ S7[z4] ^ S8[z6] ^ S7[z0] |
|
| 427 | + $tmp = substr($z, 0x08, 4); |
|
| 428 | + $tmp = parent::dec2Str( |
|
| 429 | + parent::uInt32( |
|
| 430 | + parent::str2Dec($tmp) ^ self::$_s5[ord($z[0x05])] ^ |
|
| 431 | + self::$_s6[ord($z[0x07])] ^ self::$_s7[ord($z[0x04])] ^ |
|
| 432 | + self::$_s8[ord($z[0x06])] ^ self::$_s7[ord($z[0x00])] |
|
| 433 | + ), 4); |
|
| 434 | + $x = substr_replace($x, $tmp, 0x00, 4); |
|
| 435 | + |
|
| 436 | + // x4x5x6x7 = z0z1z2z3 ^ S5[x0] ^ S6[x2] ^ S7[x1] ^ S8[x3] ^ S8[z2] |
|
| 437 | + $tmp = substr($z, 0x00, 4); |
|
| 438 | + $tmp = parent::dec2Str( |
|
| 439 | + parent::uInt32( |
|
| 440 | + parent::str2Dec($tmp) ^ self::$_s5[ord($x[0x00])] ^ |
|
| 441 | + self::$_s6[ord($x[0x02])] ^ self::$_s7[ord($x[0x01])] ^ |
|
| 442 | + self::$_s8[ord($x[0x03])] ^ self::$_s8[ord($z[0x02])] |
|
| 443 | + ), 4); |
|
| 444 | + $x = substr_replace($x, $tmp, 0x04, 4); |
|
| 445 | + |
|
| 446 | + // x8x9xAxB = z4z5z6z7 ^ S5[x7] ^ S6[x6] ^ S7[x5] ^ S8[x4] ^ S5[z1] |
|
| 447 | + $tmp = substr($z, 0x04, 4); |
|
| 448 | + $tmp = parent::dec2Str( |
|
| 449 | + parent::uInt32( |
|
| 450 | + parent::str2Dec($tmp) ^ self::$_s5[ord($x[0x07])] ^ |
|
| 451 | + self::$_s6[ord($x[0x06])] ^ self::$_s7[ord($x[0x05])] ^ |
|
| 452 | + self::$_s8[ord($x[0x04])] ^ self::$_s5[ord($z[0x01])] |
|
| 453 | + ), 4); |
|
| 454 | + $x = substr_replace($x, $tmp, 0x08, 4); |
|
| 455 | + |
|
| 456 | + // xCxDxExF = zCzDzEzF ^ S5[xA] ^ S6[x9] ^ S7[xB] ^ S8[x8] ^ S6[z3] |
|
| 457 | + $tmp = substr($z, 0x0c, 4); |
|
| 458 | + $tmp = parent::dec2Str( |
|
| 459 | + parent::uInt32( |
|
| 460 | + parent::str2Dec($tmp) ^ self::$_s5[ord($x[0x0a])] ^ |
|
| 461 | + self::$_s6[ord($x[0x09])] ^ self::$_s7[ord($x[0x0b])] ^ |
|
| 462 | + self::$_s8[ord($x[0x08])] ^ self::$_s6[ord($z[0x03])] |
|
| 463 | + ), 4); |
|
| 464 | + $x = substr_replace($x, $tmp, 0x0c, 4); |
|
| 465 | + |
|
| 466 | + // K5 = S5[x3] ^ S6[x2] ^ S7[xC] ^ S8[xD] ^ S5[x8] |
|
| 467 | + $skey[] = parent::uInt32( |
|
| 468 | + self::$_s5[ord($x[0x03])] ^ self::$_s6[ord($x[0x02])] ^ |
|
| 469 | + self::$_s7[ord($x[0x0c])] ^ self::$_s8[ord($x[0x0d])] ^ |
|
| 470 | + self::$_s5[ord($x[0x08])] |
|
| 471 | + ); |
|
| 472 | + |
|
| 473 | + // K6 = S5[x1] ^ S6[x0] ^ S7[xE] ^ S8[xF] ^ S6[xD] |
|
| 474 | + $skey[] = parent::uInt32( |
|
| 475 | + self::$_s5[ord($x[0x01])] ^ self::$_s6[ord($x[0x00])] ^ |
|
| 476 | + self::$_s7[ord($x[0x0e])] ^ self::$_s8[ord($x[0x0f])] ^ |
|
| 477 | + self::$_s6[ord($x[0x0d])] |
|
| 478 | + ); |
|
| 479 | + |
|
| 480 | + // K7 = S5[x7] ^ S6[x6] ^ S7[x8] ^ S8[x9] ^ S7[x3] |
|
| 481 | + $skey[] = parent::uInt32( |
|
| 482 | + self::$_s5[ord($x[0x07])] ^ self::$_s6[ord($x[0x06])] ^ |
|
| 483 | + self::$_s7[ord($x[0x08])] ^ self::$_s8[ord($x[0x09])] ^ |
|
| 484 | + self::$_s7[ord($x[0x03])] |
|
| 485 | + ); |
|
| 486 | + |
|
| 487 | + // K8 = S5[x5] ^ S6[x4] ^ S7[xA] ^ S8[xB] ^ S8[x7] |
|
| 488 | + $skey[] = parent::uInt32( |
|
| 489 | + self::$_s5[ord($x[0x05])] ^ self::$_s6[ord($x[0x04])] ^ |
|
| 490 | + self::$_s7[ord($x[0x0a])] ^ self::$_s8[ord($x[0x0b])] ^ |
|
| 491 | + self::$_s8[ord($x[0x07])] |
|
| 492 | + ); |
|
| 493 | + |
|
| 494 | + // z0z1z2z3 = x0x1x2x3 ^ S5[xD] ^ S6[xF] ^ S7[xC] ^ S8[xE] ^ S7[x8] |
|
| 495 | + $tmp = substr($x, 0x00, 4); |
|
| 496 | + $tmp = parent::dec2Str( |
|
| 497 | + parent::uInt32( |
|
| 498 | + parent::str2Dec($tmp) ^ self::$_s5[ord($x[0x0d])] ^ |
|
| 499 | + self::$_s6[ord($x[0x0f])] ^ self::$_s7[ord($x[0x0c])] ^ |
|
| 500 | + self::$_s8[ord($x[0x0e])] ^ self::$_s7[ord($x[0x08])] |
|
| 501 | + ), 4); |
|
| 502 | + $z = substr_replace($z, $tmp, 0x00, 4); |
|
| 503 | + |
|
| 504 | + // z4z5z6z7 = x8x9xAxB ^ S5[z0] ^ S6[z2] ^ S7[z1] ^ S8[z3] ^ S8[xA] |
|
| 505 | + $tmp = substr($x, 0x08, 4); |
|
| 506 | + $tmp = parent::dec2Str( |
|
| 507 | + parent::uInt32( |
|
| 508 | + parent::str2Dec($tmp) ^ self::$_s5[ord($z[0x00])] ^ |
|
| 509 | + self::$_s6[ord($z[0x02])] ^ self::$_s7[ord($z[0x01])] ^ |
|
| 510 | + self::$_s8[ord($z[0x03])] ^ self::$_s8[ord($x[0x0a])] |
|
| 511 | + ), 4); |
|
| 512 | + $z = substr_replace($z, $tmp, 0x04, 4); |
|
| 513 | + |
|
| 514 | + // z8z9zAzB = xCxDxExF ^ S5[z7] ^ S6[z6] ^ S7[z5] ^ S8[z4] ^ S5[x9] |
|
| 515 | + $tmp = substr($x, 0x0c, 4); |
|
| 516 | + $tmp = parent::dec2Str( |
|
| 517 | + parent::uInt32( |
|
| 518 | + parent::str2Dec($tmp) ^ self::$_s5[ord($z[0x07])] ^ |
|
| 519 | + self::$_s6[ord($z[0x06])] ^ self::$_s7[ord($z[0x05])] ^ |
|
| 520 | + self::$_s8[ord($z[0x04])] ^ self::$_s5[ord($x[0x09])] |
|
| 521 | + ), 4); |
|
| 522 | + $z = substr_replace($z, $tmp, 0x08, 4); |
|
| 523 | + |
|
| 524 | + // zCzDzEzF = x4x5x6x7 ^ S5[zA] ^ S6[z9] ^ S7[zB] ^ S8[z8] ^ S6[xB] |
|
| 525 | + $tmp = substr($x, 0x04, 4); |
|
| 526 | + $tmp = parent::dec2Str( |
|
| 527 | + parent::uInt32( |
|
| 528 | + parent::str2Dec($tmp) ^ self::$_s5[ord($z[0x0a])] ^ |
|
| 529 | + self::$_s6[ord($z[0x09])] ^ self::$_s7[ord($z[0x0b])] ^ |
|
| 530 | + self::$_s8[ord($z[0x08])] ^ self::$_s6[ord($x[0x0b])] |
|
| 531 | + ), 4); |
|
| 532 | + $z = substr_replace($z, $tmp, 0x0c, 4); |
|
| 533 | + |
|
| 534 | + // K9 = S5[z3] ^ S6[z2] ^ S7[zC] ^ S8[zD] ^ S5[z9] |
|
| 535 | + $skey[] = parent::uInt32( |
|
| 536 | + self::$_s5[ord($z[0x03])] ^ self::$_s6[ord($z[0x02])] ^ |
|
| 537 | + self::$_s7[ord($z[0x0c])] ^ self::$_s8[ord($z[0x0d])] ^ |
|
| 538 | + self::$_s5[ord($z[0x09])] |
|
| 539 | + ); |
|
| 540 | + |
|
| 541 | + // K10 = S5[z1] ^ S6[z0] ^ S7[zE] ^ S8[zF] ^ S6[zC] |
|
| 542 | + $skey[] = parent::uInt32( |
|
| 543 | + self::$_s5[ord($z[0x01])] ^ self::$_s6[ord($z[0x00])] ^ |
|
| 544 | + self::$_s7[ord($z[0x0e])] ^ self::$_s8[ord($z[0x0f])] ^ |
|
| 545 | + self::$_s6[ord($z[0x0c])] |
|
| 546 | + ); |
|
| 547 | + |
|
| 548 | + // K11 = S5[z7] ^ S6[z6] ^ S7[z8] ^ S8[z9] ^ S7[z2] |
|
| 549 | + $skey[] = parent::uInt32( |
|
| 550 | + self::$_s5[ord($z[0x07])] ^ self::$_s6[ord($z[0x06])] ^ |
|
| 551 | + self::$_s7[ord($z[0x08])] ^ self::$_s8[ord($z[0x09])] ^ |
|
| 552 | + self::$_s7[ord($z[0x02])] |
|
| 553 | + ); |
|
| 554 | + |
|
| 555 | + // K12 = S5[z5] ^ S6[z4] ^ S7[zA] ^ S8[zB] ^ S8[z6] |
|
| 556 | + $skey[] = parent::uInt32( |
|
| 557 | + self::$_s5[ord($z[0x05])] ^ self::$_s6[ord($z[0x04])] ^ |
|
| 558 | + self::$_s7[ord($z[0x0a])] ^ self::$_s8[ord($z[0x0b])] ^ |
|
| 559 | + self::$_s8[ord($z[0x06])] |
|
| 560 | + ); |
|
| 561 | + |
|
| 562 | + // x0x1x2x3 = z8z9zAzB ^ S5[z5] ^ S6[z7] ^ S7[z4] ^ S8[z6] ^ S7[z0] |
|
| 563 | + $tmp = substr($z, 0x08, 4); |
|
| 564 | + $tmp = parent::dec2Str( |
|
| 565 | + parent::uInt32( |
|
| 566 | + parent::str2Dec($tmp) ^ self::$_s5[ord($z[0x05])] ^ |
|
| 567 | + self::$_s6[ord($z[0x07])] ^ self::$_s7[ord($z[0x04])] ^ |
|
| 568 | + self::$_s8[ord($z[0x06])] ^ self::$_s7[ord($z[0x00])] |
|
| 569 | + ), 4); |
|
| 570 | + $x = substr_replace($x, $tmp, 0x00, 4); |
|
| 571 | + |
|
| 572 | + // x4x5x6x7 = z0z1z2z3 ^ S5[x0] ^ S6[x2] ^ S7[x1] ^ S8[x3] ^ S8[z2] |
|
| 573 | + $tmp = substr($z, 0x00, 4); |
|
| 574 | + $tmp = parent::dec2Str( |
|
| 575 | + parent::uInt32( |
|
| 576 | + parent::str2Dec($tmp) ^ self::$_s5[ord($x[0x00])] ^ |
|
| 577 | + self::$_s6[ord($x[0x02])] ^ self::$_s7[ord($x[0x01])] ^ |
|
| 578 | + self::$_s8[ord($x[0x03])] ^ self::$_s8[ord($z[0x02])] |
|
| 579 | + ), 4); |
|
| 580 | + $x = substr_replace($x, $tmp, 0x04, 4); |
|
| 581 | + |
|
| 582 | + // x8x9xAxB = z4z5z6z7 ^ S5[x7] ^ S6[x6] ^ S7[x5] ^ S8[x4] ^ S5[z1] |
|
| 583 | + $tmp = substr($z, 0x04, 4); |
|
| 584 | + $tmp = parent::dec2Str( |
|
| 585 | + parent::uInt32( |
|
| 586 | + parent::str2Dec($tmp) ^ self::$_s5[ord($x[0x07])] ^ |
|
| 587 | + self::$_s6[ord($x[0x06])] ^ self::$_s7[ord($x[0x05])] ^ |
|
| 588 | + self::$_s8[ord($x[0x04])] ^ self::$_s5[ord($z[0x01])] |
|
| 589 | + ), 4); |
|
| 590 | + $x = substr_replace($x, $tmp, 0x08, 4); |
|
| 591 | + |
|
| 592 | + // xCxDxExF = zCzDzEzF ^ S5[xA] ^ S6[x9] ^ S7[xB] ^ S8[x8] ^ S6[z3] |
|
| 593 | + $tmp = substr($z, 0x0c, 4); |
|
| 594 | + $tmp = parent::dec2Str( |
|
| 595 | + parent::uInt32( |
|
| 596 | + parent::str2Dec($tmp) ^ self::$_s5[ord($x[0x0a])] ^ |
|
| 597 | + self::$_s6[ord($x[0x09])] ^ self::$_s7[ord($x[0x0b])] ^ |
|
| 598 | + self::$_s8[ord($x[0x08])] ^ self::$_s6[ord($z[0x03])] |
|
| 599 | + ), 4); |
|
| 600 | + $x = substr_replace($x, $tmp, 0x0c, 4); |
|
| 601 | + |
|
| 602 | + // K13 = S5[x8] ^ S6[x9] ^ S7[x7] ^ S8[x6] ^ S5[x3] |
|
| 603 | + $skey[] = parent::uInt32( |
|
| 604 | + self::$_s5[ord($x[0x08])] ^ self::$_s6[ord($x[0x09])] ^ |
|
| 605 | + self::$_s7[ord($x[0x07])] ^ self::$_s8[ord($x[0x06])] ^ |
|
| 606 | + self::$_s5[ord($x[0x03])] |
|
| 607 | + ); |
|
| 608 | + |
|
| 609 | + // K14 = S5[xA] ^ S6[xB] ^ S7[x5] ^ S8[x4] ^ S6[x7] |
|
| 610 | + $skey[] = parent::uInt32( |
|
| 611 | + self::$_s5[ord($x[0x0a])] ^ self::$_s6[ord($x[0x0b])] ^ |
|
| 612 | + self::$_s7[ord($x[0x05])] ^ self::$_s8[ord($x[0x04])] ^ |
|
| 613 | + self::$_s6[ord($x[0x07])] |
|
| 614 | + ); |
|
| 615 | + |
|
| 616 | + // K15 = S5[xC] ^ S6[xD] ^ S7[x3] ^ S8[x2] ^ S7[x8] |
|
| 617 | + $skey[] = parent::uInt32( |
|
| 618 | + self::$_s5[ord($x[0x0c])] ^ self::$_s6[ord($x[0x0d])] ^ |
|
| 619 | + self::$_s7[ord($x[0x03])] ^ self::$_s8[ord($x[0x02])] ^ |
|
| 620 | + self::$_s7[ord($x[0x08])] |
|
| 621 | + ); |
|
| 622 | + |
|
| 623 | + // K16 = S5[xE] ^ S6[xF] ^ S7[x1] ^ S8[x0] ^ S8[xD] |
|
| 624 | + $skey[] = parent::uInt32( |
|
| 625 | + self::$_s5[ord($x[0x0e])] ^ self::$_s6[ord($x[0x0f])] ^ |
|
| 626 | + self::$_s7[ord($x[0x01])] ^ self::$_s8[ord($x[0x00])] ^ |
|
| 627 | + self::$_s8[ord($x[0x0d])] |
|
| 628 | + ); |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + // create the 16 byte masking and rotate subkeys |
|
| 632 | + $this->_mkey = array_slice($skey, 0, 16); |
|
| 633 | + $this->_rkey = array_slice($skey, 16, 16); |
|
| 634 | + |
|
| 635 | + // $_rkey only uses the least significant 5 bits |
|
| 636 | + $this->_rkey = array_map(function($v) { |
|
| 637 | + return $v &= 31; |
|
| 638 | + }, $this->_rkey); |
|
| 639 | + |
|
| 640 | + // there is 4kb in the s5 - s8 sboxes, which are not needed after we |
|
| 641 | + // create the subkeys, so free up the memory. unset() doesn't work here |
|
| 642 | + for($i = 5; $i <= 8; ++$i) |
|
| 643 | + self::${"_s$i"} = null; |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + |
|
| 647 | + /** |
|
| 648 | + * Initialize the tables. |
|
| 649 | + * |
|
| 650 | + * @return void |
|
| 651 | + */ |
|
| 652 | + private function initTables() |
|
| 653 | + { |
|
| 654 | + // 256 unsigned 32 bit integers |
|
| 655 | + self::$_s1 = array( |
|
| 656 | + 0x30FB40D4, 0x9FA0FF0B, 0x6BECCD2F, 0x3F258C7A, |
|
| 657 | + 0x1E213F2F, 0x9C004DD3, 0x6003E540, 0xCF9FC949, |
|
| 658 | + 0xBFD4AF27, 0x88BBBDB5, 0xE2034090, 0x98D09675, |
|
| 659 | + 0x6E63A0E0, 0x15C361D2, 0xC2E7661D, 0x22D4FF8E, |
|
| 660 | + 0x28683B6F, 0xC07FD059, 0xFF2379C8, 0x775F50E2, |
|
| 661 | + 0x43C340D3, 0xDF2F8656, 0x887CA41A, 0xA2D2BD2D, |
|
| 662 | + 0xA1C9E0D6, 0x346C4819, 0x61B76D87, 0x22540F2F, |
|
| 663 | + 0x2ABE32E1, 0xAA54166B, 0x22568E3A, 0xA2D341D0, |
|
| 664 | + 0x66DB40C8, 0xA784392F, 0x004DFF2F, 0x2DB9D2DE, |
|
| 665 | + 0x97943FAC, 0x4A97C1D8, 0x527644B7, 0xB5F437A7, |
|
| 666 | + 0xB82CBAEF, 0xD751D159, 0x6FF7F0ED, 0x5A097A1F, |
|
| 667 | + 0x827B68D0, 0x90ECF52E, 0x22B0C054, 0xBC8E5935, |
|
| 668 | + 0x4B6D2F7F, 0x50BB64A2, 0xD2664910, 0xBEE5812D, |
|
| 669 | + 0xB7332290, 0xE93B159F, 0xB48EE411, 0x4BFF345D, |
|
| 670 | + 0xFD45C240, 0xAD31973F, 0xC4F6D02E, 0x55FC8165, |
|
| 671 | + 0xD5B1CAAD, 0xA1AC2DAE, 0xA2D4B76D, 0xC19B0C50, |
|
| 672 | + 0x882240F2, 0x0C6E4F38, 0xA4E4BFD7, 0x4F5BA272, |
|
| 673 | + 0x564C1D2F, 0xC59C5319, 0xB949E354, 0xB04669FE, |
|
| 674 | + 0xB1B6AB8A, 0xC71358DD, 0x6385C545, 0x110F935D, |
|
| 675 | + 0x57538AD5, 0x6A390493, 0xE63D37E0, 0x2A54F6B3, |
|
| 676 | + 0x3A787D5F, 0x6276A0B5, 0x19A6FCDF, 0x7A42206A, |
|
| 677 | + 0x29F9D4D5, 0xF61B1891, 0xBB72275E, 0xAA508167, |
|
| 678 | + 0x38901091, 0xC6B505EB, 0x84C7CB8C, 0x2AD75A0F, |
|
| 679 | + 0x874A1427, 0xA2D1936B, 0x2AD286AF, 0xAA56D291, |
|
| 680 | + 0xD7894360, 0x425C750D, 0x93B39E26, 0x187184C9, |
|
| 681 | + 0x6C00B32D, 0x73E2BB14, 0xA0BEBC3C, 0x54623779, |
|
| 682 | + 0x64459EAB, 0x3F328B82, 0x7718CF82, 0x59A2CEA6, |
|
| 683 | + 0x04EE002E, 0x89FE78E6, 0x3FAB0950, 0x325FF6C2, |
|
| 684 | + 0x81383F05, 0x6963C5C8, 0x76CB5AD6, 0xD49974C9, |
|
| 685 | + 0xCA180DCF, 0x380782D5, 0xC7FA5CF6, 0x8AC31511, |
|
| 686 | + 0x35E79E13, 0x47DA91D0, 0xF40F9086, 0xA7E2419E, |
|
| 687 | + 0x31366241, 0x051EF495, 0xAA573B04, 0x4A805D8D, |
|
| 688 | + 0x548300D0, 0x00322A3C, 0xBF64CDDF, 0xBA57A68E, |
|
| 689 | + 0x75C6372B, 0x50AFD341, 0xA7C13275, 0x915A0BF5, |
|
| 690 | + 0x6B54BFAB, 0x2B0B1426, 0xAB4CC9D7, 0x449CCD82, |
|
| 691 | + 0xF7FBF265, 0xAB85C5F3, 0x1B55DB94, 0xAAD4E324, |
|
| 692 | + 0xCFA4BD3F, 0x2DEAA3E2, 0x9E204D02, 0xC8BD25AC, |
|
| 693 | + 0xEADF55B3, 0xD5BD9E98, 0xE31231B2, 0x2AD5AD6C, |
|
| 694 | + 0x954329DE, 0xADBE4528, 0xD8710F69, 0xAA51C90F, |
|
| 695 | + 0xAA786BF6, 0x22513F1E, 0xAA51A79B, 0x2AD344CC, |
|
| 696 | + 0x7B5A41F0, 0xD37CFBAD, 0x1B069505, 0x41ECE491, |
|
| 697 | + 0xB4C332E6, 0x032268D4, 0xC9600ACC, 0xCE387E6D, |
|
| 698 | + 0xBF6BB16C, 0x6A70FB78, 0x0D03D9C9, 0xD4DF39DE, |
|
| 699 | + 0xE01063DA, 0x4736F464, 0x5AD328D8, 0xB347CC96, |
|
| 700 | + 0x75BB0FC3, 0x98511BFB, 0x4FFBCC35, 0xB58BCF6A, |
|
| 701 | + 0xE11F0ABC, 0xBFC5FE4A, 0xA70AEC10, 0xAC39570A, |
|
| 702 | + 0x3F04442F, 0x6188B153, 0xE0397A2E, 0x5727CB79, |
|
| 703 | + 0x9CEB418F, 0x1CACD68D, 0x2AD37C96, 0x0175CB9D, |
|
| 704 | + 0xC69DFF09, 0xC75B65F0, 0xD9DB40D8, 0xEC0E7779, |
|
| 705 | + 0x4744EAD4, 0xB11C3274, 0xDD24CB9E, 0x7E1C54BD, |
|
| 706 | + 0xF01144F9, 0xD2240EB1, 0x9675B3FD, 0xA3AC3755, |
|
| 707 | + 0xD47C27AF, 0x51C85F4D, 0x56907596, 0xA5BB15E6, |
|
| 708 | + 0x580304F0, 0xCA042CF1, 0x011A37EA, 0x8DBFAADB, |
|
| 709 | + 0x35BA3E4A, 0x3526FFA0, 0xC37B4D09, 0xBC306ED9, |
|
| 710 | + 0x98A52666, 0x5648F725, 0xFF5E569D, 0x0CED63D0, |
|
| 711 | + 0x7C63B2CF, 0x700B45E1, 0xD5EA50F1, 0x85A92872, |
|
| 712 | + 0xAF1FBDA7, 0xD4234870, 0xA7870BF3, 0x2D3B4D79, |
|
| 713 | + 0x42E04198, 0x0CD0EDE7, 0x26470DB8, 0xF881814C, |
|
| 714 | + 0x474D6AD7, 0x7C0C5E5C, 0xD1231959, 0x381B7298, |
|
| 715 | + 0xF5D2F4DB, 0xAB838653, 0x6E2F1E23, 0x83719C9E, |
|
| 716 | + 0xBD91E046, 0x9A56456E, 0xDC39200C, 0x20C8C571, |
|
| 717 | + 0x962BDA1C, 0xE1E696FF, 0xB141AB08, 0x7CCA89B9, |
|
| 718 | + 0x1A69E783, 0x02CC4843, 0xA2F7C579, 0x429EF47D, |
|
| 719 | + 0x427B169C, 0x5AC9F049, 0xDD8F0F00, 0x5C8165BF |
|
| 720 | + ); |
|
| 721 | + |
|
| 722 | + // 256 unsigned 32 bit integers |
|
| 723 | + self::$_s2 = array( |
|
| 724 | + 0x1F201094, 0xEF0BA75B, 0x69E3CF7E, 0x393F4380, |
|
| 725 | + 0xFE61CF7A, 0xEEC5207A, 0x55889C94, 0x72FC0651, |
|
| 726 | + 0xADA7EF79, 0x4E1D7235, 0xD55A63CE, 0xDE0436BA, |
|
| 727 | + 0x99C430EF, 0x5F0C0794, 0x18DCDB7D, 0xA1D6EFF3, |
|
| 728 | + 0xA0B52F7B, 0x59E83605, 0xEE15B094, 0xE9FFD909, |
|
| 729 | + 0xDC440086, 0xEF944459, 0xBA83CCB3, 0xE0C3CDFB, |
|
| 730 | + 0xD1DA4181, 0x3B092AB1, 0xF997F1C1, 0xA5E6CF7B, |
|
| 731 | + 0x01420DDB, 0xE4E7EF5B, 0x25A1FF41, 0xE180F806, |
|
| 732 | + 0x1FC41080, 0x179BEE7A, 0xD37AC6A9, 0xFE5830A4, |
|
| 733 | + 0x98DE8B7F, 0x77E83F4E, 0x79929269, 0x24FA9F7B, |
|
| 734 | + 0xE113C85B, 0xACC40083, 0xD7503525, 0xF7EA615F, |
|
| 735 | + 0x62143154, 0x0D554B63, 0x5D681121, 0xC866C359, |
|
| 736 | + 0x3D63CF73, 0xCEE234C0, 0xD4D87E87, 0x5C672B21, |
|
| 737 | + 0x071F6181, 0x39F7627F, 0x361E3084, 0xE4EB573B, |
|
| 738 | + 0x602F64A4, 0xD63ACD9C, 0x1BBC4635, 0x9E81032D, |
|
| 739 | + 0x2701F50C, 0x99847AB4, 0xA0E3DF79, 0xBA6CF38C, |
|
| 740 | + 0x10843094, 0x2537A95E, 0xF46F6FFE, 0xA1FF3B1F, |
|
| 741 | + 0x208CFB6A, 0x8F458C74, 0xD9E0A227, 0x4EC73A34, |
|
| 742 | + 0xFC884F69, 0x3E4DE8DF, 0xEF0E0088, 0x3559648D, |
|
| 743 | + 0x8A45388C, 0x1D804366, 0x721D9BFD, 0xA58684BB, |
|
| 744 | + 0xE8256333, 0x844E8212, 0x128D8098, 0xFED33FB4, |
|
| 745 | + 0xCE280AE1, 0x27E19BA5, 0xD5A6C252, 0xE49754BD, |
|
| 746 | + 0xC5D655DD, 0xEB667064, 0x77840B4D, 0xA1B6A801, |
|
| 747 | + 0x84DB26A9, 0xE0B56714, 0x21F043B7, 0xE5D05860, |
|
| 748 | + 0x54F03084, 0x066FF472, 0xA31AA153, 0xDADC4755, |
|
| 749 | + 0xB5625DBF, 0x68561BE6, 0x83CA6B94, 0x2D6ED23B, |
|
| 750 | + 0xECCF01DB, 0xA6D3D0BA, 0xB6803D5C, 0xAF77A709, |
|
| 751 | + 0x33B4A34C, 0x397BC8D6, 0x5EE22B95, 0x5F0E5304, |
|
| 752 | + 0x81ED6F61, 0x20E74364, 0xB45E1378, 0xDE18639B, |
|
| 753 | + 0x881CA122, 0xB96726D1, 0x8049A7E8, 0x22B7DA7B, |
|
| 754 | + 0x5E552D25, 0x5272D237, 0x79D2951C, 0xC60D894C, |
|
| 755 | + 0x488CB402, 0x1BA4FE5B, 0xA4B09F6B, 0x1CA815CF, |
|
| 756 | + 0xA20C3005, 0x8871DF63, 0xB9DE2FCB, 0x0CC6C9E9, |
|
| 757 | + 0x0BEEFF53, 0xE3214517, 0xB4542835, 0x9F63293C, |
|
| 758 | + 0xEE41E729, 0x6E1D2D7C, 0x50045286, 0x1E6685F3, |
|
| 759 | + 0xF33401C6, 0x30A22C95, 0x31A70850, 0x60930F13, |
|
| 760 | + 0x73F98417, 0xA1269859, 0xEC645C44, 0x52C877A9, |
|
| 761 | + 0xCDFF33A6, 0xA02B1741, 0x7CBAD9A2, 0x2180036F, |
|
| 762 | + 0x50D99C08, 0xCB3F4861, 0xC26BD765, 0x64A3F6AB, |
|
| 763 | + 0x80342676, 0x25A75E7B, 0xE4E6D1FC, 0x20C710E6, |
|
| 764 | + 0xCDF0B680, 0x17844D3B, 0x31EEF84D, 0x7E0824E4, |
|
| 765 | + 0x2CCB49EB, 0x846A3BAE, 0x8FF77888, 0xEE5D60F6, |
|
| 766 | + 0x7AF75673, 0x2FDD5CDB, 0xA11631C1, 0x30F66F43, |
|
| 767 | + 0xB3FAEC54, 0x157FD7FA, 0xEF8579CC, 0xD152DE58, |
|
| 768 | + 0xDB2FFD5E, 0x8F32CE19, 0x306AF97A, 0x02F03EF8, |
|
| 769 | + 0x99319AD5, 0xC242FA0F, 0xA7E3EBB0, 0xC68E4906, |
|
| 770 | + 0xB8DA230C, 0x80823028, 0xDCDEF3C8, 0xD35FB171, |
|
| 771 | + 0x088A1BC8, 0xBEC0C560, 0x61A3C9E8, 0xBCA8F54D, |
|
| 772 | + 0xC72FEFFA, 0x22822E99, 0x82C570B4, 0xD8D94E89, |
|
| 773 | + 0x8B1C34BC, 0x301E16E6, 0x273BE979, 0xB0FFEAA6, |
|
| 774 | + 0x61D9B8C6, 0x00B24869, 0xB7FFCE3F, 0x08DC283B, |
|
| 775 | + 0x43DAF65A, 0xF7E19798, 0x7619B72F, 0x8F1C9BA4, |
|
| 776 | + 0xDC8637A0, 0x16A7D3B1, 0x9FC393B7, 0xA7136EEB, |
|
| 777 | + 0xC6BCC63E, 0x1A513742, 0xEF6828BC, 0x520365D6, |
|
| 778 | + 0x2D6A77AB, 0x3527ED4B, 0x821FD216, 0x095C6E2E, |
|
| 779 | + 0xDB92F2FB, 0x5EEA29CB, 0x145892F5, 0x91584F7F, |
|
| 780 | + 0x5483697B, 0x2667A8CC, 0x85196048, 0x8C4BACEA, |
|
| 781 | + 0x833860D4, 0x0D23E0F9, 0x6C387E8A, 0x0AE6D249, |
|
| 782 | + 0xB284600C, 0xD835731D, 0xDCB1C647, 0xAC4C56EA, |
|
| 783 | + 0x3EBD81B3, 0x230EABB0, 0x6438BC87, 0xF0B5B1FA, |
|
| 784 | + 0x8F5EA2B3, 0xFC184642, 0x0A036B7A, 0x4FB089BD, |
|
| 785 | + 0x649DA589, 0xA345415E, 0x5C038323, 0x3E5D3BB9, |
|
| 786 | + 0x43D79572, 0x7E6DD07C, 0x06DFDF1E, 0x6C6CC4EF, |
|
| 787 | + 0x7160A539, 0x73BFBE70, 0x83877605, 0x4523ECF1 |
|
| 788 | + ); |
|
| 789 | + |
|
| 790 | + // 256 unsigned 32 bit integers |
|
| 791 | + self::$_s3 = array( |
|
| 792 | + 0x8DEFC240, 0x25FA5D9F, 0xEB903DBF, 0xE810C907, |
|
| 793 | + 0x47607FFF, 0x369FE44B, 0x8C1FC644, 0xAECECA90, |
|
| 794 | + 0xBEB1F9BF, 0xEEFBCAEA, 0xE8CF1950, 0x51DF07AE, |
|
| 795 | + 0x920E8806, 0xF0AD0548, 0xE13C8D83, 0x927010D5, |
|
| 796 | + 0x11107D9F, 0x07647DB9, 0xB2E3E4D4, 0x3D4F285E, |
|
| 797 | + 0xB9AFA820, 0xFADE82E0, 0xA067268B, 0x8272792E, |
|
| 798 | + 0x553FB2C0, 0x489AE22B, 0xD4EF9794, 0x125E3FBC, |
|
| 799 | + 0x21FFFCEE, 0x825B1BFD, 0x9255C5ED, 0x1257A240, |
|
| 800 | + 0x4E1A8302, 0xBAE07FFF, 0x528246E7, 0x8E57140E, |
|
| 801 | + 0x3373F7BF, 0x8C9F8188, 0xA6FC4EE8, 0xC982B5A5, |
|
| 802 | + 0xA8C01DB7, 0x579FC264, 0x67094F31, 0xF2BD3F5F, |
|
| 803 | + 0x40FFF7C1, 0x1FB78DFC, 0x8E6BD2C1, 0x437BE59B, |
|
| 804 | + 0x99B03DBF, 0xB5DBC64B, 0x638DC0E6, 0x55819D99, |
|
| 805 | + 0xA197C81C, 0x4A012D6E, 0xC5884A28, 0xCCC36F71, |
|
| 806 | + 0xB843C213, 0x6C0743F1, 0x8309893C, 0x0FEDDD5F, |
|
| 807 | + 0x2F7FE850, 0xD7C07F7E, 0x02507FBF, 0x5AFB9A04, |
|
| 808 | + 0xA747D2D0, 0x1651192E, 0xAF70BF3E, 0x58C31380, |
|
| 809 | + 0x5F98302E, 0x727CC3C4, 0x0A0FB402, 0x0F7FEF82, |
|
| 810 | + 0x8C96FDAD, 0x5D2C2AAE, 0x8EE99A49, 0x50DA88B8, |
|
| 811 | + 0x8427F4A0, 0x1EAC5790, 0x796FB449, 0x8252DC15, |
|
| 812 | + 0xEFBD7D9B, 0xA672597D, 0xADA840D8, 0x45F54504, |
|
| 813 | + 0xFA5D7403, 0xE83EC305, 0x4F91751A, 0x925669C2, |
|
| 814 | + 0x23EFE941, 0xA903F12E, 0x60270DF2, 0x0276E4B6, |
|
| 815 | + 0x94FD6574, 0x927985B2, 0x8276DBCB, 0x02778176, |
|
| 816 | + 0xF8AF918D, 0x4E48F79E, 0x8F616DDF, 0xE29D840E, |
|
| 817 | + 0x842F7D83, 0x340CE5C8, 0x96BBB682, 0x93B4B148, |
|
| 818 | + 0xEF303CAB, 0x984FAF28, 0x779FAF9B, 0x92DC560D, |
|
| 819 | + 0x224D1E20, 0x8437AA88, 0x7D29DC96, 0x2756D3DC, |
|
| 820 | + 0x8B907CEE, 0xB51FD240, 0xE7C07CE3, 0xE566B4A1, |
|
| 821 | + 0xC3E9615E, 0x3CF8209D, 0x6094D1E3, 0xCD9CA341, |
|
| 822 | + 0x5C76460E, 0x00EA983B, 0xD4D67881, 0xFD47572C, |
|
| 823 | + 0xF76CEDD9, 0xBDA8229C, 0x127DADAA, 0x438A074E, |
|
| 824 | + 0x1F97C090, 0x081BDB8A, 0x93A07EBE, 0xB938CA15, |
|
| 825 | + 0x97B03CFF, 0x3DC2C0F8, 0x8D1AB2EC, 0x64380E51, |
|
| 826 | + 0x68CC7BFB, 0xD90F2788, 0x12490181, 0x5DE5FFD4, |
|
| 827 | + 0xDD7EF86A, 0x76A2E214, 0xB9A40368, 0x925D958F, |
|
| 828 | + 0x4B39FFFA, 0xBA39AEE9, 0xA4FFD30B, 0xFAF7933B, |
|
| 829 | + 0x6D498623, 0x193CBCFA, 0x27627545, 0x825CF47A, |
|
| 830 | + 0x61BD8BA0, 0xD11E42D1, 0xCEAD04F4, 0x127EA392, |
|
| 831 | + 0x10428DB7, 0x8272A972, 0x9270C4A8, 0x127DE50B, |
|
| 832 | + 0x285BA1C8, 0x3C62F44F, 0x35C0EAA5, 0xE805D231, |
|
| 833 | + 0x428929FB, 0xB4FCDF82, 0x4FB66A53, 0x0E7DC15B, |
|
| 834 | + 0x1F081FAB, 0x108618AE, 0xFCFD086D, 0xF9FF2889, |
|
| 835 | + 0x694BCC11, 0x236A5CAE, 0x12DECA4D, 0x2C3F8CC5, |
|
| 836 | + 0xD2D02DFE, 0xF8EF5896, 0xE4CF52DA, 0x95155B67, |
|
| 837 | + 0x494A488C, 0xB9B6A80C, 0x5C8F82BC, 0x89D36B45, |
|
| 838 | + 0x3A609437, 0xEC00C9A9, 0x44715253, 0x0A874B49, |
|
| 839 | + 0xD773BC40, 0x7C34671C, 0x02717EF6, 0x4FEB5536, |
|
| 840 | + 0xA2D02FFF, 0xD2BF60C4, 0xD43F03C0, 0x50B4EF6D, |
|
| 841 | + 0x07478CD1, 0x006E1888, 0xA2E53F55, 0xB9E6D4BC, |
|
| 842 | + 0xA2048016, 0x97573833, 0xD7207D67, 0xDE0F8F3D, |
|
| 843 | + 0x72F87B33, 0xABCC4F33, 0x7688C55D, 0x7B00A6B0, |
|
| 844 | + 0x947B0001, 0x570075D2, 0xF9BB88F8, 0x8942019E, |
|
| 845 | + 0x4264A5FF, 0x856302E0, 0x72DBD92B, 0xEE971B69, |
|
| 846 | + 0x6EA22FDE, 0x5F08AE2B, 0xAF7A616D, 0xE5C98767, |
|
| 847 | + 0xCF1FEBD2, 0x61EFC8C2, 0xF1AC2571, 0xCC8239C2, |
|
| 848 | + 0x67214CB8, 0xB1E583D1, 0xB7DC3E62, 0x7F10BDCE, |
|
| 849 | + 0xF90A5C38, 0x0FF0443D, 0x606E6DC6, 0x60543A49, |
|
| 850 | + 0x5727C148, 0x2BE98A1D, 0x8AB41738, 0x20E1BE24, |
|
| 851 | + 0xAF96DA0F, 0x68458425, 0x99833BE5, 0x600D457D, |
|
| 852 | + 0x282F9350, 0x8334B362, 0xD91D1120, 0x2B6D8DA0, |
|
| 853 | + 0x642B1E31, 0x9C305A00, 0x52BCE688, 0x1B03588A, |
|
| 854 | + 0xF7BAEFD5, 0x4142ED9C, 0xA4315C11, 0x83323EC5, |
|
| 855 | + 0xDFEF4636, 0xA133C501, 0xE9D3531C, 0xEE353783 |
|
| 856 | + ); |
|
| 857 | + |
|
| 858 | + // 256 unsigned 32 bit integers |
|
| 859 | + self::$_s4 = array( |
|
| 860 | + 0x9DB30420, 0x1FB6E9DE, 0xA7BE7BEF, 0xD273A298, |
|
| 861 | + 0x4A4F7BDB, 0x64AD8C57, 0x85510443, 0xFA020ED1, |
|
| 862 | + 0x7E287AFF, 0xE60FB663, 0x095F35A1, 0x79EBF120, |
|
| 863 | + 0xFD059D43, 0x6497B7B1, 0xF3641F63, 0x241E4ADF, |
|
| 864 | + 0x28147F5F, 0x4FA2B8CD, 0xC9430040, 0x0CC32220, |
|
| 865 | + 0xFDD30B30, 0xC0A5374F, 0x1D2D00D9, 0x24147B15, |
|
| 866 | + 0xEE4D111A, 0x0FCA5167, 0x71FF904C, 0x2D195FFE, |
|
| 867 | + 0x1A05645F, 0x0C13FEFE, 0x081B08CA, 0x05170121, |
|
| 868 | + 0x80530100, 0xE83E5EFE, 0xAC9AF4F8, 0x7FE72701, |
|
| 869 | + 0xD2B8EE5F, 0x06DF4261, 0xBB9E9B8A, 0x7293EA25, |
|
| 870 | + 0xCE84FFDF, 0xF5718801, 0x3DD64B04, 0xA26F263B, |
|
| 871 | + 0x7ED48400, 0x547EEBE6, 0x446D4CA0, 0x6CF3D6F5, |
|
| 872 | + 0x2649ABDF, 0xAEA0C7F5, 0x36338CC1, 0x503F7E93, |
|
| 873 | + 0xD3772061, 0x11B638E1, 0x72500E03, 0xF80EB2BB, |
|
| 874 | + 0xABE0502E, 0xEC8D77DE, 0x57971E81, 0xE14F6746, |
|
| 875 | + 0xC9335400, 0x6920318F, 0x081DBB99, 0xFFC304A5, |
|
| 876 | + 0x4D351805, 0x7F3D5CE3, 0xA6C866C6, 0x5D5BCCA9, |
|
| 877 | + 0xDAEC6FEA, 0x9F926F91, 0x9F46222F, 0x3991467D, |
|
| 878 | + 0xA5BF6D8E, 0x1143C44F, 0x43958302, 0xD0214EEB, |
|
| 879 | + 0x022083B8, 0x3FB6180C, 0x18F8931E, 0x281658E6, |
|
| 880 | + 0x26486E3E, 0x8BD78A70, 0x7477E4C1, 0xB506E07C, |
|
| 881 | + 0xF32D0A25, 0x79098B02, 0xE4EABB81, 0x28123B23, |
|
| 882 | + 0x69DEAD38, 0x1574CA16, 0xDF871B62, 0x211C40B7, |
|
| 883 | + 0xA51A9EF9, 0x0014377B, 0x041E8AC8, 0x09114003, |
|
| 884 | + 0xBD59E4D2, 0xE3D156D5, 0x4FE876D5, 0x2F91A340, |
|
| 885 | + 0x557BE8DE, 0x00EAE4A7, 0x0CE5C2EC, 0x4DB4BBA6, |
|
| 886 | + 0xE756BDFF, 0xDD3369AC, 0xEC17B035, 0x06572327, |
|
| 887 | + 0x99AFC8B0, 0x56C8C391, 0x6B65811C, 0x5E146119, |
|
| 888 | + 0x6E85CB75, 0xBE07C002, 0xC2325577, 0x893FF4EC, |
|
| 889 | + 0x5BBFC92D, 0xD0EC3B25, 0xB7801AB7, 0x8D6D3B24, |
|
| 890 | + 0x20C763EF, 0xC366A5FC, 0x9C382880, 0x0ACE3205, |
|
| 891 | + 0xAAC9548A, 0xECA1D7C7, 0x041AFA32, 0x1D16625A, |
|
| 892 | + 0x6701902C, 0x9B757A54, 0x31D477F7, 0x9126B031, |
|
| 893 | + 0x36CC6FDB, 0xC70B8B46, 0xD9E66A48, 0x56E55A79, |
|
| 894 | + 0x026A4CEB, 0x52437EFF, 0x2F8F76B4, 0x0DF980A5, |
|
| 895 | + 0x8674CDE3, 0xEDDA04EB, 0x17A9BE04, 0x2C18F4DF, |
|
| 896 | + 0xB7747F9D, 0xAB2AF7B4, 0xEFC34D20, 0x2E096B7C, |
|
| 897 | + 0x1741A254, 0xE5B6A035, 0x213D42F6, 0x2C1C7C26, |
|
| 898 | + 0x61C2F50F, 0x6552DAF9, 0xD2C231F8, 0x25130F69, |
|
| 899 | + 0xD8167FA2, 0x0418F2C8, 0x001A96A6, 0x0D1526AB, |
|
| 900 | + 0x63315C21, 0x5E0A72EC, 0x49BAFEFD, 0x187908D9, |
|
| 901 | + 0x8D0DBD86, 0x311170A7, 0x3E9B640C, 0xCC3E10D7, |
|
| 902 | + 0xD5CAD3B6, 0x0CAEC388, 0xF73001E1, 0x6C728AFF, |
|
| 903 | + 0x71EAE2A1, 0x1F9AF36E, 0xCFCBD12F, 0xC1DE8417, |
|
| 904 | + 0xAC07BE6B, 0xCB44A1D8, 0x8B9B0F56, 0x013988C3, |
|
| 905 | + 0xB1C52FCA, 0xB4BE31CD, 0xD8782806, 0x12A3A4E2, |
|
| 906 | + 0x6F7DE532, 0x58FD7EB6, 0xD01EE900, 0x24ADFFC2, |
|
| 907 | + 0xF4990FC5, 0x9711AAC5, 0x001D7B95, 0x82E5E7D2, |
|
| 908 | + 0x109873F6, 0x00613096, 0xC32D9521, 0xADA121FF, |
|
| 909 | + 0x29908415, 0x7FBB977F, 0xAF9EB3DB, 0x29C9ED2A, |
|
| 910 | + 0x5CE2A465, 0xA730F32C, 0xD0AA3FE8, 0x8A5CC091, |
|
| 911 | + 0xD49E2CE7, 0x0CE454A9, 0xD60ACD86, 0x015F1919, |
|
| 912 | + 0x77079103, 0xDEA03AF6, 0x78A8565E, 0xDEE356DF, |
|
| 913 | + 0x21F05CBE, 0x8B75E387, 0xB3C50651, 0xB8A5C3EF, |
|
| 914 | + 0xD8EEB6D2, 0xE523BE77, 0xC2154529, 0x2F69EFDF, |
|
| 915 | + 0xAFE67AFB, 0xF470C4B2, 0xF3E0EB5B, 0xD6CC9876, |
|
| 916 | + 0x39E4460C, 0x1FDA8538, 0x1987832F, 0xCA007367, |
|
| 917 | + 0xA99144F8, 0x296B299E, 0x492FC295, 0x9266BEAB, |
|
| 918 | + 0xB5676E69, 0x9BD3DDDA, 0xDF7E052F, 0xDB25701C, |
|
| 919 | + 0x1B5E51EE, 0xF65324E6, 0x6AFCE36C, 0x0316CC04, |
|
| 920 | + 0x8644213E, 0xB7DC59D0, 0x7965291F, 0xCCD6FD43, |
|
| 921 | + 0x41823979, 0x932BCDF6, 0xB657C34D, 0x4EDFD282, |
|
| 922 | + 0x7AE5290C, 0x3CB9536B, 0x851E20FE, 0x9833557E, |
|
| 923 | + 0x13ECF0B0, 0xD3FFB372, 0x3F85C5C1, 0x0AEF7ED2 |
|
| 924 | + ); |
|
| 925 | + |
|
| 926 | + // 256 unsigned 32 bit integers |
|
| 927 | + self::$_s5 = array( |
|
| 928 | + 0x7EC90C04, 0x2C6E74B9, 0x9B0E66DF, 0xA6337911, |
|
| 929 | + 0xB86A7FFF, 0x1DD358F5, 0x44DD9D44, 0x1731167F, |
|
| 930 | + 0x08FBF1FA, 0xE7F511CC, 0xD2051B00, 0x735ABA00, |
|
| 931 | + 0x2AB722D8, 0x386381CB, 0xACF6243A, 0x69BEFD7A, |
|
| 932 | + 0xE6A2E77F, 0xF0C720CD, 0xC4494816, 0xCCF5C180, |
|
| 933 | + 0x38851640, 0x15B0A848, 0xE68B18CB, 0x4CAADEFF, |
|
| 934 | + 0x5F480A01, 0x0412B2AA, 0x259814FC, 0x41D0EFE2, |
|
| 935 | + 0x4E40B48D, 0x248EB6FB, 0x8DBA1CFE, 0x41A99B02, |
|
| 936 | + 0x1A550A04, 0xBA8F65CB, 0x7251F4E7, 0x95A51725, |
|
| 937 | + 0xC106ECD7, 0x97A5980A, 0xC539B9AA, 0x4D79FE6A, |
|
| 938 | + 0xF2F3F763, 0x68AF8040, 0xED0C9E56, 0x11B4958B, |
|
| 939 | + 0xE1EB5A88, 0x8709E6B0, 0xD7E07156, 0x4E29FEA7, |
|
| 940 | + 0x6366E52D, 0x02D1C000, 0xC4AC8E05, 0x9377F571, |
|
| 941 | + 0x0C05372A, 0x578535F2, 0x2261BE02, 0xD642A0C9, |
|
| 942 | + 0xDF13A280, 0x74B55BD2, 0x682199C0, 0xD421E5EC, |
|
| 943 | + 0x53FB3CE8, 0xC8ADEDB3, 0x28A87FC9, 0x3D959981, |
|
| 944 | + 0x5C1FF900, 0xFE38D399, 0x0C4EFF0B, 0x062407EA, |
|
| 945 | + 0xAA2F4FB1, 0x4FB96976, 0x90C79505, 0xB0A8A774, |
|
| 946 | + 0xEF55A1FF, 0xE59CA2C2, 0xA6B62D27, 0xE66A4263, |
|
| 947 | + 0xDF65001F, 0x0EC50966, 0xDFDD55BC, 0x29DE0655, |
|
| 948 | + 0x911E739A, 0x17AF8975, 0x32C7911C, 0x89F89468, |
|
| 949 | + 0x0D01E980, 0x524755F4, 0x03B63CC9, 0x0CC844B2, |
|
| 950 | + 0xBCF3F0AA, 0x87AC36E9, 0xE53A7426, 0x01B3D82B, |
|
| 951 | + 0x1A9E7449, 0x64EE2D7E, 0xCDDBB1DA, 0x01C94910, |
|
| 952 | + 0xB868BF80, 0x0D26F3FD, 0x9342EDE7, 0x04A5C284, |
|
| 953 | + 0x636737B6, 0x50F5B616, 0xF24766E3, 0x8ECA36C1, |
|
| 954 | + 0x136E05DB, 0xFEF18391, 0xFB887A37, 0xD6E7F7D4, |
|
| 955 | + 0xC7FB7DC9, 0x3063FCDF, 0xB6F589DE, 0xEC2941DA, |
|
| 956 | + 0x26E46695, 0xB7566419, 0xF654EFC5, 0xD08D58B7, |
|
| 957 | + 0x48925401, 0xC1BACB7F, 0xE5FF550F, 0xB6083049, |
|
| 958 | + 0x5BB5D0E8, 0x87D72E5A, 0xAB6A6EE1, 0x223A66CE, |
|
| 959 | + 0xC62BF3CD, 0x9E0885F9, 0x68CB3E47, 0x086C010F, |
|
| 960 | + 0xA21DE820, 0xD18B69DE, 0xF3F65777, 0xFA02C3F6, |
|
| 961 | + 0x407EDAC3, 0xCBB3D550, 0x1793084D, 0xB0D70EBA, |
|
| 962 | + 0x0AB378D5, 0xD951FB0C, 0xDED7DA56, 0x4124BBE4, |
|
| 963 | + 0x94CA0B56, 0x0F5755D1, 0xE0E1E56E, 0x6184B5BE, |
|
| 964 | + 0x580A249F, 0x94F74BC0, 0xE327888E, 0x9F7B5561, |
|
| 965 | + 0xC3DC0280, 0x05687715, 0x646C6BD7, 0x44904DB3, |
|
| 966 | + 0x66B4F0A3, 0xC0F1648A, 0x697ED5AF, 0x49E92FF6, |
|
| 967 | + 0x309E374F, 0x2CB6356A, 0x85808573, 0x4991F840, |
|
| 968 | + 0x76F0AE02, 0x083BE84D, 0x28421C9A, 0x44489406, |
|
| 969 | + 0x736E4CB8, 0xC1092910, 0x8BC95FC6, 0x7D869CF4, |
|
| 970 | + 0x134F616F, 0x2E77118D, 0xB31B2BE1, 0xAA90B472, |
|
| 971 | + 0x3CA5D717, 0x7D161BBA, 0x9CAD9010, 0xAF462BA2, |
|
| 972 | + 0x9FE459D2, 0x45D34559, 0xD9F2DA13, 0xDBC65487, |
|
| 973 | + 0xF3E4F94E, 0x176D486F, 0x097C13EA, 0x631DA5C7, |
|
| 974 | + 0x445F7382, 0x175683F4, 0xCDC66A97, 0x70BE0288, |
|
| 975 | + 0xB3CDCF72, 0x6E5DD2F3, 0x20936079, 0x459B80A5, |
|
| 976 | + 0xBE60E2DB, 0xA9C23101, 0xEBA5315C, 0x224E42F2, |
|
| 977 | + 0x1C5C1572, 0xF6721B2C, 0x1AD2FFF3, 0x8C25404E, |
|
| 978 | + 0x324ED72F, 0x4067B7FD, 0x0523138E, 0x5CA3BC78, |
|
| 979 | + 0xDC0FD66E, 0x75922283, 0x784D6B17, 0x58EBB16E, |
|
| 980 | + 0x44094F85, 0x3F481D87, 0xFCFEAE7B, 0x77B5FF76, |
|
| 981 | + 0x8C2302BF, 0xAAF47556, 0x5F46B02A, 0x2B092801, |
|
| 982 | + 0x3D38F5F7, 0x0CA81F36, 0x52AF4A8A, 0x66D5E7C0, |
|
| 983 | + 0xDF3B0874, 0x95055110, 0x1B5AD7A8, 0xF61ED5AD, |
|
| 984 | + 0x6CF6E479, 0x20758184, 0xD0CEFA65, 0x88F7BE58, |
|
| 985 | + 0x4A046826, 0x0FF6F8F3, 0xA09C7F70, 0x5346ABA0, |
|
| 986 | + 0x5CE96C28, 0xE176EDA3, 0x6BAC307F, 0x376829D2, |
|
| 987 | + 0x85360FA9, 0x17E3FE2A, 0x24B79767, 0xF5A96B20, |
|
| 988 | + 0xD6CD2595, 0x68FF1EBF, 0x7555442C, 0xF19F06BE, |
|
| 989 | + 0xF9E0659A, 0xEEB9491D, 0x34010718, 0xBB30CAB8, |
|
| 990 | + 0xE822FE15, 0x88570983, 0x750E6249, 0xDA627E55, |
|
| 991 | + 0x5E76FFA8, 0xB1534546, 0x6D47DE08, 0xEFE9E7D4 |
|
| 992 | + ); |
|
| 993 | + |
|
| 994 | + // 256 unsigned 32 bit integers |
|
| 995 | + self::$_s6 = array( |
|
| 996 | + 0xF6FA8F9D, 0x2CAC6CE1, 0x4CA34867, 0xE2337F7C, |
|
| 997 | + 0x95DB08E7, 0x016843B4, 0xECED5CBC, 0x325553AC, |
|
| 998 | + 0xBF9F0960, 0xDFA1E2ED, 0x83F0579D, 0x63ED86B9, |
|
| 999 | + 0x1AB6A6B8, 0xDE5EBE39, 0xF38FF732, 0x8989B138, |
|
| 1000 | + 0x33F14961, 0xC01937BD, 0xF506C6DA, 0xE4625E7E, |
|
| 1001 | + 0xA308EA99, 0x4E23E33C, 0x79CBD7CC, 0x48A14367, |
|
| 1002 | + 0xA3149619, 0xFEC94BD5, 0xA114174A, 0xEAA01866, |
|
| 1003 | + 0xA084DB2D, 0x09A8486F, 0xA888614A, 0x2900AF98, |
|
| 1004 | + 0x01665991, 0xE1992863, 0xC8F30C60, 0x2E78EF3C, |
|
| 1005 | + 0xD0D51932, 0xCF0FEC14, 0xF7CA07D2, 0xD0A82072, |
|
| 1006 | + 0xFD41197E, 0x9305A6B0, 0xE86BE3DA, 0x74BED3CD, |
|
| 1007 | + 0x372DA53C, 0x4C7F4448, 0xDAB5D440, 0x6DBA0EC3, |
|
| 1008 | + 0x083919A7, 0x9FBAEED9, 0x49DBCFB0, 0x4E670C53, |
|
| 1009 | + 0x5C3D9C01, 0x64BDB941, 0x2C0E636A, 0xBA7DD9CD, |
|
| 1010 | + 0xEA6F7388, 0xE70BC762, 0x35F29ADB, 0x5C4CDD8D, |
|
| 1011 | + 0xF0D48D8C, 0xB88153E2, 0x08A19866, 0x1AE2EAC8, |
|
| 1012 | + 0x284CAF89, 0xAA928223, 0x9334BE53, 0x3B3A21BF, |
|
| 1013 | + 0x16434BE3, 0x9AEA3906, 0xEFE8C36E, 0xF890CDD9, |
|
| 1014 | + 0x80226DAE, 0xC340A4A3, 0xDF7E9C09, 0xA694A807, |
|
| 1015 | + 0x5B7C5ECC, 0x221DB3A6, 0x9A69A02F, 0x68818A54, |
|
| 1016 | + 0xCEB2296F, 0x53C0843A, 0xFE893655, 0x25BFE68A, |
|
| 1017 | + 0xB4628ABC, 0xCF222EBF, 0x25AC6F48, 0xA9A99387, |
|
| 1018 | + 0x53BDDB65, 0xE76FFBE7, 0xE967FD78, 0x0BA93563, |
|
| 1019 | + 0x8E342BC1, 0xE8A11BE9, 0x4980740D, 0xC8087DFC, |
|
| 1020 | + 0x8DE4BF99, 0xA11101A0, 0x7FD37975, 0xDA5A26C0, |
|
| 1021 | + 0xE81F994F, 0x9528CD89, 0xFD339FED, 0xB87834BF, |
|
| 1022 | + 0x5F04456D, 0x22258698, 0xC9C4C83B, 0x2DC156BE, |
|
| 1023 | + 0x4F628DAA, 0x57F55EC5, 0xE2220ABE, 0xD2916EBF, |
|
| 1024 | + 0x4EC75B95, 0x24F2C3C0, 0x42D15D99, 0xCD0D7FA0, |
|
| 1025 | + 0x7B6E27FF, 0xA8DC8AF0, 0x7345C106, 0xF41E232F, |
|
| 1026 | + 0x35162386, 0xE6EA8926, 0x3333B094, 0x157EC6F2, |
|
| 1027 | + 0x372B74AF, 0x692573E4, 0xE9A9D848, 0xF3160289, |
|
| 1028 | + 0x3A62EF1D, 0xA787E238, 0xF3A5F676, 0x74364853, |
|
| 1029 | + 0x20951063, 0x4576698D, 0xB6FAD407, 0x592AF950, |
|
| 1030 | + 0x36F73523, 0x4CFB6E87, 0x7DA4CEC0, 0x6C152DAA, |
|
| 1031 | + 0xCB0396A8, 0xC50DFE5D, 0xFCD707AB, 0x0921C42F, |
|
| 1032 | + 0x89DFF0BB, 0x5FE2BE78, 0x448F4F33, 0x754613C9, |
|
| 1033 | + 0x2B05D08D, 0x48B9D585, 0xDC049441, 0xC8098F9B, |
|
| 1034 | + 0x7DEDE786, 0xC39A3373, 0x42410005, 0x6A091751, |
|
| 1035 | + 0x0EF3C8A6, 0x890072D6, 0x28207682, 0xA9A9F7BE, |
|
| 1036 | + 0xBF32679D, 0xD45B5B75, 0xB353FD00, 0xCBB0E358, |
|
| 1037 | + 0x830F220A, 0x1F8FB214, 0xD372CF08, 0xCC3C4A13, |
|
| 1038 | + 0x8CF63166, 0x061C87BE, 0x88C98F88, 0x6062E397, |
|
| 1039 | + 0x47CF8E7A, 0xB6C85283, 0x3CC2ACFB, 0x3FC06976, |
|
| 1040 | + 0x4E8F0252, 0x64D8314D, 0xDA3870E3, 0x1E665459, |
|
| 1041 | + 0xC10908F0, 0x513021A5, 0x6C5B68B7, 0x822F8AA0, |
|
| 1042 | + 0x3007CD3E, 0x74719EEF, 0xDC872681, 0x073340D4, |
|
| 1043 | + 0x7E432FD9, 0x0C5EC241, 0x8809286C, 0xF592D891, |
|
| 1044 | + 0x08A930F6, 0x957EF305, 0xB7FBFFBD, 0xC266E96F, |
|
| 1045 | + 0x6FE4AC98, 0xB173ECC0, 0xBC60B42A, 0x953498DA, |
|
| 1046 | + 0xFBA1AE12, 0x2D4BD736, 0x0F25FAAB, 0xA4F3FCEB, |
|
| 1047 | + 0xE2969123, 0x257F0C3D, 0x9348AF49, 0x361400BC, |
|
| 1048 | + 0xE8816F4A, 0x3814F200, 0xA3F94043, 0x9C7A54C2, |
|
| 1049 | + 0xBC704F57, 0xDA41E7F9, 0xC25AD33A, 0x54F4A084, |
|
| 1050 | + 0xB17F5505, 0x59357CBE, 0xEDBD15C8, 0x7F97C5AB, |
|
| 1051 | + 0xBA5AC7B5, 0xB6F6DEAF, 0x3A479C3A, 0x5302DA25, |
|
| 1052 | + 0x653D7E6A, 0x54268D49, 0x51A477EA, 0x5017D55B, |
|
| 1053 | + 0xD7D25D88, 0x44136C76, 0x0404A8C8, 0xB8E5A121, |
|
| 1054 | + 0xB81A928A, 0x60ED5869, 0x97C55B96, 0xEAEC991B, |
|
| 1055 | + 0x29935913, 0x01FDB7F1, 0x088E8DFA, 0x9AB6F6F5, |
|
| 1056 | + 0x3B4CBF9F, 0x4A5DE3AB, 0xE6051D35, 0xA0E1D855, |
|
| 1057 | + 0xD36B4CF1, 0xF544EDEB, 0xB0E93524, 0xBEBB8FBD, |
|
| 1058 | + 0xA2D762CF, 0x49C92F54, 0x38B5F331, 0x7128A454, |
|
| 1059 | + 0x48392905, 0xA65B1DB8, 0x851C97BD, 0xD675CF2F |
|
| 1060 | + ); |
|
| 1061 | + |
|
| 1062 | + // 256 unsigned 32 bit integers |
|
| 1063 | + self::$_s7 = array( |
|
| 1064 | + 0x85E04019, 0x332BF567, 0x662DBFFF, 0xCFC65693, |
|
| 1065 | + 0x2A8D7F6F, 0xAB9BC912, 0xDE6008A1, 0x2028DA1F, |
|
| 1066 | + 0x0227BCE7, 0x4D642916, 0x18FAC300, 0x50F18B82, |
|
| 1067 | + 0x2CB2CB11, 0xB232E75C, 0x4B3695F2, 0xB28707DE, |
|
| 1068 | + 0xA05FBCF6, 0xCD4181E9, 0xE150210C, 0xE24EF1BD, |
|
| 1069 | + 0xB168C381, 0xFDE4E789, 0x5C79B0D8, 0x1E8BFD43, |
|
| 1070 | + 0x4D495001, 0x38BE4341, 0x913CEE1D, 0x92A79C3F, |
|
| 1071 | + 0x089766BE, 0xBAEEADF4, 0x1286BECF, 0xB6EACB19, |
|
| 1072 | + 0x2660C200, 0x7565BDE4, 0x64241F7A, 0x8248DCA9, |
|
| 1073 | + 0xC3B3AD66, 0x28136086, 0x0BD8DFA8, 0x356D1CF2, |
|
| 1074 | + 0x107789BE, 0xB3B2E9CE, 0x0502AA8F, 0x0BC0351E, |
|
| 1075 | + 0x166BF52A, 0xEB12FF82, 0xE3486911, 0xD34D7516, |
|
| 1076 | + 0x4E7B3AFF, 0x5F43671B, 0x9CF6E037, 0x4981AC83, |
|
| 1077 | + 0x334266CE, 0x8C9341B7, 0xD0D854C0, 0xCB3A6C88, |
|
| 1078 | + 0x47BC2829, 0x4725BA37, 0xA66AD22B, 0x7AD61F1E, |
|
| 1079 | + 0x0C5CBAFA, 0x4437F107, 0xB6E79962, 0x42D2D816, |
|
| 1080 | + 0x0A961288, 0xE1A5C06E, 0x13749E67, 0x72FC081A, |
|
| 1081 | + 0xB1D139F7, 0xF9583745, 0xCF19DF58, 0xBEC3F756, |
|
| 1082 | + 0xC06EBA30, 0x07211B24, 0x45C28829, 0xC95E317F, |
|
| 1083 | + 0xBC8EC511, 0x38BC46E9, 0xC6E6FA14, 0xBAE8584A, |
|
| 1084 | + 0xAD4EBC46, 0x468F508B, 0x7829435F, 0xF124183B, |
|
| 1085 | + 0x821DBA9F, 0xAFF60FF4, 0xEA2C4E6D, 0x16E39264, |
|
| 1086 | + 0x92544A8B, 0x009B4FC3, 0xABA68CED, 0x9AC96F78, |
|
| 1087 | + 0x06A5B79A, 0xB2856E6E, 0x1AEC3CA9, 0xBE838688, |
|
| 1088 | + 0x0E0804E9, 0x55F1BE56, 0xE7E5363B, 0xB3A1F25D, |
|
| 1089 | + 0xF7DEBB85, 0x61FE033C, 0x16746233, 0x3C034C28, |
|
| 1090 | + 0xDA6D0C74, 0x79AAC56C, 0x3CE4E1AD, 0x51F0C802, |
|
| 1091 | + 0x98F8F35A, 0x1626A49F, 0xEED82B29, 0x1D382FE3, |
|
| 1092 | + 0x0C4FB99A, 0xBB325778, 0x3EC6D97B, 0x6E77A6A9, |
|
| 1093 | + 0xCB658B5C, 0xD45230C7, 0x2BD1408B, 0x60C03EB7, |
|
| 1094 | + 0xB9068D78, 0xA33754F4, 0xF430C87D, 0xC8A71302, |
|
| 1095 | + 0xB96D8C32, 0xEBD4E7BE, 0xBE8B9D2D, 0x7979FB06, |
|
| 1096 | + 0xE7225308, 0x8B75CF77, 0x11EF8DA4, 0xE083C858, |
|
| 1097 | + 0x8D6B786F, 0x5A6317A6, 0xFA5CF7A0, 0x5DDA0033, |
|
| 1098 | + 0xF28EBFB0, 0xF5B9C310, 0xA0EAC280, 0x08B9767A, |
|
| 1099 | + 0xA3D9D2B0, 0x79D34217, 0x021A718D, 0x9AC6336A, |
|
| 1100 | + 0x2711FD60, 0x438050E3, 0x069908A8, 0x3D7FEDC4, |
|
| 1101 | + 0x826D2BEF, 0x4EEB8476, 0x488DCF25, 0x36C9D566, |
|
| 1102 | + 0x28E74E41, 0xC2610ACA, 0x3D49A9CF, 0xBAE3B9DF, |
|
| 1103 | + 0xB65F8DE6, 0x92AEAF64, 0x3AC7D5E6, 0x9EA80509, |
|
| 1104 | + 0xF22B017D, 0xA4173F70, 0xDD1E16C3, 0x15E0D7F9, |
|
| 1105 | + 0x50B1B887, 0x2B9F4FD5, 0x625ABA82, 0x6A017962, |
|
| 1106 | + 0x2EC01B9C, 0x15488AA9, 0xD716E740, 0x40055A2C, |
|
| 1107 | + 0x93D29A22, 0xE32DBF9A, 0x058745B9, 0x3453DC1E, |
|
| 1108 | + 0xD699296E, 0x496CFF6F, 0x1C9F4986, 0xDFE2ED07, |
|
| 1109 | + 0xB87242D1, 0x19DE7EAE, 0x053E561A, 0x15AD6F8C, |
|
| 1110 | + 0x66626C1C, 0x7154C24C, 0xEA082B2A, 0x93EB2939, |
|
| 1111 | + 0x17DCB0F0, 0x58D4F2AE, 0x9EA294FB, 0x52CF564C, |
|
| 1112 | + 0x9883FE66, 0x2EC40581, 0x763953C3, 0x01D6692E, |
|
| 1113 | + 0xD3A0C108, 0xA1E7160E, 0xE4F2DFA6, 0x693ED285, |
|
| 1114 | + 0x74904698, 0x4C2B0EDD, 0x4F757656, 0x5D393378, |
|
| 1115 | + 0xA132234F, 0x3D321C5D, 0xC3F5E194, 0x4B269301, |
|
| 1116 | + 0xC79F022F, 0x3C997E7E, 0x5E4F9504, 0x3FFAFBBD, |
|
| 1117 | + 0x76F7AD0E, 0x296693F4, 0x3D1FCE6F, 0xC61E45BE, |
|
| 1118 | + 0xD3B5AB34, 0xF72BF9B7, 0x1B0434C0, 0x4E72B567, |
|
| 1119 | + 0x5592A33D, 0xB5229301, 0xCFD2A87F, 0x60AEB767, |
|
| 1120 | + 0x1814386B, 0x30BCC33D, 0x38A0C07D, 0xFD1606F2, |
|
| 1121 | + 0xC363519B, 0x589DD390, 0x5479F8E6, 0x1CB8D647, |
|
| 1122 | + 0x97FD61A9, 0xEA7759F4, 0x2D57539D, 0x569A58CF, |
|
| 1123 | + 0xE84E63AD, 0x462E1B78, 0x6580F87E, 0xF3817914, |
|
| 1124 | + 0x91DA55F4, 0x40A230F3, 0xD1988F35, 0xB6E318D2, |
|
| 1125 | + 0x3FFA50BC, 0x3D40F021, 0xC3C0BDAE, 0x4958C24C, |
|
| 1126 | + 0x518F36B2, 0x84B1D370, 0x0FEDCE83, 0x878DDADA, |
|
| 1127 | + 0xF2A279C7, 0x94E01BE8, 0x90716F4B, 0x954B8AA3 |
|
| 1128 | + ); |
|
| 1129 | + |
|
| 1130 | + // 256 unsigned 32 bit integers |
|
| 1131 | + self::$_s8 = array( |
|
| 1132 | + 0xE216300D, 0xBBDDFFFC, 0xA7EBDABD, 0x35648095, |
|
| 1133 | + 0x7789F8B7, 0xE6C1121B, 0x0E241600, 0x052CE8B5, |
|
| 1134 | + 0x11A9CFB0, 0xE5952F11, 0xECE7990A, 0x9386D174, |
|
| 1135 | + 0x2A42931C, 0x76E38111, 0xB12DEF3A, 0x37DDDDFC, |
|
| 1136 | + 0xDE9ADEB1, 0x0A0CC32C, 0xBE197029, 0x84A00940, |
|
| 1137 | + 0xBB243A0F, 0xB4D137CF, 0xB44E79F0, 0x049EEDFD, |
|
| 1138 | + 0x0B15A15D, 0x480D3168, 0x8BBBDE5A, 0x669DED42, |
|
| 1139 | + 0xC7ECE831, 0x3F8F95E7, 0x72DF191B, 0x7580330D, |
|
| 1140 | + 0x94074251, 0x5C7DCDFA, 0xABBE6D63, 0xAA402164, |
|
| 1141 | + 0xB301D40A, 0x02E7D1CA, 0x53571DAE, 0x7A3182A2, |
|
| 1142 | + 0x12A8DDEC, 0xFDAA335D, 0x176F43E8, 0x71FB46D4, |
|
| 1143 | + 0x38129022, 0xCE949AD4, 0xB84769AD, 0x965BD862, |
|
| 1144 | + 0x82F3D055, 0x66FB9767, 0x15B80B4E, 0x1D5B47A0, |
|
| 1145 | + 0x4CFDE06F, 0xC28EC4B8, 0x57E8726E, 0x647A78FC, |
|
| 1146 | + 0x99865D44, 0x608BD593, 0x6C200E03, 0x39DC5FF6, |
|
| 1147 | + 0x5D0B00A3, 0xAE63AFF2, 0x7E8BD632, 0x70108C0C, |
|
| 1148 | + 0xBBD35049, 0x2998DF04, 0x980CF42A, 0x9B6DF491, |
|
| 1149 | + 0x9E7EDD53, 0x06918548, 0x58CB7E07, 0x3B74EF2E, |
|
| 1150 | + 0x522FFFB1, 0xD24708CC, 0x1C7E27CD, 0xA4EB215B, |
|
| 1151 | + 0x3CF1D2E2, 0x19B47A38, 0x424F7618, 0x35856039, |
|
| 1152 | + 0x9D17DEE7, 0x27EB35E6, 0xC9AFF67B, 0x36BAF5B8, |
|
| 1153 | + 0x09C467CD, 0xC18910B1, 0xE11DBF7B, 0x06CD1AF8, |
|
| 1154 | + 0x7170C608, 0x2D5E3354, 0xD4DE495A, 0x64C6D006, |
|
| 1155 | + 0xBCC0C62C, 0x3DD00DB3, 0x708F8F34, 0x77D51B42, |
|
| 1156 | + 0x264F620F, 0x24B8D2BF, 0x15C1B79E, 0x46A52564, |
|
| 1157 | + 0xF8D7E54E, 0x3E378160, 0x7895CDA5, 0x859C15A5, |
|
| 1158 | + 0xE6459788, 0xC37BC75F, 0xDB07BA0C, 0x0676A3AB, |
|
| 1159 | + 0x7F229B1E, 0x31842E7B, 0x24259FD7, 0xF8BEF472, |
|
| 1160 | + 0x835FFCB8, 0x6DF4C1F2, 0x96F5B195, 0xFD0AF0FC, |
|
| 1161 | + 0xB0FE134C, 0xE2506D3D, 0x4F9B12EA, 0xF215F225, |
|
| 1162 | + 0xA223736F, 0x9FB4C428, 0x25D04979, 0x34C713F8, |
|
| 1163 | + 0xC4618187, 0xEA7A6E98, 0x7CD16EFC, 0x1436876C, |
|
| 1164 | + 0xF1544107, 0xBEDEEE14, 0x56E9AF27, 0xA04AA441, |
|
| 1165 | + 0x3CF7C899, 0x92ECBAE6, 0xDD67016D, 0x151682EB, |
|
| 1166 | + 0xA842EEDF, 0xFDBA60B4, 0xF1907B75, 0x20E3030F, |
|
| 1167 | + 0x24D8C29E, 0xE139673B, 0xEFA63FB8, 0x71873054, |
|
| 1168 | + 0xB6F2CF3B, 0x9F326442, 0xCB15A4CC, 0xB01A4504, |
|
| 1169 | + 0xF1E47D8D, 0x844A1BE5, 0xBAE7DFDC, 0x42CBDA70, |
|
| 1170 | + 0xCD7DAE0A, 0x57E85B7A, 0xD53F5AF6, 0x20CF4D8C, |
|
| 1171 | + 0xCEA4D428, 0x79D130A4, 0x3486EBFB, 0x33D3CDDC, |
|
| 1172 | + 0x77853B53, 0x37EFFCB5, 0xC5068778, 0xE580B3E6, |
|
| 1173 | + 0x4E68B8F4, 0xC5C8B37E, 0x0D809EA2, 0x398FEB7C, |
|
| 1174 | + 0x132A4F94, 0x43B7950E, 0x2FEE7D1C, 0x223613BD, |
|
| 1175 | + 0xDD06CAA2, 0x37DF932B, 0xC4248289, 0xACF3EBC3, |
|
| 1176 | + 0x5715F6B7, 0xEF3478DD, 0xF267616F, 0xC148CBE4, |
|
| 1177 | + 0x9052815E, 0x5E410FAB, 0xB48A2465, 0x2EDA7FA4, |
|
| 1178 | + 0xE87B40E4, 0xE98EA084, 0x5889E9E1, 0xEFD390FC, |
|
| 1179 | + 0xDD07D35B, 0xDB485694, 0x38D7E5B2, 0x57720101, |
|
| 1180 | + 0x730EDEBC, 0x5B643113, 0x94917E4F, 0x503C2FBA, |
|
| 1181 | + 0x646F1282, 0x7523D24A, 0xE0779695, 0xF9C17A8F, |
|
| 1182 | + 0x7A5B2121, 0xD187B896, 0x29263A4D, 0xBA510CDF, |
|
| 1183 | + 0x81F47C9F, 0xAD1163ED, 0xEA7B5965, 0x1A00726E, |
|
| 1184 | + 0x11403092, 0x00DA6D77, 0x4A0CDD61, 0xAD1F4603, |
|
| 1185 | + 0x605BDFB0, 0x9EEDC364, 0x22EBE6A8, 0xCEE7D28A, |
|
| 1186 | + 0xA0E736A0, 0x5564A6B9, 0x10853209, 0xC7EB8F37, |
|
| 1187 | + 0x2DE705CA, 0x8951570F, 0xDF09822B, 0xBD691A6C, |
|
| 1188 | + 0xAA12E4F2, 0x87451C0F, 0xE0F6A27A, 0x3ADA4819, |
|
| 1189 | + 0x4CF1764F, 0x0D771C2B, 0x67CDB156, 0x350D8384, |
|
| 1190 | + 0x5938FA0F, 0x42399EF3, 0x36997B07, 0x0E84093D, |
|
| 1191 | + 0x4AA93E61, 0x8360D87B, 0x1FA98B0C, 0x1149382C, |
|
| 1192 | + 0xE97625A5, 0x0614D1B7, 0x0E25244B, 0x0C768347, |
|
| 1193 | + 0x589E8D82, 0x0D2059D1, 0xA466BB1E, 0xF8DA0A82, |
|
| 1194 | + 0x04F19130, 0xBA6E4EC0, 0x99265164, 0x1EE7230D, |
|
| 1195 | + 0x50B2AD80, 0xEAEE6801, 0x8DB2A283, 0xEA8BF59E |
|
| 1196 | + ); |
|
| 1197 | + } |
|
| 1198 | + |
|
| 1199 | + |
|
| 1200 | + /** |
|
| 1201 | + * Indicates this is a block cipher |
|
| 1202 | + * |
|
| 1203 | + * @return integer Returns Cipher::BLOCK |
|
| 1204 | + */ |
|
| 1205 | + public function type() |
|
| 1206 | + { |
|
| 1207 | + return parent::BLOCK; |
|
| 1208 | + } |
|
| 1209 | 1209 | } |
| 1210 | 1210 | ?> |
@@ -38,558 +38,558 @@ |
||
| 38 | 38 | */ |
| 39 | 39 | class Cipher_DES extends Cipher |
| 40 | 40 | { |
| 41 | - /** @type integer BYTES_BLOCK The block size, in bytes */ |
|
| 42 | - const BYTES_BLOCK = 8; // 64 bits |
|
| 41 | + /** @type integer BYTES_BLOCK The block size, in bytes */ |
|
| 42 | + const BYTES_BLOCK = 8; // 64 bits |
|
| 43 | 43 | |
| 44 | - /** @type integer BYTES_KEY The key size, in bytes */ |
|
| 45 | - const BYTES_KEY = 8; // 64 bits |
|
| 44 | + /** @type integer BYTES_KEY The key size, in bytes */ |
|
| 45 | + const BYTES_KEY = 8; // 64 bits |
|
| 46 | 46 | |
| 47 | - /** @type array $sub_keys The permutated subkeys */ |
|
| 48 | - protected $sub_keys = array(); |
|
| 47 | + /** @type array $sub_keys The permutated subkeys */ |
|
| 48 | + protected $sub_keys = array(); |
|
| 49 | 49 | |
| 50 | - /* |
|
| 50 | + /* |
|
| 51 | 51 | * Tables initialized in the initTables() |
| 52 | 52 | */ |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @type array $_pc1 Permutated choice 1 (PC1), |
|
| 56 | - * This should be considered a constant |
|
| 57 | - */ |
|
| 58 | - protected static $_pc1 = array(); |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @type array $_pc2 Permutated choice 2 (PC2), |
|
| 62 | - * This should be considered a constant |
|
| 63 | - */ |
|
| 64 | - protected static $_pc2 = array(); |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @type array $_key_sched The key schedule, |
|
| 68 | - * This should be considered a constant |
|
| 69 | - */ |
|
| 70 | - protected static $_key_sched = array(); |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @type array $_ip The Initial Permutation (IP), |
|
| 74 | - * This should be considered a constant |
|
| 75 | - */ |
|
| 76 | - private static $_ip = array(); |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @type array $_e The Expansion table (E), |
|
| 80 | - * This should be considered a constant |
|
| 81 | - */ |
|
| 82 | - private static $_e = array(); |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @type array $_s The Substitution Box (S), |
|
| 86 | - * This should be considered a constant |
|
| 87 | - */ |
|
| 88 | - private static $_s = array(); |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @type array $_p The Permutation table (P), |
|
| 92 | - * This should be considered a constant |
|
| 93 | - */ |
|
| 94 | - private static $_p = array(); |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @type array $_ip The The Final Permutation table (FP), |
|
| 98 | - * This should be considered a constant |
|
| 99 | - */ |
|
| 100 | - private static $_fp = array(); |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Constructor, used only when calling this class directly |
|
| 105 | - * for classes that extend this class, call __construct1() |
|
| 106 | - * |
|
| 107 | - * @param string $key The key used for Encryption/Decryption |
|
| 108 | - * @return void |
|
| 109 | - */ |
|
| 110 | - public function __construct($key) |
|
| 111 | - { |
|
| 112 | - // set the DES key |
|
| 113 | - parent::__construct(PHP_Crypt::CIPHER_DES, $key, self::BYTES_KEY); |
|
| 114 | - |
|
| 115 | - // initialize variables |
|
| 116 | - $this->initTables(); |
|
| 117 | - |
|
| 118 | - // DES requires that data is 64 bits |
|
| 119 | - $this->blockSize(self::BYTES_BLOCK); |
|
| 120 | - |
|
| 121 | - // create the 16 rounds of 56 bit keys |
|
| 122 | - $this->keyPermutation(); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Second Constructor, used only by child classes that extend this class |
|
| 128 | - * |
|
| 129 | - * @param string $cipher The name of the cipher extending this class |
|
| 130 | - * @param string $key The key used for Encryption/Decryption |
|
| 131 | - * @param integer $key_byte_sz The required byte size of the extending cipher |
|
| 132 | - * @return void |
|
| 133 | - */ |
|
| 134 | - protected function __construct1($cipher, $key, $key_byte_sz) |
|
| 135 | - { |
|
| 136 | - // set the key and key size |
|
| 137 | - parent::__construct($cipher, $key, $key_byte_sz); |
|
| 138 | - |
|
| 139 | - // initialize variables |
|
| 140 | - $this->initTables(); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Destructor |
|
| 146 | - * |
|
| 147 | - * @return void |
|
| 148 | - */ |
|
| 149 | - public function __destruct() |
|
| 150 | - { |
|
| 151 | - parent::__destruct(); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Encrypt plain text data using DES |
|
| 157 | - * |
|
| 158 | - * @param string $data A plain text string |
|
| 159 | - * @return boolean Returns true |
|
| 160 | - */ |
|
| 161 | - public function encrypt(&$text) |
|
| 162 | - { |
|
| 163 | - $this->operation(parent::ENCRYPT); |
|
| 164 | - return $this->des($text); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Decrypt a DES encrypted string |
|
| 170 | - * |
|
| 171 | - * @param string $encrypted A DES encrypted string |
|
| 172 | - * @return boolean Returns true |
|
| 173 | - */ |
|
| 174 | - public function decrypt(&$text) |
|
| 175 | - { |
|
| 176 | - $this->operation(parent::DECRYPT); |
|
| 177 | - return $this->des($text); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * This is where the actual encrypt/decryption takes place. Since |
|
| 183 | - * encryption and decryption are the same algorithm in DES, we only |
|
| 184 | - * need one function to do both. |
|
| 185 | - * |
|
| 186 | - * @param string $data The string to be encrypted or decrypted |
|
| 187 | - * @return boolean Returns true |
|
| 188 | - */ |
|
| 189 | - protected function des(&$data) |
|
| 190 | - { |
|
| 191 | - $l = array(); |
|
| 192 | - $r = array(); |
|
| 193 | - |
|
| 194 | - // step two: Initial Permutation (IP) of plaintext |
|
| 195 | - $data = $this->ip($data); |
|
| 196 | - |
|
| 197 | - // divide the permuted block IP into a left half L0 of 32 bits, |
|
| 198 | - // and a right half R0 of 32 bits |
|
| 199 | - $l[0] = substr($data, 0, 32); |
|
| 200 | - $r[0] = substr($data, 32, 32); |
|
| 201 | - |
|
| 202 | - for($n = 1; $n <= 16; ++$n) |
|
| 203 | - { |
|
| 204 | - $l[$n] = $r[$n-1]; |
|
| 205 | - |
|
| 206 | - if($this->operation() == parent::DECRYPT) |
|
| 207 | - $f = $this->F($r[$n-1], $this->sub_keys[16-$n]); |
|
| 208 | - else |
|
| 209 | - $f = $this->F($r[$n-1], $this->sub_keys[$n-1]); |
|
| 210 | - |
|
| 211 | - // XOR F with Ln |
|
| 212 | - $r[$n] = $this->xorBin($l[$n-1], $f); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - // now we combine L[16] and R[16] back into a 64-bit string, but we reverse |
|
| 216 | - // L[16] and R[16] so that it becomes R[16]L[16] |
|
| 217 | - $data = $r[16].$l[16]; |
|
| 218 | - |
|
| 219 | - // now do the final permutation |
|
| 220 | - $data = $this->fp($data); |
|
| 221 | - $data = parent::bin2Str($data); |
|
| 222 | - |
|
| 223 | - return true; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * The Key permutation, based on tables $_pc1 and $_pc2 |
|
| 229 | - * Create 16 subkeys, each of which is 48-bits long. |
|
| 230 | - * |
|
| 231 | - * @return void |
|
| 232 | - */ |
|
| 233 | - private function keyPermutation() |
|
| 234 | - { |
|
| 235 | - $this->sub_keys = array(); |
|
| 236 | - $pc1m = array(); |
|
| 237 | - $pcr = array(); |
|
| 238 | - $c = array(); |
|
| 239 | - $d = array(); |
|
| 240 | - |
|
| 241 | - // convert the key to binary |
|
| 242 | - $binkey = parent::str2Bin($this->key()); |
|
| 243 | - |
|
| 244 | - // reduce the key down to 56bits based on table $_pc1 |
|
| 245 | - for($i = 0; $i < 56; ++$i) |
|
| 54 | + /** |
|
| 55 | + * @type array $_pc1 Permutated choice 1 (PC1), |
|
| 56 | + * This should be considered a constant |
|
| 57 | + */ |
|
| 58 | + protected static $_pc1 = array(); |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @type array $_pc2 Permutated choice 2 (PC2), |
|
| 62 | + * This should be considered a constant |
|
| 63 | + */ |
|
| 64 | + protected static $_pc2 = array(); |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @type array $_key_sched The key schedule, |
|
| 68 | + * This should be considered a constant |
|
| 69 | + */ |
|
| 70 | + protected static $_key_sched = array(); |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @type array $_ip The Initial Permutation (IP), |
|
| 74 | + * This should be considered a constant |
|
| 75 | + */ |
|
| 76 | + private static $_ip = array(); |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @type array $_e The Expansion table (E), |
|
| 80 | + * This should be considered a constant |
|
| 81 | + */ |
|
| 82 | + private static $_e = array(); |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @type array $_s The Substitution Box (S), |
|
| 86 | + * This should be considered a constant |
|
| 87 | + */ |
|
| 88 | + private static $_s = array(); |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @type array $_p The Permutation table (P), |
|
| 92 | + * This should be considered a constant |
|
| 93 | + */ |
|
| 94 | + private static $_p = array(); |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @type array $_ip The The Final Permutation table (FP), |
|
| 98 | + * This should be considered a constant |
|
| 99 | + */ |
|
| 100 | + private static $_fp = array(); |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Constructor, used only when calling this class directly |
|
| 105 | + * for classes that extend this class, call __construct1() |
|
| 106 | + * |
|
| 107 | + * @param string $key The key used for Encryption/Decryption |
|
| 108 | + * @return void |
|
| 109 | + */ |
|
| 110 | + public function __construct($key) |
|
| 111 | + { |
|
| 112 | + // set the DES key |
|
| 113 | + parent::__construct(PHP_Crypt::CIPHER_DES, $key, self::BYTES_KEY); |
|
| 114 | + |
|
| 115 | + // initialize variables |
|
| 116 | + $this->initTables(); |
|
| 117 | + |
|
| 118 | + // DES requires that data is 64 bits |
|
| 119 | + $this->blockSize(self::BYTES_BLOCK); |
|
| 120 | + |
|
| 121 | + // create the 16 rounds of 56 bit keys |
|
| 122 | + $this->keyPermutation(); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Second Constructor, used only by child classes that extend this class |
|
| 128 | + * |
|
| 129 | + * @param string $cipher The name of the cipher extending this class |
|
| 130 | + * @param string $key The key used for Encryption/Decryption |
|
| 131 | + * @param integer $key_byte_sz The required byte size of the extending cipher |
|
| 132 | + * @return void |
|
| 133 | + */ |
|
| 134 | + protected function __construct1($cipher, $key, $key_byte_sz) |
|
| 135 | + { |
|
| 136 | + // set the key and key size |
|
| 137 | + parent::__construct($cipher, $key, $key_byte_sz); |
|
| 138 | + |
|
| 139 | + // initialize variables |
|
| 140 | + $this->initTables(); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Destructor |
|
| 146 | + * |
|
| 147 | + * @return void |
|
| 148 | + */ |
|
| 149 | + public function __destruct() |
|
| 150 | + { |
|
| 151 | + parent::__destruct(); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Encrypt plain text data using DES |
|
| 157 | + * |
|
| 158 | + * @param string $data A plain text string |
|
| 159 | + * @return boolean Returns true |
|
| 160 | + */ |
|
| 161 | + public function encrypt(&$text) |
|
| 162 | + { |
|
| 163 | + $this->operation(parent::ENCRYPT); |
|
| 164 | + return $this->des($text); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Decrypt a DES encrypted string |
|
| 170 | + * |
|
| 171 | + * @param string $encrypted A DES encrypted string |
|
| 172 | + * @return boolean Returns true |
|
| 173 | + */ |
|
| 174 | + public function decrypt(&$text) |
|
| 175 | + { |
|
| 176 | + $this->operation(parent::DECRYPT); |
|
| 177 | + return $this->des($text); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * This is where the actual encrypt/decryption takes place. Since |
|
| 183 | + * encryption and decryption are the same algorithm in DES, we only |
|
| 184 | + * need one function to do both. |
|
| 185 | + * |
|
| 186 | + * @param string $data The string to be encrypted or decrypted |
|
| 187 | + * @return boolean Returns true |
|
| 188 | + */ |
|
| 189 | + protected function des(&$data) |
|
| 190 | + { |
|
| 191 | + $l = array(); |
|
| 192 | + $r = array(); |
|
| 193 | + |
|
| 194 | + // step two: Initial Permutation (IP) of plaintext |
|
| 195 | + $data = $this->ip($data); |
|
| 196 | + |
|
| 197 | + // divide the permuted block IP into a left half L0 of 32 bits, |
|
| 198 | + // and a right half R0 of 32 bits |
|
| 199 | + $l[0] = substr($data, 0, 32); |
|
| 200 | + $r[0] = substr($data, 32, 32); |
|
| 201 | + |
|
| 202 | + for($n = 1; $n <= 16; ++$n) |
|
| 203 | + { |
|
| 204 | + $l[$n] = $r[$n-1]; |
|
| 205 | + |
|
| 206 | + if($this->operation() == parent::DECRYPT) |
|
| 207 | + $f = $this->F($r[$n-1], $this->sub_keys[16-$n]); |
|
| 208 | + else |
|
| 209 | + $f = $this->F($r[$n-1], $this->sub_keys[$n-1]); |
|
| 210 | + |
|
| 211 | + // XOR F with Ln |
|
| 212 | + $r[$n] = $this->xorBin($l[$n-1], $f); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + // now we combine L[16] and R[16] back into a 64-bit string, but we reverse |
|
| 216 | + // L[16] and R[16] so that it becomes R[16]L[16] |
|
| 217 | + $data = $r[16].$l[16]; |
|
| 218 | + |
|
| 219 | + // now do the final permutation |
|
| 220 | + $data = $this->fp($data); |
|
| 221 | + $data = parent::bin2Str($data); |
|
| 222 | + |
|
| 223 | + return true; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * The Key permutation, based on tables $_pc1 and $_pc2 |
|
| 229 | + * Create 16 subkeys, each of which is 48-bits long. |
|
| 230 | + * |
|
| 231 | + * @return void |
|
| 232 | + */ |
|
| 233 | + private function keyPermutation() |
|
| 234 | + { |
|
| 235 | + $this->sub_keys = array(); |
|
| 236 | + $pc1m = array(); |
|
| 237 | + $pcr = array(); |
|
| 238 | + $c = array(); |
|
| 239 | + $d = array(); |
|
| 240 | + |
|
| 241 | + // convert the key to binary |
|
| 242 | + $binkey = parent::str2Bin($this->key()); |
|
| 243 | + |
|
| 244 | + // reduce the key down to 56bits based on table $_pc1 |
|
| 245 | + for($i = 0; $i < 56; ++$i) |
|
| 246 | 246 | $pc1m[$i] = $binkey[self::$_pc1[$i] - 1]; |
| 247 | 247 | |
| 248 | - // split $pc1m in half (C0 and D0) |
|
| 249 | - $c[0] = array_slice($pc1m, 0, 28); |
|
| 250 | - $d[0] = array_slice($pc1m, 28, 28); |
|
| 251 | - |
|
| 252 | - // now that $c[0] and $d[0] are defined, create 16 blocks for Cn and Dn |
|
| 253 | - // where 1 <= n <= 16 |
|
| 254 | - for($i = 1; $i <= 16; ++$i) |
|
| 255 | - { |
|
| 256 | - // now set the next Cn and Dn as the previous Cn and Dn |
|
| 257 | - $c[$i] = $c[$i-1]; |
|
| 258 | - $d[$i] = $d[$i-1]; |
|
| 259 | - |
|
| 260 | - for($j = 0; $j < self::$_key_sched[$i-1]; ++$j) |
|
| 261 | - { |
|
| 262 | - // do a left shift, move each bit one place to the left, |
|
| 263 | - // except for the first bit, which is cycled to the end |
|
| 264 | - // of the block. |
|
| 265 | - $c[$i][] = array_shift($c[$i]); |
|
| 266 | - $d[$i][] = array_shift($d[$i]); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - // We now form the sub_keys (Kn), for 1<=n<=16, by applying the |
|
| 270 | - // following permutation table to each of the concatenated |
|
| 271 | - // pairs CnDn. Each pair has 56 bits, but PC-2 only uses 48 |
|
| 272 | - // of these. |
|
| 273 | - $CnDn = array_merge($c[$i], $d[$i]); |
|
| 274 | - $this->sub_keys[$i-1] = ""; |
|
| 275 | - for($j = 0; $j < 48; ++$j) |
|
| 276 | - $this->sub_keys[$i-1] .= $CnDn[self::$_pc2[$j] - 1]; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - // the sub_keys are created, we are done with the key permutation |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * Initial Permutation (IP) |
|
| 285 | - * Now we encode each 64-bit block of data. There is an initial permutation IP of |
|
| 286 | - * the 64 bits of the message data M. This rearranges the bits according to the |
|
| 287 | - * following table, where the entries in the table show the new arrangement of the |
|
| 288 | - * bits from their initial order. The 58th bit of M becomes the first bit of IP. |
|
| 289 | - * The 50th bit of M becomes the second bit of IP. The 7th bit of M is the last |
|
| 290 | - * bit of IP. |
|
| 291 | - * |
|
| 292 | - * According to the book Applied Cryptography (Bruce Schneier, 2nd edition, pg. 271): |
|
| 293 | - * The initial permution was used to make it easier to load plain text and cipher text |
|
| 294 | - * data into a DES chip in byte-sized pieces when doing DES in hardware. The IP and FP |
|
| 295 | - * are not necessary in software implementations and do not affect the security. However, |
|
| 296 | - * the IP and FP are part of the DES standard and not implementing it would deviate from |
|
| 297 | - * the standard, so we will do it here in phpCrypt. |
|
| 298 | - * |
|
| 299 | - * @param string $m The plain text message |
|
| 300 | - * @return array the Initial Permutation (IP) |
|
| 301 | - */ |
|
| 302 | - private function ip($text) |
|
| 303 | - { |
|
| 304 | - $text = parent::str2Bin($text); |
|
| 305 | - $ip = ""; |
|
| 306 | - |
|
| 307 | - // loop through the 64 bit block, ordering it occording to $_ip |
|
| 308 | - for($i = 0; $i < 64; ++$i) |
|
| 309 | - $ip .= $text[self::$_ip[$i] - 1]; |
|
| 310 | - |
|
| 311 | - return $ip; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Function F - To calculate f, we first expand each block Rn-1 from 32 bits to 48 bits. |
|
| 317 | - * This is done by using a selection table that repeats some of the bits in Rn-1. We'll |
|
| 318 | - * call the use of this selection table the function E. Thus E(Rn-1) has a 32 bit input |
|
| 319 | - * block, and a 48 bit output block. |
|
| 320 | - * |
|
| 321 | - * @param array $r 32 bit binary, each bit in an array element |
|
| 322 | - * @param string $k 48 bit binary string |
|
| 323 | - * @return string 48 bit binary string |
|
| 324 | - */ |
|
| 325 | - private function f($r, $k) |
|
| 326 | - { |
|
| 327 | - $bin = parent::xorBin($k, $this->E($r)); |
|
| 328 | - |
|
| 329 | - // create a 32-bit string from $bits by passing it through the S-Boxes |
|
| 330 | - $bin = $this->s($bin); |
|
| 331 | - |
|
| 332 | - // now send permute $bin as defined by table self::$_p |
|
| 333 | - $bin = $this->p($bin); |
|
| 334 | - |
|
| 335 | - return $bin; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * Function E - Let E be such that the 48 bits of its output, written as 8 blocks of |
|
| 341 | - * 6 bits each, are obtained by selecting the bits in its inputs in order according |
|
| 342 | - * to the self::$_e[] table. |
|
| 343 | - * This is only used in the F() function |
|
| 344 | - * |
|
| 345 | - * @param array $r 32 bit binary, each bit in an array element |
|
| 346 | - * @return string 48 bit binary string |
|
| 347 | - */ |
|
| 348 | - private function e($r) |
|
| 349 | - { |
|
| 350 | - $e = ""; |
|
| 351 | - for($i = 0; $i < 48; ++$i) |
|
| 352 | - $e .= $r[self::$_e[$i] - 1]; |
|
| 353 | - |
|
| 354 | - return $e; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * S-Box |
|
| 360 | - * Take a 48-bit string from F() and run it through the S-Boxes, this requires |
|
| 361 | - * us to break up the 48-bit string into 8 groups of 6 bits before sending it |
|
| 362 | - * through the S-Boxes |
|
| 363 | - * |
|
| 364 | - * @param string $bits The 48-bit string from F() to be processed |
|
| 365 | - * @return string A 32-bit string from created from the 48-bit string after passing through S-Boxes |
|
| 366 | - */ |
|
| 367 | - private function s($bits) |
|
| 368 | - { |
|
| 369 | - $s = ""; |
|
| 370 | - |
|
| 371 | - for($i = 0; $i <= 42; $i += 6) |
|
| 372 | - { |
|
| 373 | - $sbits = substr($bits, $i, 6); |
|
| 374 | - |
|
| 375 | - // we need to determine the S-Box column number and row number |
|
| 376 | - // from the 6 bit string passed in, this is done using the following method: |
|
| 377 | - // The First & Last bits represent a number between 0-3, used to determine which row |
|
| 378 | - // The middle 4 bits represent a number between 0-15, used to determine the column |
|
| 379 | - $row = bindec("{$sbits[0]}{$sbits[5]}"); |
|
| 380 | - $col = bindec("{$sbits[1]}{$sbits[2]}{$sbits[3]}{$sbits[4]}"); |
|
| 381 | - |
|
| 382 | - // determine the position in the S-BOX, S-Box table is in self::$_s[] |
|
| 383 | - $pos = ($row * 16) + $col; |
|
| 384 | - |
|
| 385 | - // get the integer from the S-Box and convert it to binary |
|
| 386 | - $bin = decbin(self::$_s[($i/6)][$pos]); |
|
| 387 | - $s .= str_pad($bin, 4, "0", STR_PAD_LEFT); |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - return $s; |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * Permutation P |
|
| 396 | - * The permutation P is defined in self::$_p. P() returns a 32-bit output |
|
| 397 | - * from a 32-bit input from a binary string from the S-BOX by permuting |
|
| 398 | - * the bits of the input block. |
|
| 399 | - * This is only used inside of F() function |
|
| 400 | - * |
|
| 401 | - * @param string $s A 32-bit string originating from being passed through S-Box |
|
| 402 | - * @return string A 32-bit string, which is $s permuted through table self::$_p |
|
| 403 | - */ |
|
| 404 | - private function p($s) |
|
| 405 | - { |
|
| 406 | - $p = ""; |
|
| 407 | - for($i = 0; $i < 32; ++$i) |
|
| 408 | - $p .= $s[self::$_p[$i] - 1]; |
|
| 409 | - |
|
| 410 | - return $p; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * Final Permutation (FP) |
|
| 416 | - * Read the comment about IP and FP being unecessary in software implmented DES (though |
|
| 417 | - * we will do it to follow the DES standard). |
|
| 418 | - * |
|
| 419 | - * @param string $bin A 64-bit binary string |
|
| 420 | - * @return string A 64-bit binary string that has been run through self::$_fp[] table |
|
| 421 | - */ |
|
| 422 | - private function fp($bin) |
|
| 423 | - { |
|
| 424 | - $fp = ""; |
|
| 425 | - for($i = 0; $i < 64; ++$i) |
|
| 426 | - $fp .= $bin[self::$_fp[$i] - 1]; |
|
| 427 | - |
|
| 428 | - return $fp; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * Initialize all the tables, this function is called inside the constructor |
|
| 434 | - * |
|
| 435 | - * @return void |
|
| 436 | - */ |
|
| 437 | - private function initTables() |
|
| 438 | - { |
|
| 439 | - // permuted choice 1 (PC1) |
|
| 440 | - // these values are chars and should be run through chr() when used |
|
| 441 | - self::$_pc1 = array( |
|
| 442 | - 57, 49, 41, 33, 25, 17, 9, |
|
| 443 | - 1, 58, 50, 42, 34, 26, 18, |
|
| 444 | - 10, 2, 59, 51, 43, 35, 27, |
|
| 445 | - 19, 11, 3, 60, 52, 44, 36, |
|
| 446 | - 63, 55, 47, 39, 31, 23, 15, |
|
| 447 | - 7, 62, 54, 46, 38, 30, 22, |
|
| 448 | - 14, 6, 61, 53, 45, 37, 29, |
|
| 449 | - 21, 13, 5, 28, 20, 12, 4 |
|
| 450 | - ); |
|
| 451 | - |
|
| 452 | - // permuted choice 2 (PC2) |
|
| 453 | - // these values are chars and should be run through chr() when used |
|
| 454 | - self::$_pc2 = array( |
|
| 455 | - 14, 17, 11, 24, 1, 5, |
|
| 456 | - 3, 28, 15, 6, 21, 10, |
|
| 457 | - 23, 19, 12, 4, 26, 8, |
|
| 458 | - 16, 7, 27, 20, 13, 2, |
|
| 459 | - 41, 52, 31, 37, 47, 55, |
|
| 460 | - 30, 40, 51, 45, 33, 48, |
|
| 461 | - 44, 49, 39, 56, 34, 53, |
|
| 462 | - 46, 42, 50, 36, 29, 32 |
|
| 463 | - ); |
|
| 464 | - |
|
| 465 | - // initial permutation (IP) |
|
| 466 | - self::$_ip = array( |
|
| 467 | - 58, 50, 42, 34, 26, 18, 10, 2, |
|
| 468 | - 60, 52, 44, 36, 28, 20, 12, 4, |
|
| 469 | - 62, 54, 46, 38, 30, 22, 14, 6, |
|
| 470 | - 64, 56, 48, 40, 32, 24, 16, 8, |
|
| 471 | - 57, 49, 41, 33, 25, 17, 9, 1, |
|
| 472 | - 59, 51, 43, 35, 27, 19, 11, 3, |
|
| 473 | - 61, 53, 45, 37, 29, 21, 13, 5, |
|
| 474 | - 63, 55, 47, 39, 31, 23, 15, 7 |
|
| 475 | - ); |
|
| 476 | - |
|
| 477 | - // expansion (E) |
|
| 478 | - self::$_e = array( |
|
| 479 | - 32, 1, 2, 3, 4, 5, |
|
| 480 | - 4, 5, 6, 7, 8, 9, |
|
| 481 | - 8, 9, 10, 11, 12, 13, |
|
| 482 | - 12, 13, 14, 15, 16, 17, |
|
| 483 | - 16, 17, 18, 19, 20, 21, |
|
| 484 | - 20, 21, 22, 23, 24, 25, |
|
| 485 | - 24, 25, 26, 27, 28, 29, |
|
| 486 | - 28, 29, 30, 31, 32, 1 |
|
| 487 | - ); |
|
| 488 | - |
|
| 489 | - // substition box (S) |
|
| 490 | - self::$_s = array( |
|
| 491 | - /* S1 */ |
|
| 492 | - array( |
|
| 493 | - 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, |
|
| 494 | - 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, |
|
| 495 | - 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, |
|
| 496 | - 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 |
|
| 497 | - ), |
|
| 498 | - |
|
| 499 | - /* S2 */ |
|
| 500 | - array( |
|
| 501 | - 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, |
|
| 502 | - 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, |
|
| 503 | - 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, |
|
| 504 | - 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 |
|
| 505 | - ), |
|
| 506 | - |
|
| 507 | - /* S3 */ |
|
| 508 | - array( |
|
| 509 | - 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, |
|
| 510 | - 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, |
|
| 511 | - 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, |
|
| 512 | - 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 |
|
| 513 | - ), |
|
| 514 | - |
|
| 515 | - /* S4 */ |
|
| 516 | - array( |
|
| 517 | - 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, |
|
| 518 | - 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, |
|
| 519 | - 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, |
|
| 520 | - 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 |
|
| 521 | - ), |
|
| 522 | - |
|
| 523 | - /* S5 */ |
|
| 524 | - array( |
|
| 525 | - 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, |
|
| 526 | - 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, |
|
| 527 | - 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, |
|
| 528 | - 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 |
|
| 529 | - ), |
|
| 530 | - |
|
| 531 | - /* S6 */ |
|
| 532 | - array( |
|
| 533 | - 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, |
|
| 534 | - 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, |
|
| 535 | - 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, |
|
| 536 | - 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 |
|
| 537 | - ), |
|
| 538 | - |
|
| 539 | - /* S7 */ |
|
| 540 | - array( |
|
| 541 | - 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, |
|
| 542 | - 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, |
|
| 543 | - 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, |
|
| 544 | - 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12 |
|
| 545 | - ), |
|
| 546 | - |
|
| 547 | - /* S8 */ |
|
| 548 | - array( |
|
| 549 | - 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, |
|
| 550 | - 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, |
|
| 551 | - 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, |
|
| 552 | - 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11 |
|
| 553 | - ) |
|
| 554 | - ); |
|
| 555 | - |
|
| 556 | - // permutation (P) |
|
| 557 | - self::$_p = array( |
|
| 558 | - 16, 7, 20, 21, |
|
| 559 | - 29, 12, 28, 17, |
|
| 560 | - 1, 15, 23, 26, |
|
| 561 | - 5, 18, 31, 10, |
|
| 562 | - 2, 8, 24, 14, |
|
| 563 | - 32, 27, 3, 9, |
|
| 564 | - 19, 13, 30, 6, |
|
| 565 | - 22, 11, 4, 25 |
|
| 566 | - ); |
|
| 567 | - |
|
| 568 | - // final permutation (FP) |
|
| 569 | - self::$_fp = array( |
|
| 570 | - 40, 8, 48, 16, 56, 24, 64, 32, |
|
| 571 | - 39, 7, 47, 15, 55, 23, 63, 31, |
|
| 572 | - 38, 6, 46, 14, 54, 22, 62, 30, |
|
| 573 | - 37, 5, 45, 13, 53, 21, 61, 29, |
|
| 574 | - 36, 4, 44, 12, 52, 20, 60, 28, |
|
| 575 | - 35, 3, 43, 11, 51, 19, 59, 27, |
|
| 576 | - 34, 2, 42, 10, 50, 18, 58, 26, |
|
| 577 | - 33, 1, 41, 9, 49, 17, 57, 25 |
|
| 578 | - ); |
|
| 579 | - |
|
| 580 | - // key schedule used in KeyPermutation() |
|
| 581 | - self::$_key_sched = array(1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1); |
|
| 582 | - } |
|
| 583 | - |
|
| 584 | - |
|
| 585 | - /** |
|
| 586 | - * Indicates this is a block cipher |
|
| 587 | - * |
|
| 588 | - * @return integer Returns Cipher::BLOCK |
|
| 589 | - */ |
|
| 590 | - public function type() |
|
| 591 | - { |
|
| 592 | - return parent::BLOCK; |
|
| 593 | - } |
|
| 248 | + // split $pc1m in half (C0 and D0) |
|
| 249 | + $c[0] = array_slice($pc1m, 0, 28); |
|
| 250 | + $d[0] = array_slice($pc1m, 28, 28); |
|
| 251 | + |
|
| 252 | + // now that $c[0] and $d[0] are defined, create 16 blocks for Cn and Dn |
|
| 253 | + // where 1 <= n <= 16 |
|
| 254 | + for($i = 1; $i <= 16; ++$i) |
|
| 255 | + { |
|
| 256 | + // now set the next Cn and Dn as the previous Cn and Dn |
|
| 257 | + $c[$i] = $c[$i-1]; |
|
| 258 | + $d[$i] = $d[$i-1]; |
|
| 259 | + |
|
| 260 | + for($j = 0; $j < self::$_key_sched[$i-1]; ++$j) |
|
| 261 | + { |
|
| 262 | + // do a left shift, move each bit one place to the left, |
|
| 263 | + // except for the first bit, which is cycled to the end |
|
| 264 | + // of the block. |
|
| 265 | + $c[$i][] = array_shift($c[$i]); |
|
| 266 | + $d[$i][] = array_shift($d[$i]); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + // We now form the sub_keys (Kn), for 1<=n<=16, by applying the |
|
| 270 | + // following permutation table to each of the concatenated |
|
| 271 | + // pairs CnDn. Each pair has 56 bits, but PC-2 only uses 48 |
|
| 272 | + // of these. |
|
| 273 | + $CnDn = array_merge($c[$i], $d[$i]); |
|
| 274 | + $this->sub_keys[$i-1] = ""; |
|
| 275 | + for($j = 0; $j < 48; ++$j) |
|
| 276 | + $this->sub_keys[$i-1] .= $CnDn[self::$_pc2[$j] - 1]; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + // the sub_keys are created, we are done with the key permutation |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * Initial Permutation (IP) |
|
| 285 | + * Now we encode each 64-bit block of data. There is an initial permutation IP of |
|
| 286 | + * the 64 bits of the message data M. This rearranges the bits according to the |
|
| 287 | + * following table, where the entries in the table show the new arrangement of the |
|
| 288 | + * bits from their initial order. The 58th bit of M becomes the first bit of IP. |
|
| 289 | + * The 50th bit of M becomes the second bit of IP. The 7th bit of M is the last |
|
| 290 | + * bit of IP. |
|
| 291 | + * |
|
| 292 | + * According to the book Applied Cryptography (Bruce Schneier, 2nd edition, pg. 271): |
|
| 293 | + * The initial permution was used to make it easier to load plain text and cipher text |
|
| 294 | + * data into a DES chip in byte-sized pieces when doing DES in hardware. The IP and FP |
|
| 295 | + * are not necessary in software implementations and do not affect the security. However, |
|
| 296 | + * the IP and FP are part of the DES standard and not implementing it would deviate from |
|
| 297 | + * the standard, so we will do it here in phpCrypt. |
|
| 298 | + * |
|
| 299 | + * @param string $m The plain text message |
|
| 300 | + * @return array the Initial Permutation (IP) |
|
| 301 | + */ |
|
| 302 | + private function ip($text) |
|
| 303 | + { |
|
| 304 | + $text = parent::str2Bin($text); |
|
| 305 | + $ip = ""; |
|
| 306 | + |
|
| 307 | + // loop through the 64 bit block, ordering it occording to $_ip |
|
| 308 | + for($i = 0; $i < 64; ++$i) |
|
| 309 | + $ip .= $text[self::$_ip[$i] - 1]; |
|
| 310 | + |
|
| 311 | + return $ip; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Function F - To calculate f, we first expand each block Rn-1 from 32 bits to 48 bits. |
|
| 317 | + * This is done by using a selection table that repeats some of the bits in Rn-1. We'll |
|
| 318 | + * call the use of this selection table the function E. Thus E(Rn-1) has a 32 bit input |
|
| 319 | + * block, and a 48 bit output block. |
|
| 320 | + * |
|
| 321 | + * @param array $r 32 bit binary, each bit in an array element |
|
| 322 | + * @param string $k 48 bit binary string |
|
| 323 | + * @return string 48 bit binary string |
|
| 324 | + */ |
|
| 325 | + private function f($r, $k) |
|
| 326 | + { |
|
| 327 | + $bin = parent::xorBin($k, $this->E($r)); |
|
| 328 | + |
|
| 329 | + // create a 32-bit string from $bits by passing it through the S-Boxes |
|
| 330 | + $bin = $this->s($bin); |
|
| 331 | + |
|
| 332 | + // now send permute $bin as defined by table self::$_p |
|
| 333 | + $bin = $this->p($bin); |
|
| 334 | + |
|
| 335 | + return $bin; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * Function E - Let E be such that the 48 bits of its output, written as 8 blocks of |
|
| 341 | + * 6 bits each, are obtained by selecting the bits in its inputs in order according |
|
| 342 | + * to the self::$_e[] table. |
|
| 343 | + * This is only used in the F() function |
|
| 344 | + * |
|
| 345 | + * @param array $r 32 bit binary, each bit in an array element |
|
| 346 | + * @return string 48 bit binary string |
|
| 347 | + */ |
|
| 348 | + private function e($r) |
|
| 349 | + { |
|
| 350 | + $e = ""; |
|
| 351 | + for($i = 0; $i < 48; ++$i) |
|
| 352 | + $e .= $r[self::$_e[$i] - 1]; |
|
| 353 | + |
|
| 354 | + return $e; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * S-Box |
|
| 360 | + * Take a 48-bit string from F() and run it through the S-Boxes, this requires |
|
| 361 | + * us to break up the 48-bit string into 8 groups of 6 bits before sending it |
|
| 362 | + * through the S-Boxes |
|
| 363 | + * |
|
| 364 | + * @param string $bits The 48-bit string from F() to be processed |
|
| 365 | + * @return string A 32-bit string from created from the 48-bit string after passing through S-Boxes |
|
| 366 | + */ |
|
| 367 | + private function s($bits) |
|
| 368 | + { |
|
| 369 | + $s = ""; |
|
| 370 | + |
|
| 371 | + for($i = 0; $i <= 42; $i += 6) |
|
| 372 | + { |
|
| 373 | + $sbits = substr($bits, $i, 6); |
|
| 374 | + |
|
| 375 | + // we need to determine the S-Box column number and row number |
|
| 376 | + // from the 6 bit string passed in, this is done using the following method: |
|
| 377 | + // The First & Last bits represent a number between 0-3, used to determine which row |
|
| 378 | + // The middle 4 bits represent a number between 0-15, used to determine the column |
|
| 379 | + $row = bindec("{$sbits[0]}{$sbits[5]}"); |
|
| 380 | + $col = bindec("{$sbits[1]}{$sbits[2]}{$sbits[3]}{$sbits[4]}"); |
|
| 381 | + |
|
| 382 | + // determine the position in the S-BOX, S-Box table is in self::$_s[] |
|
| 383 | + $pos = ($row * 16) + $col; |
|
| 384 | + |
|
| 385 | + // get the integer from the S-Box and convert it to binary |
|
| 386 | + $bin = decbin(self::$_s[($i/6)][$pos]); |
|
| 387 | + $s .= str_pad($bin, 4, "0", STR_PAD_LEFT); |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + return $s; |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + |
|
| 394 | + /** |
|
| 395 | + * Permutation P |
|
| 396 | + * The permutation P is defined in self::$_p. P() returns a 32-bit output |
|
| 397 | + * from a 32-bit input from a binary string from the S-BOX by permuting |
|
| 398 | + * the bits of the input block. |
|
| 399 | + * This is only used inside of F() function |
|
| 400 | + * |
|
| 401 | + * @param string $s A 32-bit string originating from being passed through S-Box |
|
| 402 | + * @return string A 32-bit string, which is $s permuted through table self::$_p |
|
| 403 | + */ |
|
| 404 | + private function p($s) |
|
| 405 | + { |
|
| 406 | + $p = ""; |
|
| 407 | + for($i = 0; $i < 32; ++$i) |
|
| 408 | + $p .= $s[self::$_p[$i] - 1]; |
|
| 409 | + |
|
| 410 | + return $p; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * Final Permutation (FP) |
|
| 416 | + * Read the comment about IP and FP being unecessary in software implmented DES (though |
|
| 417 | + * we will do it to follow the DES standard). |
|
| 418 | + * |
|
| 419 | + * @param string $bin A 64-bit binary string |
|
| 420 | + * @return string A 64-bit binary string that has been run through self::$_fp[] table |
|
| 421 | + */ |
|
| 422 | + private function fp($bin) |
|
| 423 | + { |
|
| 424 | + $fp = ""; |
|
| 425 | + for($i = 0; $i < 64; ++$i) |
|
| 426 | + $fp .= $bin[self::$_fp[$i] - 1]; |
|
| 427 | + |
|
| 428 | + return $fp; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * Initialize all the tables, this function is called inside the constructor |
|
| 434 | + * |
|
| 435 | + * @return void |
|
| 436 | + */ |
|
| 437 | + private function initTables() |
|
| 438 | + { |
|
| 439 | + // permuted choice 1 (PC1) |
|
| 440 | + // these values are chars and should be run through chr() when used |
|
| 441 | + self::$_pc1 = array( |
|
| 442 | + 57, 49, 41, 33, 25, 17, 9, |
|
| 443 | + 1, 58, 50, 42, 34, 26, 18, |
|
| 444 | + 10, 2, 59, 51, 43, 35, 27, |
|
| 445 | + 19, 11, 3, 60, 52, 44, 36, |
|
| 446 | + 63, 55, 47, 39, 31, 23, 15, |
|
| 447 | + 7, 62, 54, 46, 38, 30, 22, |
|
| 448 | + 14, 6, 61, 53, 45, 37, 29, |
|
| 449 | + 21, 13, 5, 28, 20, 12, 4 |
|
| 450 | + ); |
|
| 451 | + |
|
| 452 | + // permuted choice 2 (PC2) |
|
| 453 | + // these values are chars and should be run through chr() when used |
|
| 454 | + self::$_pc2 = array( |
|
| 455 | + 14, 17, 11, 24, 1, 5, |
|
| 456 | + 3, 28, 15, 6, 21, 10, |
|
| 457 | + 23, 19, 12, 4, 26, 8, |
|
| 458 | + 16, 7, 27, 20, 13, 2, |
|
| 459 | + 41, 52, 31, 37, 47, 55, |
|
| 460 | + 30, 40, 51, 45, 33, 48, |
|
| 461 | + 44, 49, 39, 56, 34, 53, |
|
| 462 | + 46, 42, 50, 36, 29, 32 |
|
| 463 | + ); |
|
| 464 | + |
|
| 465 | + // initial permutation (IP) |
|
| 466 | + self::$_ip = array( |
|
| 467 | + 58, 50, 42, 34, 26, 18, 10, 2, |
|
| 468 | + 60, 52, 44, 36, 28, 20, 12, 4, |
|
| 469 | + 62, 54, 46, 38, 30, 22, 14, 6, |
|
| 470 | + 64, 56, 48, 40, 32, 24, 16, 8, |
|
| 471 | + 57, 49, 41, 33, 25, 17, 9, 1, |
|
| 472 | + 59, 51, 43, 35, 27, 19, 11, 3, |
|
| 473 | + 61, 53, 45, 37, 29, 21, 13, 5, |
|
| 474 | + 63, 55, 47, 39, 31, 23, 15, 7 |
|
| 475 | + ); |
|
| 476 | + |
|
| 477 | + // expansion (E) |
|
| 478 | + self::$_e = array( |
|
| 479 | + 32, 1, 2, 3, 4, 5, |
|
| 480 | + 4, 5, 6, 7, 8, 9, |
|
| 481 | + 8, 9, 10, 11, 12, 13, |
|
| 482 | + 12, 13, 14, 15, 16, 17, |
|
| 483 | + 16, 17, 18, 19, 20, 21, |
|
| 484 | + 20, 21, 22, 23, 24, 25, |
|
| 485 | + 24, 25, 26, 27, 28, 29, |
|
| 486 | + 28, 29, 30, 31, 32, 1 |
|
| 487 | + ); |
|
| 488 | + |
|
| 489 | + // substition box (S) |
|
| 490 | + self::$_s = array( |
|
| 491 | + /* S1 */ |
|
| 492 | + array( |
|
| 493 | + 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, |
|
| 494 | + 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, |
|
| 495 | + 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, |
|
| 496 | + 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 |
|
| 497 | + ), |
|
| 498 | + |
|
| 499 | + /* S2 */ |
|
| 500 | + array( |
|
| 501 | + 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, |
|
| 502 | + 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, |
|
| 503 | + 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, |
|
| 504 | + 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 |
|
| 505 | + ), |
|
| 506 | + |
|
| 507 | + /* S3 */ |
|
| 508 | + array( |
|
| 509 | + 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, |
|
| 510 | + 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, |
|
| 511 | + 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, |
|
| 512 | + 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 |
|
| 513 | + ), |
|
| 514 | + |
|
| 515 | + /* S4 */ |
|
| 516 | + array( |
|
| 517 | + 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, |
|
| 518 | + 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, |
|
| 519 | + 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, |
|
| 520 | + 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 |
|
| 521 | + ), |
|
| 522 | + |
|
| 523 | + /* S5 */ |
|
| 524 | + array( |
|
| 525 | + 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, |
|
| 526 | + 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, |
|
| 527 | + 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, |
|
| 528 | + 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 |
|
| 529 | + ), |
|
| 530 | + |
|
| 531 | + /* S6 */ |
|
| 532 | + array( |
|
| 533 | + 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, |
|
| 534 | + 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, |
|
| 535 | + 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, |
|
| 536 | + 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 |
|
| 537 | + ), |
|
| 538 | + |
|
| 539 | + /* S7 */ |
|
| 540 | + array( |
|
| 541 | + 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, |
|
| 542 | + 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, |
|
| 543 | + 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, |
|
| 544 | + 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12 |
|
| 545 | + ), |
|
| 546 | + |
|
| 547 | + /* S8 */ |
|
| 548 | + array( |
|
| 549 | + 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, |
|
| 550 | + 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, |
|
| 551 | + 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, |
|
| 552 | + 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11 |
|
| 553 | + ) |
|
| 554 | + ); |
|
| 555 | + |
|
| 556 | + // permutation (P) |
|
| 557 | + self::$_p = array( |
|
| 558 | + 16, 7, 20, 21, |
|
| 559 | + 29, 12, 28, 17, |
|
| 560 | + 1, 15, 23, 26, |
|
| 561 | + 5, 18, 31, 10, |
|
| 562 | + 2, 8, 24, 14, |
|
| 563 | + 32, 27, 3, 9, |
|
| 564 | + 19, 13, 30, 6, |
|
| 565 | + 22, 11, 4, 25 |
|
| 566 | + ); |
|
| 567 | + |
|
| 568 | + // final permutation (FP) |
|
| 569 | + self::$_fp = array( |
|
| 570 | + 40, 8, 48, 16, 56, 24, 64, 32, |
|
| 571 | + 39, 7, 47, 15, 55, 23, 63, 31, |
|
| 572 | + 38, 6, 46, 14, 54, 22, 62, 30, |
|
| 573 | + 37, 5, 45, 13, 53, 21, 61, 29, |
|
| 574 | + 36, 4, 44, 12, 52, 20, 60, 28, |
|
| 575 | + 35, 3, 43, 11, 51, 19, 59, 27, |
|
| 576 | + 34, 2, 42, 10, 50, 18, 58, 26, |
|
| 577 | + 33, 1, 41, 9, 49, 17, 57, 25 |
|
| 578 | + ); |
|
| 579 | + |
|
| 580 | + // key schedule used in KeyPermutation() |
|
| 581 | + self::$_key_sched = array(1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1); |
|
| 582 | + } |
|
| 583 | + |
|
| 584 | + |
|
| 585 | + /** |
|
| 586 | + * Indicates this is a block cipher |
|
| 587 | + * |
|
| 588 | + * @return integer Returns Cipher::BLOCK |
|
| 589 | + */ |
|
| 590 | + public function type() |
|
| 591 | + { |
|
| 592 | + return parent::BLOCK; |
|
| 593 | + } |
|
| 594 | 594 | } |
| 595 | 595 | ?> |
@@ -44,206 +44,206 @@ |
||
| 44 | 44 | */ |
| 45 | 45 | class Cipher_Vigenere extends Cipher |
| 46 | 46 | { |
| 47 | - /** @type array $_vtable The Vigenere table */ |
|
| 48 | - private static $_vtable = null; |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Constructor |
|
| 53 | - * |
|
| 54 | - * @param string $key The key used for Encryption/Decryption |
|
| 55 | - * @return void |
|
| 56 | - */ |
|
| 57 | - public function __construct($key) |
|
| 58 | - { |
|
| 59 | - // set the key |
|
| 60 | - parent::__construct(PHP_Crypt::CIPHER_VIGENERE, $key); |
|
| 61 | - |
|
| 62 | - $this->initTables(); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Destructor |
|
| 68 | - * |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - public function __destruct() |
|
| 72 | - { |
|
| 73 | - parent::__destruct(); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Encrypt plain text data using Vigenere cipher |
|
| 79 | - * |
|
| 80 | - * @param string $data A plain text string |
|
| 81 | - * @return boolean Returns true |
|
| 82 | - */ |
|
| 83 | - public function encrypt(&$text) |
|
| 84 | - { |
|
| 85 | - $this->operation(parent::ENCRYPT); |
|
| 86 | - |
|
| 87 | - // convert to uppercase, and remove any non alphabetic characters |
|
| 88 | - $text = strtoupper($text); |
|
| 89 | - $text = preg_replace("/[^A-Z]/", "", $text); |
|
| 90 | - $len = strlen($text); |
|
| 91 | - |
|
| 92 | - // prepare the key for the cipher |
|
| 93 | - $this->keyPrep($len); |
|
| 94 | - |
|
| 95 | - // loop through each letter of the message |
|
| 96 | - for($i = 0; $i < $len; ++$i) |
|
| 97 | - { |
|
| 98 | - // get the Cipher letter from the Vigenere table, using the |
|
| 99 | - // current letter from the key as the row, and the current letter |
|
| 100 | - // from the text, as the column, subtract 65 because ascii upper case |
|
| 101 | - // letters start at 65 |
|
| 102 | - $row = ord($this->expanded_key[$i]) - 65; |
|
| 103 | - $col = ord($text[$i]) - 65; |
|
| 104 | - $pos = ($row * 26) + $col; |
|
| 105 | - |
|
| 106 | - // convert the plain text to cipher text |
|
| 107 | - $text[$i] = self::$_vtable[$pos]; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - return true; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Decrypt a Vigenere encrypted string |
|
| 116 | - * |
|
| 117 | - * @param string $encrypted A Vigenere encrypted string |
|
| 118 | - * @return boolean Returns true |
|
| 119 | - */ |
|
| 120 | - public function decrypt(&$text) |
|
| 121 | - { |
|
| 122 | - $this->operation(parent::DECRYPT); |
|
| 123 | - |
|
| 124 | - // ensure the cipher text is all uppercase |
|
| 125 | - $text = strtoupper($text); |
|
| 126 | - $len = strlen($text); |
|
| 127 | - |
|
| 128 | - // prepare the key for the cipher |
|
| 129 | - $this->keyPrep($len); |
|
| 130 | - |
|
| 131 | - // go to the row corresponding to the letter from the key |
|
| 132 | - for($i = 0; $i < $len; ++$i) |
|
| 133 | - { |
|
| 134 | - // find the row from the current character of the key, we subtract 65 |
|
| 135 | - // because uppercase letters start at ASCII 65 |
|
| 136 | - $row = (ord($this->expanded_key[$i]) - 65) * 26; |
|
| 137 | - |
|
| 138 | - // loop throw the entire row in the table until we find the letter |
|
| 139 | - // that matches the letter from the encrypted text |
|
| 140 | - for($j = 0; $j < 26; ++$j) |
|
| 141 | - { |
|
| 142 | - // save the position we are in in the row |
|
| 143 | - $pos = $row + $j; |
|
| 144 | - |
|
| 145 | - // compare the letter from the table to the letter in the cipher text |
|
| 146 | - if(self::$_vtable[$pos] == $text[$i]) |
|
| 147 | - { |
|
| 148 | - // bingo, we found it. The plain text is the letter associated with |
|
| 149 | - // with the column position, again add 65 because ascii capital |
|
| 150 | - // letters start at 65 |
|
| 151 | - $text[$i] = chr($j + 65); |
|
| 152 | - break; |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - return true; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Prepare the key. The key can only contain uppercase letters. |
|
| 163 | - * All other characters are stripped out. The key length must match |
|
| 164 | - * The length of the message |
|
| 165 | - * |
|
| 166 | - * @param integer $len The length of message |
|
| 167 | - * @return void |
|
| 168 | - */ |
|
| 169 | - private function keyPrep($len) |
|
| 170 | - { |
|
| 171 | - // we never modify the actual key, so we save it into another variable |
|
| 172 | - $this->expanded_key = $this->key(); |
|
| 173 | - $this->expanded_key = strtoupper($this->expanded_key); |
|
| 174 | - $this->expanded_key = preg_replace("/[^A-Z]/", "", $this->expanded_key); |
|
| 175 | - $keylen = strlen($this->expanded_key); |
|
| 176 | - |
|
| 177 | - // The key must be prepared so that it is the same length as the |
|
| 178 | - // message. If it is longer or shorter we need to modify it |
|
| 179 | - // to make it the correct length |
|
| 180 | - if($keylen > $len) |
|
| 181 | - $this->expanded_key = substr($this->expanded_key, 0, $len); |
|
| 182 | - else if($len > $keylen) |
|
| 183 | - { |
|
| 184 | - // if the key is shorter than the message, then we need pad the key |
|
| 185 | - // by repeating it until it is the correct length |
|
| 186 | - $diff = $len - $keylen; |
|
| 187 | - $pos = 0; |
|
| 188 | - |
|
| 189 | - for($i = 0; $i < $diff; ++$i) |
|
| 190 | - { |
|
| 191 | - if($pos >= $keylen) |
|
| 192 | - $pos = 0; |
|
| 193 | - |
|
| 194 | - $this->expanded_key .= $this->expanded_key[$pos]; |
|
| 195 | - ++$pos; |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * Initialize the Vigenere table used for encryption & decryption |
|
| 203 | - * |
|
| 204 | - * @return void |
|
| 205 | - */ |
|
| 206 | - private function initTables() |
|
| 207 | - { |
|
| 208 | - self::$_vtable = array( |
|
| 209 | - 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z', |
|
| 210 | - 'B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A', |
|
| 211 | - 'C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B', |
|
| 212 | - 'D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C', |
|
| 213 | - 'E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D', |
|
| 214 | - 'F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E', |
|
| 215 | - 'G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F', |
|
| 216 | - 'H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G', |
|
| 217 | - 'I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H', |
|
| 218 | - 'J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I', |
|
| 219 | - 'K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J', |
|
| 220 | - 'L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K', |
|
| 221 | - 'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L', |
|
| 222 | - 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M', |
|
| 223 | - 'O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N', |
|
| 224 | - 'P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O', |
|
| 225 | - 'Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P', |
|
| 226 | - 'R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q', |
|
| 227 | - 'S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R', |
|
| 228 | - 'T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S', |
|
| 229 | - 'U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T', |
|
| 230 | - 'V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U', |
|
| 231 | - 'W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V', |
|
| 232 | - 'X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W', |
|
| 233 | - 'Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X', |
|
| 234 | - 'Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y' |
|
| 235 | - ); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * Indicates that this is a stream cipher |
|
| 241 | - * |
|
| 242 | - * @return integer Returns Cipher::STREAM |
|
| 243 | - */ |
|
| 244 | - public function type() |
|
| 245 | - { |
|
| 246 | - return parent::STREAM; |
|
| 247 | - } |
|
| 47 | + /** @type array $_vtable The Vigenere table */ |
|
| 48 | + private static $_vtable = null; |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Constructor |
|
| 53 | + * |
|
| 54 | + * @param string $key The key used for Encryption/Decryption |
|
| 55 | + * @return void |
|
| 56 | + */ |
|
| 57 | + public function __construct($key) |
|
| 58 | + { |
|
| 59 | + // set the key |
|
| 60 | + parent::__construct(PHP_Crypt::CIPHER_VIGENERE, $key); |
|
| 61 | + |
|
| 62 | + $this->initTables(); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Destructor |
|
| 68 | + * |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + public function __destruct() |
|
| 72 | + { |
|
| 73 | + parent::__destruct(); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Encrypt plain text data using Vigenere cipher |
|
| 79 | + * |
|
| 80 | + * @param string $data A plain text string |
|
| 81 | + * @return boolean Returns true |
|
| 82 | + */ |
|
| 83 | + public function encrypt(&$text) |
|
| 84 | + { |
|
| 85 | + $this->operation(parent::ENCRYPT); |
|
| 86 | + |
|
| 87 | + // convert to uppercase, and remove any non alphabetic characters |
|
| 88 | + $text = strtoupper($text); |
|
| 89 | + $text = preg_replace("/[^A-Z]/", "", $text); |
|
| 90 | + $len = strlen($text); |
|
| 91 | + |
|
| 92 | + // prepare the key for the cipher |
|
| 93 | + $this->keyPrep($len); |
|
| 94 | + |
|
| 95 | + // loop through each letter of the message |
|
| 96 | + for($i = 0; $i < $len; ++$i) |
|
| 97 | + { |
|
| 98 | + // get the Cipher letter from the Vigenere table, using the |
|
| 99 | + // current letter from the key as the row, and the current letter |
|
| 100 | + // from the text, as the column, subtract 65 because ascii upper case |
|
| 101 | + // letters start at 65 |
|
| 102 | + $row = ord($this->expanded_key[$i]) - 65; |
|
| 103 | + $col = ord($text[$i]) - 65; |
|
| 104 | + $pos = ($row * 26) + $col; |
|
| 105 | + |
|
| 106 | + // convert the plain text to cipher text |
|
| 107 | + $text[$i] = self::$_vtable[$pos]; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + return true; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Decrypt a Vigenere encrypted string |
|
| 116 | + * |
|
| 117 | + * @param string $encrypted A Vigenere encrypted string |
|
| 118 | + * @return boolean Returns true |
|
| 119 | + */ |
|
| 120 | + public function decrypt(&$text) |
|
| 121 | + { |
|
| 122 | + $this->operation(parent::DECRYPT); |
|
| 123 | + |
|
| 124 | + // ensure the cipher text is all uppercase |
|
| 125 | + $text = strtoupper($text); |
|
| 126 | + $len = strlen($text); |
|
| 127 | + |
|
| 128 | + // prepare the key for the cipher |
|
| 129 | + $this->keyPrep($len); |
|
| 130 | + |
|
| 131 | + // go to the row corresponding to the letter from the key |
|
| 132 | + for($i = 0; $i < $len; ++$i) |
|
| 133 | + { |
|
| 134 | + // find the row from the current character of the key, we subtract 65 |
|
| 135 | + // because uppercase letters start at ASCII 65 |
|
| 136 | + $row = (ord($this->expanded_key[$i]) - 65) * 26; |
|
| 137 | + |
|
| 138 | + // loop throw the entire row in the table until we find the letter |
|
| 139 | + // that matches the letter from the encrypted text |
|
| 140 | + for($j = 0; $j < 26; ++$j) |
|
| 141 | + { |
|
| 142 | + // save the position we are in in the row |
|
| 143 | + $pos = $row + $j; |
|
| 144 | + |
|
| 145 | + // compare the letter from the table to the letter in the cipher text |
|
| 146 | + if(self::$_vtable[$pos] == $text[$i]) |
|
| 147 | + { |
|
| 148 | + // bingo, we found it. The plain text is the letter associated with |
|
| 149 | + // with the column position, again add 65 because ascii capital |
|
| 150 | + // letters start at 65 |
|
| 151 | + $text[$i] = chr($j + 65); |
|
| 152 | + break; |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + return true; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Prepare the key. The key can only contain uppercase letters. |
|
| 163 | + * All other characters are stripped out. The key length must match |
|
| 164 | + * The length of the message |
|
| 165 | + * |
|
| 166 | + * @param integer $len The length of message |
|
| 167 | + * @return void |
|
| 168 | + */ |
|
| 169 | + private function keyPrep($len) |
|
| 170 | + { |
|
| 171 | + // we never modify the actual key, so we save it into another variable |
|
| 172 | + $this->expanded_key = $this->key(); |
|
| 173 | + $this->expanded_key = strtoupper($this->expanded_key); |
|
| 174 | + $this->expanded_key = preg_replace("/[^A-Z]/", "", $this->expanded_key); |
|
| 175 | + $keylen = strlen($this->expanded_key); |
|
| 176 | + |
|
| 177 | + // The key must be prepared so that it is the same length as the |
|
| 178 | + // message. If it is longer or shorter we need to modify it |
|
| 179 | + // to make it the correct length |
|
| 180 | + if($keylen > $len) |
|
| 181 | + $this->expanded_key = substr($this->expanded_key, 0, $len); |
|
| 182 | + else if($len > $keylen) |
|
| 183 | + { |
|
| 184 | + // if the key is shorter than the message, then we need pad the key |
|
| 185 | + // by repeating it until it is the correct length |
|
| 186 | + $diff = $len - $keylen; |
|
| 187 | + $pos = 0; |
|
| 188 | + |
|
| 189 | + for($i = 0; $i < $diff; ++$i) |
|
| 190 | + { |
|
| 191 | + if($pos >= $keylen) |
|
| 192 | + $pos = 0; |
|
| 193 | + |
|
| 194 | + $this->expanded_key .= $this->expanded_key[$pos]; |
|
| 195 | + ++$pos; |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * Initialize the Vigenere table used for encryption & decryption |
|
| 203 | + * |
|
| 204 | + * @return void |
|
| 205 | + */ |
|
| 206 | + private function initTables() |
|
| 207 | + { |
|
| 208 | + self::$_vtable = array( |
|
| 209 | + 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z', |
|
| 210 | + 'B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A', |
|
| 211 | + 'C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B', |
|
| 212 | + 'D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C', |
|
| 213 | + 'E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D', |
|
| 214 | + 'F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E', |
|
| 215 | + 'G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F', |
|
| 216 | + 'H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G', |
|
| 217 | + 'I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H', |
|
| 218 | + 'J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I', |
|
| 219 | + 'K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J', |
|
| 220 | + 'L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K', |
|
| 221 | + 'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L', |
|
| 222 | + 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M', |
|
| 223 | + 'O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N', |
|
| 224 | + 'P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O', |
|
| 225 | + 'Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P', |
|
| 226 | + 'R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q', |
|
| 227 | + 'S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R', |
|
| 228 | + 'T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S', |
|
| 229 | + 'U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T', |
|
| 230 | + 'V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U', |
|
| 231 | + 'W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V', |
|
| 232 | + 'X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W', |
|
| 233 | + 'Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X', |
|
| 234 | + 'Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y' |
|
| 235 | + ); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * Indicates that this is a stream cipher |
|
| 241 | + * |
|
| 242 | + * @return integer Returns Cipher::STREAM |
|
| 243 | + */ |
|
| 244 | + public function type() |
|
| 245 | + { |
|
| 246 | + return parent::STREAM; |
|
| 247 | + } |
|
| 248 | 248 | } |
| 249 | 249 | ?> |
@@ -38,619 +38,619 @@ |
||
| 38 | 38 | */ |
| 39 | 39 | class Cipher_CAST_256 extends Cipher |
| 40 | 40 | { |
| 41 | - /** @type integer BYTES_BLOCK The size of the block, in bytes */ |
|
| 42 | - const BYTES_BLOCK = 16; // 128 bits; |
|
| 43 | - |
|
| 44 | - //const BYTES_KEY = 0; // between 128, 160, 192, 224, 256 bits |
|
| 45 | - |
|
| 46 | - /** @type integer BYTES_KEY_MAX The max key size, in bytes */ |
|
| 47 | - const BYTES_KEY_MAX = 32; |
|
| 48 | - |
|
| 49 | - /** @type array $_s1 An array of 256 unsigned integers */ |
|
| 50 | - private static $_s1 = array(); |
|
| 51 | - |
|
| 52 | - /** @type array $_s2 An array of 256 unsigned integers */ |
|
| 53 | - private static $_s2 = array(); |
|
| 54 | - |
|
| 55 | - /** @type array $_s3 An array of 256 unsigned integers */ |
|
| 56 | - private static $_s3 = array(); |
|
| 57 | - |
|
| 58 | - /** @type array $_s4 An array of 256 unsigned integers */ |
|
| 59 | - private static $_s4 = array(); |
|
| 60 | - |
|
| 61 | - private static $_req_key_sizes = array(16, 20, 24, 28, 32); |
|
| 62 | - |
|
| 63 | - /** @type string $_mkey The 16 byte masking subkey */ |
|
| 64 | - private $_mkey = array(); |
|
| 65 | - |
|
| 66 | - /** @type string $_rkey The 16 byte rotate subkey */ |
|
| 67 | - private $_rkey = array(); |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Constructor |
|
| 72 | - * |
|
| 73 | - * @param string $key The key used for Encryption/Decryption |
|
| 74 | - * @return void |
|
| 75 | - */ |
|
| 76 | - public function __construct($key) |
|
| 77 | - { |
|
| 78 | - $keylen = strlen($key); |
|
| 79 | - |
|
| 80 | - if($keylen > self::BYTES_KEY_MAX) |
|
| 81 | - { |
|
| 82 | - $key = substr($key, 0, self::BYTES_KEY_MAX); |
|
| 83 | - $keylen = self::BYTES_KEY_MAX; |
|
| 84 | - } |
|
| 85 | - else if(!in_array($keylen, self::$_req_key_sizes)) |
|
| 86 | - { |
|
| 87 | - $msg = PHP_Crypt::CIPHER_CAST_256." requires a key size of 16, "; |
|
| 88 | - $msg .= "20, 24, 28, or 32 bytes."; |
|
| 89 | - trigger_error($msg, E_USER_WARNING); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - // set the key, make sure the required length is set in bytes |
|
| 93 | - parent::__construct(PHP_Crypt::CIPHER_CAST_256, $key, $keylen); |
|
| 94 | - |
|
| 95 | - // set the block size |
|
| 96 | - $this->blockSize(self::BYTES_BLOCK); |
|
| 97 | - |
|
| 98 | - // initialize the sboxes constants |
|
| 99 | - $this->initTables(); |
|
| 100 | - |
|
| 101 | - // create the sub keys using the sboxes |
|
| 102 | - $this->createSubKeys(); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Destructor |
|
| 108 | - * |
|
| 109 | - * @return void |
|
| 110 | - */ |
|
| 111 | - public function __destruct() |
|
| 112 | - { |
|
| 113 | - parent::__destruct(); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Encrypt plain text data |
|
| 119 | - * |
|
| 120 | - * @param string $data A 128 bit block of plain data |
|
| 121 | - * @return boolean Returns true |
|
| 122 | - */ |
|
| 123 | - public function encrypt(&$data) |
|
| 124 | - { |
|
| 125 | - $this->operation(parent::ENCRYPT); |
|
| 126 | - |
|
| 127 | - // first split the data into four 32 bit blocks, reverse |
|
| 128 | - // the string order of each block, convert the blocks of data to integers |
|
| 129 | - $data = str_split($data, 4); |
|
| 130 | - $data = array_map("strrev", $data); |
|
| 131 | - $data = array_map("parent::str2Dec", $data); |
|
| 132 | - |
|
| 133 | - // do the first 6 loops |
|
| 134 | - for($i = 0; $i < 6; ++$i) |
|
| 135 | - { |
|
| 136 | - |
|
| 137 | - $data[2] ^= $this->f1($data[3], $this->_mkey[$i][0], $this->_rkey[$i][0]); |
|
| 138 | - $data[1] ^= $this->f2($data[2], $this->_mkey[$i][1], $this->_rkey[$i][1]); |
|
| 139 | - $data[0] ^= $this->f3($data[1], $this->_mkey[$i][2], $this->_rkey[$i][2]); |
|
| 140 | - $data[3] ^= $this->f1($data[0], $this->_mkey[$i][3], $this->_rkey[$i][3]); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - // the second 6 loops are done in a different order |
|
| 144 | - for($i = 6; $i < 12; ++$i) |
|
| 145 | - { |
|
| 146 | - |
|
| 147 | - $data[3] ^= $this->f1($data[0], $this->_mkey[$i][3], $this->_rkey[$i][3]); |
|
| 148 | - $data[0] ^= $this->f3($data[1], $this->_mkey[$i][2], $this->_rkey[$i][2]); |
|
| 149 | - $data[1] ^= $this->f2($data[2], $this->_mkey[$i][1], $this->_rkey[$i][1]); |
|
| 150 | - $data[2] ^= $this->f1($data[3], $this->_mkey[$i][0], $this->_rkey[$i][0]); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - // convert the decimals back to a string, reverse the string so it's |
|
| 154 | - // in the correct order |
|
| 155 | - $data = array_map(function($v) { |
|
| 156 | - $v = Core::dec2Str($v, 4); |
|
| 157 | - return strrev($v); |
|
| 158 | - }, $data); |
|
| 159 | - |
|
| 160 | - // glue the string back together |
|
| 161 | - $data = implode("", $data); |
|
| 162 | - |
|
| 163 | - return true; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Decrypt an encrypted string, it does all the steps of encryption, |
|
| 169 | - * but in reverse. |
|
| 170 | - * |
|
| 171 | - * @param string $data A 128 bit block of encrypted data |
|
| 172 | - * @return boolean Returns true |
|
| 173 | - */ |
|
| 174 | - public function decrypt(&$data) |
|
| 175 | - { |
|
| 176 | - $this->operation(parent::DECRYPT); |
|
| 177 | - |
|
| 178 | - // first split the data into four 32 bit blocks, reverse |
|
| 179 | - // the string order of each block, convert the blocks of data to integers |
|
| 180 | - $data = str_split($data, 4); |
|
| 181 | - $data = array_map("strrev", $data); |
|
| 182 | - $data = array_map("parent::str2Dec", $data); |
|
| 183 | - |
|
| 184 | - // do the first 6 loops |
|
| 185 | - for($i = 11; $i >= 6; --$i) |
|
| 186 | - { |
|
| 187 | - $data[2] ^= $this->f1($data[3], $this->_mkey[$i][0], $this->_rkey[$i][0]); |
|
| 188 | - $data[1] ^= $this->f2($data[2], $this->_mkey[$i][1], $this->_rkey[$i][1]); |
|
| 189 | - $data[0] ^= $this->f3($data[1], $this->_mkey[$i][2], $this->_rkey[$i][2]); |
|
| 190 | - $data[3] ^= $this->f1($data[0], $this->_mkey[$i][3], $this->_rkey[$i][3]); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - // the second 6 loops are done in a different order |
|
| 194 | - for($i = 5; $i >= 0; --$i) |
|
| 195 | - { |
|
| 196 | - $data[3] ^= $this->f1($data[0], $this->_mkey[$i][3], $this->_rkey[$i][3]); |
|
| 197 | - $data[0] ^= $this->f3($data[1], $this->_mkey[$i][2], $this->_rkey[$i][2]); |
|
| 198 | - $data[1] ^= $this->f2($data[2], $this->_mkey[$i][1], $this->_rkey[$i][1]); |
|
| 199 | - $data[2] ^= $this->f1($data[3], $this->_mkey[$i][0], $this->_rkey[$i][0]); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - // convert the decimals back to a string, reverse the string so it's |
|
| 203 | - // in the correct order |
|
| 204 | - $data = array_map(function($v) { |
|
| 205 | - $v = Core::dec2Str($v, 4); |
|
| 206 | - return strrev($v); |
|
| 207 | - }, $data); |
|
| 208 | - |
|
| 209 | - // glue the string back together |
|
| 210 | - $data = implode("", $data); |
|
| 211 | - |
|
| 212 | - return true; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * CAST-256 F1 function |
|
| 218 | - * |
|
| 219 | - * @param $d integer The the data input |
|
| 220 | - * @param $m integer The 32 bit masking key |
|
| 221 | - * @param $r integer The round number |
|
| 222 | - * @return integer The value after the F1 calculation |
|
| 223 | - */ |
|
| 224 | - private function f1($d, $m, $r) |
|
| 225 | - { |
|
| 226 | - $n = parent::uInt32($m + $d); |
|
| 227 | - $n = parent::uInt32(parent::rotBitsLeft32($n, $r)); |
|
| 228 | - $n = parent::dec2Str($n, 4); |
|
| 229 | - |
|
| 230 | - return parent::uInt32( |
|
| 231 | - ((self::$_s1[ord($n[0])] ^ self::$_s2[ord($n[1])]) - |
|
| 232 | - self::$_s3[ord($n[2])]) + self::$_s4[ord($n[3])] |
|
| 233 | - ); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * CAST-256 F2 function |
|
| 239 | - * |
|
| 240 | - * @param $d integer The the data input |
|
| 241 | - * @param $m integer The 32 bit masking key |
|
| 242 | - * @param $r integer The round number |
|
| 243 | - * @return integer The value after the F2 calculation |
|
| 244 | - */ |
|
| 245 | - private function f2($d, $m, $r) |
|
| 246 | - { |
|
| 247 | - $n = parent::uInt32($m ^ $d); |
|
| 248 | - $n = parent::uInt32(parent::rotBitsLeft32($n, $r)); |
|
| 249 | - $n = parent::dec2Str($n, 4); |
|
| 250 | - |
|
| 251 | - return parent::uInt32( |
|
| 252 | - ((self::$_s1[ord($n[0])] - self::$_s2[ord($n[1])]) + |
|
| 253 | - self::$_s3[ord($n[2])]) ^ self::$_s4[ord($n[3])] |
|
| 254 | - ); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * CAST-256 F3 function |
|
| 260 | - * |
|
| 261 | - * @param $d integer The the data input |
|
| 262 | - * @param $m integer The 32 bit masking key |
|
| 263 | - * @param $r integer The round number |
|
| 264 | - * @return integer The value after the F3 calculation |
|
| 265 | - */ |
|
| 266 | - private function f3($d, $m, $r) |
|
| 267 | - { |
|
| 268 | - $n = parent::uInt32($m - $d); |
|
| 269 | - $n = parent::uInt32(parent::rotBitsLeft32($n, $r)); |
|
| 270 | - $n = parent::dec2Str($n, 4); |
|
| 271 | - |
|
| 272 | - return parent::uInt32( |
|
| 273 | - ((self::$_s1[ord($n[0])] + self::$_s2[ord($n[1])]) ^ |
|
| 274 | - self::$_s3[ord($n[2])]) - self::$_s4[ord($n[3])] |
|
| 275 | - ); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * Creates the subkeys $_mkey (the masking key) and |
|
| 281 | - * $_rkey (the rotate key) which are 16 bytes each. These are |
|
| 282 | - * created from the original key. The original key is null |
|
| 283 | - * padded up to 16 bytes and expanded to 32 bytes. It is then |
|
| 284 | - * split in half to create $_mkey and $_rkey |
|
| 285 | - * |
|
| 286 | - * @return void |
|
| 287 | - */ |
|
| 288 | - private function createSubKeys() |
|
| 289 | - { |
|
| 290 | - $cm = 0x5A827999; |
|
| 291 | - $mm = 0x6ED9EBA1; |
|
| 292 | - $cr = 19; |
|
| 293 | - $mr = 17; |
|
| 294 | - $tm = array(); |
|
| 295 | - $tr = array(); |
|
| 296 | - $xkey = $this->key(); |
|
| 297 | - $tmpkey = array(); |
|
| 298 | - |
|
| 299 | - // if the key is less than 32 bytes, pad it to 32 bytes |
|
| 300 | - // for the key expansion |
|
| 301 | - if($this->keySize() < 32) |
|
| 302 | - $xkey = str_pad($xkey, 32, "\0", STR_PAD_RIGHT); |
|
| 303 | - |
|
| 304 | - // split the key up into 4 byte parts, reverse the string, |
|
| 305 | - // then convert each part into a 32 bit integer |
|
| 306 | - $xkey = str_split($xkey, 4); |
|
| 307 | - $xkey = array_map("strrev", $xkey); |
|
| 308 | - $xkey = array_map("parent::str2Dec", $xkey); |
|
| 309 | - |
|
| 310 | - // set up the values need for creating round and masking keys |
|
| 311 | - for($i = 0; $i < 24; ++$i) |
|
| 312 | - { |
|
| 313 | - $tm[$i] = array(); |
|
| 314 | - $tr[$i] = array(); |
|
| 315 | - |
|
| 316 | - for($j = 0; $j < 8; ++$j) |
|
| 317 | - { |
|
| 318 | - $tm[$i][$j] = $cm; |
|
| 319 | - $cm = parent::uInt32($cm + $mm); |
|
| 320 | - $tr[$i][$j] = $cr; |
|
| 321 | - $cr = parent::uInt32($cr + $mr); |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - // now create the round and masking keys |
|
| 326 | - for($i = 0; $i < 12; ++$i) |
|
| 327 | - { |
|
| 328 | - $j = 2 * $i; |
|
| 329 | - |
|
| 330 | - $xkey[6] = parent::uInt32($xkey[6] ^ $this->f1($xkey[7], $tm[$j][0], $tr[$j][0])); |
|
| 331 | - $xkey[5] = parent::uInt32($xkey[5] ^ $this->f2($xkey[6], $tm[$j][1], $tr[$j][1])); |
|
| 332 | - $xkey[4] = parent::uInt32($xkey[4] ^ $this->f3($xkey[5], $tm[$j][2], $tr[$j][2])); |
|
| 333 | - $xkey[3] = parent::uInt32($xkey[3] ^ $this->f1($xkey[4], $tm[$j][3], $tr[$j][3])); |
|
| 334 | - $xkey[2] = parent::uInt32($xkey[2] ^ $this->f2($xkey[3], $tm[$j][4], $tr[$j][4])); |
|
| 335 | - $xkey[1] = parent::uInt32($xkey[1] ^ $this->f3($xkey[2], $tm[$j][5], $tr[$j][5])); |
|
| 336 | - $xkey[0] = parent::uInt32($xkey[0] ^ $this->f1($xkey[1], $tm[$j][6], $tr[$j][6])); |
|
| 337 | - $xkey[7] = parent::uInt32($xkey[7] ^ $this->f2($xkey[0], $tm[$j][7], $tr[$j][7])); |
|
| 338 | - |
|
| 339 | - $j = (2 * $i) + 1; |
|
| 340 | - $xkey[6] = parent::uInt32($xkey[6] ^ $this->f1($xkey[7], $tm[$j][0], $tr[$j][0])); |
|
| 341 | - $xkey[5] = parent::uInt32($xkey[5] ^ $this->f2($xkey[6], $tm[$j][1], $tr[$j][1])); |
|
| 342 | - $xkey[4] = parent::uInt32($xkey[4] ^ $this->f3($xkey[5], $tm[$j][2], $tr[$j][2])); |
|
| 343 | - $xkey[3] = parent::uInt32($xkey[3] ^ $this->f1($xkey[4], $tm[$j][3], $tr[$j][3])); |
|
| 344 | - $xkey[2] = parent::uInt32($xkey[2] ^ $this->f2($xkey[3], $tm[$j][4], $tr[$j][4])); |
|
| 345 | - $xkey[1] = parent::uInt32($xkey[1] ^ $this->f3($xkey[2], $tm[$j][5], $tr[$j][5])); |
|
| 346 | - $xkey[0] = parent::uInt32($xkey[0] ^ $this->f1($xkey[1], $tm[$j][6], $tr[$j][6])); |
|
| 347 | - $xkey[7] = parent::uInt32($xkey[7] ^ $this->f2($xkey[0], $tm[$j][7], $tr[$j][7])); |
|
| 348 | - |
|
| 349 | - // take the least 5 significant bits of each $xkey byte below and assign it |
|
| 350 | - // to the round key |
|
| 351 | - $this->_rkey[$i][0] = $xkey[0] & 31; |
|
| 352 | - $this->_rkey[$i][1] = $xkey[2] & 31; |
|
| 353 | - $this->_rkey[$i][2] = $xkey[4] & 31; |
|
| 354 | - $this->_rkey[$i][3] = $xkey[6] & 31; |
|
| 355 | - |
|
| 356 | - // now create 32 byte masking keys |
|
| 357 | - $this->_mkey[$i][0] = $xkey[7]; |
|
| 358 | - $this->_mkey[$i][1] = $xkey[5]; |
|
| 359 | - $this->_mkey[$i][2] = $xkey[3]; |
|
| 360 | - $this->_mkey[$i][3] = $xkey[1]; |
|
| 361 | - } |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * Initialize the tables |
|
| 367 | - * |
|
| 368 | - * @return void |
|
| 369 | - */ |
|
| 370 | - private function initTables() |
|
| 371 | - { |
|
| 372 | - // 256 unsigned 32 bit integers |
|
| 373 | - self::$_s1 = array( |
|
| 374 | - 0x30FB40D4, 0x9FA0FF0B, 0x6BECCD2F, 0x3F258C7A, |
|
| 375 | - 0x1E213F2F, 0x9C004DD3, 0x6003E540, 0xCF9FC949, |
|
| 376 | - 0xBFD4AF27, 0x88BBBDB5, 0xE2034090, 0x98D09675, |
|
| 377 | - 0x6E63A0E0, 0x15C361D2, 0xC2E7661D, 0x22D4FF8E, |
|
| 378 | - 0x28683B6F, 0xC07FD059, 0xFF2379C8, 0x775F50E2, |
|
| 379 | - 0x43C340D3, 0xDF2F8656, 0x887CA41A, 0xA2D2BD2D, |
|
| 380 | - 0xA1C9E0D6, 0x346C4819, 0x61B76D87, 0x22540F2F, |
|
| 381 | - 0x2ABE32E1, 0xAA54166B, 0x22568E3A, 0xA2D341D0, |
|
| 382 | - 0x66DB40C8, 0xA784392F, 0x004DFF2F, 0x2DB9D2DE, |
|
| 383 | - 0x97943FAC, 0x4A97C1D8, 0x527644B7, 0xB5F437A7, |
|
| 384 | - 0xB82CBAEF, 0xD751D159, 0x6FF7F0ED, 0x5A097A1F, |
|
| 385 | - 0x827B68D0, 0x90ECF52E, 0x22B0C054, 0xBC8E5935, |
|
| 386 | - 0x4B6D2F7F, 0x50BB64A2, 0xD2664910, 0xBEE5812D, |
|
| 387 | - 0xB7332290, 0xE93B159F, 0xB48EE411, 0x4BFF345D, |
|
| 388 | - 0xFD45C240, 0xAD31973F, 0xC4F6D02E, 0x55FC8165, |
|
| 389 | - 0xD5B1CAAD, 0xA1AC2DAE, 0xA2D4B76D, 0xC19B0C50, |
|
| 390 | - 0x882240F2, 0x0C6E4F38, 0xA4E4BFD7, 0x4F5BA272, |
|
| 391 | - 0x564C1D2F, 0xC59C5319, 0xB949E354, 0xB04669FE, |
|
| 392 | - 0xB1B6AB8A, 0xC71358DD, 0x6385C545, 0x110F935D, |
|
| 393 | - 0x57538AD5, 0x6A390493, 0xE63D37E0, 0x2A54F6B3, |
|
| 394 | - 0x3A787D5F, 0x6276A0B5, 0x19A6FCDF, 0x7A42206A, |
|
| 395 | - 0x29F9D4D5, 0xF61B1891, 0xBB72275E, 0xAA508167, |
|
| 396 | - 0x38901091, 0xC6B505EB, 0x84C7CB8C, 0x2AD75A0F, |
|
| 397 | - 0x874A1427, 0xA2D1936B, 0x2AD286AF, 0xAA56D291, |
|
| 398 | - 0xD7894360, 0x425C750D, 0x93B39E26, 0x187184C9, |
|
| 399 | - 0x6C00B32D, 0x73E2BB14, 0xA0BEBC3C, 0x54623779, |
|
| 400 | - 0x64459EAB, 0x3F328B82, 0x7718CF82, 0x59A2CEA6, |
|
| 401 | - 0x04EE002E, 0x89FE78E6, 0x3FAB0950, 0x325FF6C2, |
|
| 402 | - 0x81383F05, 0x6963C5C8, 0x76CB5AD6, 0xD49974C9, |
|
| 403 | - 0xCA180DCF, 0x380782D5, 0xC7FA5CF6, 0x8AC31511, |
|
| 404 | - 0x35E79E13, 0x47DA91D0, 0xF40F9086, 0xA7E2419E, |
|
| 405 | - 0x31366241, 0x051EF495, 0xAA573B04, 0x4A805D8D, |
|
| 406 | - 0x548300D0, 0x00322A3C, 0xBF64CDDF, 0xBA57A68E, |
|
| 407 | - 0x75C6372B, 0x50AFD341, 0xA7C13275, 0x915A0BF5, |
|
| 408 | - 0x6B54BFAB, 0x2B0B1426, 0xAB4CC9D7, 0x449CCD82, |
|
| 409 | - 0xF7FBF265, 0xAB85C5F3, 0x1B55DB94, 0xAAD4E324, |
|
| 410 | - 0xCFA4BD3F, 0x2DEAA3E2, 0x9E204D02, 0xC8BD25AC, |
|
| 411 | - 0xEADF55B3, 0xD5BD9E98, 0xE31231B2, 0x2AD5AD6C, |
|
| 412 | - 0x954329DE, 0xADBE4528, 0xD8710F69, 0xAA51C90F, |
|
| 413 | - 0xAA786BF6, 0x22513F1E, 0xAA51A79B, 0x2AD344CC, |
|
| 414 | - 0x7B5A41F0, 0xD37CFBAD, 0x1B069505, 0x41ECE491, |
|
| 415 | - 0xB4C332E6, 0x032268D4, 0xC9600ACC, 0xCE387E6D, |
|
| 416 | - 0xBF6BB16C, 0x6A70FB78, 0x0D03D9C9, 0xD4DF39DE, |
|
| 417 | - 0xE01063DA, 0x4736F464, 0x5AD328D8, 0xB347CC96, |
|
| 418 | - 0x75BB0FC3, 0x98511BFB, 0x4FFBCC35, 0xB58BCF6A, |
|
| 419 | - 0xE11F0ABC, 0xBFC5FE4A, 0xA70AEC10, 0xAC39570A, |
|
| 420 | - 0x3F04442F, 0x6188B153, 0xE0397A2E, 0x5727CB79, |
|
| 421 | - 0x9CEB418F, 0x1CACD68D, 0x2AD37C96, 0x0175CB9D, |
|
| 422 | - 0xC69DFF09, 0xC75B65F0, 0xD9DB40D8, 0xEC0E7779, |
|
| 423 | - 0x4744EAD4, 0xB11C3274, 0xDD24CB9E, 0x7E1C54BD, |
|
| 424 | - 0xF01144F9, 0xD2240EB1, 0x9675B3FD, 0xA3AC3755, |
|
| 425 | - 0xD47C27AF, 0x51C85F4D, 0x56907596, 0xA5BB15E6, |
|
| 426 | - 0x580304F0, 0xCA042CF1, 0x011A37EA, 0x8DBFAADB, |
|
| 427 | - 0x35BA3E4A, 0x3526FFA0, 0xC37B4D09, 0xBC306ED9, |
|
| 428 | - 0x98A52666, 0x5648F725, 0xFF5E569D, 0x0CED63D0, |
|
| 429 | - 0x7C63B2CF, 0x700B45E1, 0xD5EA50F1, 0x85A92872, |
|
| 430 | - 0xAF1FBDA7, 0xD4234870, 0xA7870BF3, 0x2D3B4D79, |
|
| 431 | - 0x42E04198, 0x0CD0EDE7, 0x26470DB8, 0xF881814C, |
|
| 432 | - 0x474D6AD7, 0x7C0C5E5C, 0xD1231959, 0x381B7298, |
|
| 433 | - 0xF5D2F4DB, 0xAB838653, 0x6E2F1E23, 0x83719C9E, |
|
| 434 | - 0xBD91E046, 0x9A56456E, 0xDC39200C, 0x20C8C571, |
|
| 435 | - 0x962BDA1C, 0xE1E696FF, 0xB141AB08, 0x7CCA89B9, |
|
| 436 | - 0x1A69E783, 0x02CC4843, 0xA2F7C579, 0x429EF47D, |
|
| 437 | - 0x427B169C, 0x5AC9F049, 0xDD8F0F00, 0x5C8165BF |
|
| 438 | - ); |
|
| 439 | - |
|
| 440 | - // 256 unsigned 32 bit integers |
|
| 441 | - self::$_s2 = array( |
|
| 442 | - 0x1F201094, 0xEF0BA75B, 0x69E3CF7E, 0x393F4380, |
|
| 443 | - 0xFE61CF7A, 0xEEC5207A, 0x55889C94, 0x72FC0651, |
|
| 444 | - 0xADA7EF79, 0x4E1D7235, 0xD55A63CE, 0xDE0436BA, |
|
| 445 | - 0x99C430EF, 0x5F0C0794, 0x18DCDB7D, 0xA1D6EFF3, |
|
| 446 | - 0xA0B52F7B, 0x59E83605, 0xEE15B094, 0xE9FFD909, |
|
| 447 | - 0xDC440086, 0xEF944459, 0xBA83CCB3, 0xE0C3CDFB, |
|
| 448 | - 0xD1DA4181, 0x3B092AB1, 0xF997F1C1, 0xA5E6CF7B, |
|
| 449 | - 0x01420DDB, 0xE4E7EF5B, 0x25A1FF41, 0xE180F806, |
|
| 450 | - 0x1FC41080, 0x179BEE7A, 0xD37AC6A9, 0xFE5830A4, |
|
| 451 | - 0x98DE8B7F, 0x77E83F4E, 0x79929269, 0x24FA9F7B, |
|
| 452 | - 0xE113C85B, 0xACC40083, 0xD7503525, 0xF7EA615F, |
|
| 453 | - 0x62143154, 0x0D554B63, 0x5D681121, 0xC866C359, |
|
| 454 | - 0x3D63CF73, 0xCEE234C0, 0xD4D87E87, 0x5C672B21, |
|
| 455 | - 0x071F6181, 0x39F7627F, 0x361E3084, 0xE4EB573B, |
|
| 456 | - 0x602F64A4, 0xD63ACD9C, 0x1BBC4635, 0x9E81032D, |
|
| 457 | - 0x2701F50C, 0x99847AB4, 0xA0E3DF79, 0xBA6CF38C, |
|
| 458 | - 0x10843094, 0x2537A95E, 0xF46F6FFE, 0xA1FF3B1F, |
|
| 459 | - 0x208CFB6A, 0x8F458C74, 0xD9E0A227, 0x4EC73A34, |
|
| 460 | - 0xFC884F69, 0x3E4DE8DF, 0xEF0E0088, 0x3559648D, |
|
| 461 | - 0x8A45388C, 0x1D804366, 0x721D9BFD, 0xA58684BB, |
|
| 462 | - 0xE8256333, 0x844E8212, 0x128D8098, 0xFED33FB4, |
|
| 463 | - 0xCE280AE1, 0x27E19BA5, 0xD5A6C252, 0xE49754BD, |
|
| 464 | - 0xC5D655DD, 0xEB667064, 0x77840B4D, 0xA1B6A801, |
|
| 465 | - 0x84DB26A9, 0xE0B56714, 0x21F043B7, 0xE5D05860, |
|
| 466 | - 0x54F03084, 0x066FF472, 0xA31AA153, 0xDADC4755, |
|
| 467 | - 0xB5625DBF, 0x68561BE6, 0x83CA6B94, 0x2D6ED23B, |
|
| 468 | - 0xECCF01DB, 0xA6D3D0BA, 0xB6803D5C, 0xAF77A709, |
|
| 469 | - 0x33B4A34C, 0x397BC8D6, 0x5EE22B95, 0x5F0E5304, |
|
| 470 | - 0x81ED6F61, 0x20E74364, 0xB45E1378, 0xDE18639B, |
|
| 471 | - 0x881CA122, 0xB96726D1, 0x8049A7E8, 0x22B7DA7B, |
|
| 472 | - 0x5E552D25, 0x5272D237, 0x79D2951C, 0xC60D894C, |
|
| 473 | - 0x488CB402, 0x1BA4FE5B, 0xA4B09F6B, 0x1CA815CF, |
|
| 474 | - 0xA20C3005, 0x8871DF63, 0xB9DE2FCB, 0x0CC6C9E9, |
|
| 475 | - 0x0BEEFF53, 0xE3214517, 0xB4542835, 0x9F63293C, |
|
| 476 | - 0xEE41E729, 0x6E1D2D7C, 0x50045286, 0x1E6685F3, |
|
| 477 | - 0xF33401C6, 0x30A22C95, 0x31A70850, 0x60930F13, |
|
| 478 | - 0x73F98417, 0xA1269859, 0xEC645C44, 0x52C877A9, |
|
| 479 | - 0xCDFF33A6, 0xA02B1741, 0x7CBAD9A2, 0x2180036F, |
|
| 480 | - 0x50D99C08, 0xCB3F4861, 0xC26BD765, 0x64A3F6AB, |
|
| 481 | - 0x80342676, 0x25A75E7B, 0xE4E6D1FC, 0x20C710E6, |
|
| 482 | - 0xCDF0B680, 0x17844D3B, 0x31EEF84D, 0x7E0824E4, |
|
| 483 | - 0x2CCB49EB, 0x846A3BAE, 0x8FF77888, 0xEE5D60F6, |
|
| 484 | - 0x7AF75673, 0x2FDD5CDB, 0xA11631C1, 0x30F66F43, |
|
| 485 | - 0xB3FAEC54, 0x157FD7FA, 0xEF8579CC, 0xD152DE58, |
|
| 486 | - 0xDB2FFD5E, 0x8F32CE19, 0x306AF97A, 0x02F03EF8, |
|
| 487 | - 0x99319AD5, 0xC242FA0F, 0xA7E3EBB0, 0xC68E4906, |
|
| 488 | - 0xB8DA230C, 0x80823028, 0xDCDEF3C8, 0xD35FB171, |
|
| 489 | - 0x088A1BC8, 0xBEC0C560, 0x61A3C9E8, 0xBCA8F54D, |
|
| 490 | - 0xC72FEFFA, 0x22822E99, 0x82C570B4, 0xD8D94E89, |
|
| 491 | - 0x8B1C34BC, 0x301E16E6, 0x273BE979, 0xB0FFEAA6, |
|
| 492 | - 0x61D9B8C6, 0x00B24869, 0xB7FFCE3F, 0x08DC283B, |
|
| 493 | - 0x43DAF65A, 0xF7E19798, 0x7619B72F, 0x8F1C9BA4, |
|
| 494 | - 0xDC8637A0, 0x16A7D3B1, 0x9FC393B7, 0xA7136EEB, |
|
| 495 | - 0xC6BCC63E, 0x1A513742, 0xEF6828BC, 0x520365D6, |
|
| 496 | - 0x2D6A77AB, 0x3527ED4B, 0x821FD216, 0x095C6E2E, |
|
| 497 | - 0xDB92F2FB, 0x5EEA29CB, 0x145892F5, 0x91584F7F, |
|
| 498 | - 0x5483697B, 0x2667A8CC, 0x85196048, 0x8C4BACEA, |
|
| 499 | - 0x833860D4, 0x0D23E0F9, 0x6C387E8A, 0x0AE6D249, |
|
| 500 | - 0xB284600C, 0xD835731D, 0xDCB1C647, 0xAC4C56EA, |
|
| 501 | - 0x3EBD81B3, 0x230EABB0, 0x6438BC87, 0xF0B5B1FA, |
|
| 502 | - 0x8F5EA2B3, 0xFC184642, 0x0A036B7A, 0x4FB089BD, |
|
| 503 | - 0x649DA589, 0xA345415E, 0x5C038323, 0x3E5D3BB9, |
|
| 504 | - 0x43D79572, 0x7E6DD07C, 0x06DFDF1E, 0x6C6CC4EF, |
|
| 505 | - 0x7160A539, 0x73BFBE70, 0x83877605, 0x4523ECF1 |
|
| 506 | - ); |
|
| 507 | - |
|
| 508 | - // 256 unsigned 32 bit integers |
|
| 509 | - self::$_s3 = array( |
|
| 510 | - 0x8DEFC240, 0x25FA5D9F, 0xEB903DBF, 0xE810C907, |
|
| 511 | - 0x47607FFF, 0x369FE44B, 0x8C1FC644, 0xAECECA90, |
|
| 512 | - 0xBEB1F9BF, 0xEEFBCAEA, 0xE8CF1950, 0x51DF07AE, |
|
| 513 | - 0x920E8806, 0xF0AD0548, 0xE13C8D83, 0x927010D5, |
|
| 514 | - 0x11107D9F, 0x07647DB9, 0xB2E3E4D4, 0x3D4F285E, |
|
| 515 | - 0xB9AFA820, 0xFADE82E0, 0xA067268B, 0x8272792E, |
|
| 516 | - 0x553FB2C0, 0x489AE22B, 0xD4EF9794, 0x125E3FBC, |
|
| 517 | - 0x21FFFCEE, 0x825B1BFD, 0x9255C5ED, 0x1257A240, |
|
| 518 | - 0x4E1A8302, 0xBAE07FFF, 0x528246E7, 0x8E57140E, |
|
| 519 | - 0x3373F7BF, 0x8C9F8188, 0xA6FC4EE8, 0xC982B5A5, |
|
| 520 | - 0xA8C01DB7, 0x579FC264, 0x67094F31, 0xF2BD3F5F, |
|
| 521 | - 0x40FFF7C1, 0x1FB78DFC, 0x8E6BD2C1, 0x437BE59B, |
|
| 522 | - 0x99B03DBF, 0xB5DBC64B, 0x638DC0E6, 0x55819D99, |
|
| 523 | - 0xA197C81C, 0x4A012D6E, 0xC5884A28, 0xCCC36F71, |
|
| 524 | - 0xB843C213, 0x6C0743F1, 0x8309893C, 0x0FEDDD5F, |
|
| 525 | - 0x2F7FE850, 0xD7C07F7E, 0x02507FBF, 0x5AFB9A04, |
|
| 526 | - 0xA747D2D0, 0x1651192E, 0xAF70BF3E, 0x58C31380, |
|
| 527 | - 0x5F98302E, 0x727CC3C4, 0x0A0FB402, 0x0F7FEF82, |
|
| 528 | - 0x8C96FDAD, 0x5D2C2AAE, 0x8EE99A49, 0x50DA88B8, |
|
| 529 | - 0x8427F4A0, 0x1EAC5790, 0x796FB449, 0x8252DC15, |
|
| 530 | - 0xEFBD7D9B, 0xA672597D, 0xADA840D8, 0x45F54504, |
|
| 531 | - 0xFA5D7403, 0xE83EC305, 0x4F91751A, 0x925669C2, |
|
| 532 | - 0x23EFE941, 0xA903F12E, 0x60270DF2, 0x0276E4B6, |
|
| 533 | - 0x94FD6574, 0x927985B2, 0x8276DBCB, 0x02778176, |
|
| 534 | - 0xF8AF918D, 0x4E48F79E, 0x8F616DDF, 0xE29D840E, |
|
| 535 | - 0x842F7D83, 0x340CE5C8, 0x96BBB682, 0x93B4B148, |
|
| 536 | - 0xEF303CAB, 0x984FAF28, 0x779FAF9B, 0x92DC560D, |
|
| 537 | - 0x224D1E20, 0x8437AA88, 0x7D29DC96, 0x2756D3DC, |
|
| 538 | - 0x8B907CEE, 0xB51FD240, 0xE7C07CE3, 0xE566B4A1, |
|
| 539 | - 0xC3E9615E, 0x3CF8209D, 0x6094D1E3, 0xCD9CA341, |
|
| 540 | - 0x5C76460E, 0x00EA983B, 0xD4D67881, 0xFD47572C, |
|
| 541 | - 0xF76CEDD9, 0xBDA8229C, 0x127DADAA, 0x438A074E, |
|
| 542 | - 0x1F97C090, 0x081BDB8A, 0x93A07EBE, 0xB938CA15, |
|
| 543 | - 0x97B03CFF, 0x3DC2C0F8, 0x8D1AB2EC, 0x64380E51, |
|
| 544 | - 0x68CC7BFB, 0xD90F2788, 0x12490181, 0x5DE5FFD4, |
|
| 545 | - 0xDD7EF86A, 0x76A2E214, 0xB9A40368, 0x925D958F, |
|
| 546 | - 0x4B39FFFA, 0xBA39AEE9, 0xA4FFD30B, 0xFAF7933B, |
|
| 547 | - 0x6D498623, 0x193CBCFA, 0x27627545, 0x825CF47A, |
|
| 548 | - 0x61BD8BA0, 0xD11E42D1, 0xCEAD04F4, 0x127EA392, |
|
| 549 | - 0x10428DB7, 0x8272A972, 0x9270C4A8, 0x127DE50B, |
|
| 550 | - 0x285BA1C8, 0x3C62F44F, 0x35C0EAA5, 0xE805D231, |
|
| 551 | - 0x428929FB, 0xB4FCDF82, 0x4FB66A53, 0x0E7DC15B, |
|
| 552 | - 0x1F081FAB, 0x108618AE, 0xFCFD086D, 0xF9FF2889, |
|
| 553 | - 0x694BCC11, 0x236A5CAE, 0x12DECA4D, 0x2C3F8CC5, |
|
| 554 | - 0xD2D02DFE, 0xF8EF5896, 0xE4CF52DA, 0x95155B67, |
|
| 555 | - 0x494A488C, 0xB9B6A80C, 0x5C8F82BC, 0x89D36B45, |
|
| 556 | - 0x3A609437, 0xEC00C9A9, 0x44715253, 0x0A874B49, |
|
| 557 | - 0xD773BC40, 0x7C34671C, 0x02717EF6, 0x4FEB5536, |
|
| 558 | - 0xA2D02FFF, 0xD2BF60C4, 0xD43F03C0, 0x50B4EF6D, |
|
| 559 | - 0x07478CD1, 0x006E1888, 0xA2E53F55, 0xB9E6D4BC, |
|
| 560 | - 0xA2048016, 0x97573833, 0xD7207D67, 0xDE0F8F3D, |
|
| 561 | - 0x72F87B33, 0xABCC4F33, 0x7688C55D, 0x7B00A6B0, |
|
| 562 | - 0x947B0001, 0x570075D2, 0xF9BB88F8, 0x8942019E, |
|
| 563 | - 0x4264A5FF, 0x856302E0, 0x72DBD92B, 0xEE971B69, |
|
| 564 | - 0x6EA22FDE, 0x5F08AE2B, 0xAF7A616D, 0xE5C98767, |
|
| 565 | - 0xCF1FEBD2, 0x61EFC8C2, 0xF1AC2571, 0xCC8239C2, |
|
| 566 | - 0x67214CB8, 0xB1E583D1, 0xB7DC3E62, 0x7F10BDCE, |
|
| 567 | - 0xF90A5C38, 0x0FF0443D, 0x606E6DC6, 0x60543A49, |
|
| 568 | - 0x5727C148, 0x2BE98A1D, 0x8AB41738, 0x20E1BE24, |
|
| 569 | - 0xAF96DA0F, 0x68458425, 0x99833BE5, 0x600D457D, |
|
| 570 | - 0x282F9350, 0x8334B362, 0xD91D1120, 0x2B6D8DA0, |
|
| 571 | - 0x642B1E31, 0x9C305A00, 0x52BCE688, 0x1B03588A, |
|
| 572 | - 0xF7BAEFD5, 0x4142ED9C, 0xA4315C11, 0x83323EC5, |
|
| 573 | - 0xDFEF4636, 0xA133C501, 0xE9D3531C, 0xEE353783 |
|
| 574 | - ); |
|
| 575 | - |
|
| 576 | - // 256 unsigned 32 bit integers |
|
| 577 | - self::$_s4 = array( |
|
| 578 | - 0x9DB30420, 0x1FB6E9DE, 0xA7BE7BEF, 0xD273A298, |
|
| 579 | - 0x4A4F7BDB, 0x64AD8C57, 0x85510443, 0xFA020ED1, |
|
| 580 | - 0x7E287AFF, 0xE60FB663, 0x095F35A1, 0x79EBF120, |
|
| 581 | - 0xFD059D43, 0x6497B7B1, 0xF3641F63, 0x241E4ADF, |
|
| 582 | - 0x28147F5F, 0x4FA2B8CD, 0xC9430040, 0x0CC32220, |
|
| 583 | - 0xFDD30B30, 0xC0A5374F, 0x1D2D00D9, 0x24147B15, |
|
| 584 | - 0xEE4D111A, 0x0FCA5167, 0x71FF904C, 0x2D195FFE, |
|
| 585 | - 0x1A05645F, 0x0C13FEFE, 0x081B08CA, 0x05170121, |
|
| 586 | - 0x80530100, 0xE83E5EFE, 0xAC9AF4F8, 0x7FE72701, |
|
| 587 | - 0xD2B8EE5F, 0x06DF4261, 0xBB9E9B8A, 0x7293EA25, |
|
| 588 | - 0xCE84FFDF, 0xF5718801, 0x3DD64B04, 0xA26F263B, |
|
| 589 | - 0x7ED48400, 0x547EEBE6, 0x446D4CA0, 0x6CF3D6F5, |
|
| 590 | - 0x2649ABDF, 0xAEA0C7F5, 0x36338CC1, 0x503F7E93, |
|
| 591 | - 0xD3772061, 0x11B638E1, 0x72500E03, 0xF80EB2BB, |
|
| 592 | - 0xABE0502E, 0xEC8D77DE, 0x57971E81, 0xE14F6746, |
|
| 593 | - 0xC9335400, 0x6920318F, 0x081DBB99, 0xFFC304A5, |
|
| 594 | - 0x4D351805, 0x7F3D5CE3, 0xA6C866C6, 0x5D5BCCA9, |
|
| 595 | - 0xDAEC6FEA, 0x9F926F91, 0x9F46222F, 0x3991467D, |
|
| 596 | - 0xA5BF6D8E, 0x1143C44F, 0x43958302, 0xD0214EEB, |
|
| 597 | - 0x022083B8, 0x3FB6180C, 0x18F8931E, 0x281658E6, |
|
| 598 | - 0x26486E3E, 0x8BD78A70, 0x7477E4C1, 0xB506E07C, |
|
| 599 | - 0xF32D0A25, 0x79098B02, 0xE4EABB81, 0x28123B23, |
|
| 600 | - 0x69DEAD38, 0x1574CA16, 0xDF871B62, 0x211C40B7, |
|
| 601 | - 0xA51A9EF9, 0x0014377B, 0x041E8AC8, 0x09114003, |
|
| 602 | - 0xBD59E4D2, 0xE3D156D5, 0x4FE876D5, 0x2F91A340, |
|
| 603 | - 0x557BE8DE, 0x00EAE4A7, 0x0CE5C2EC, 0x4DB4BBA6, |
|
| 604 | - 0xE756BDFF, 0xDD3369AC, 0xEC17B035, 0x06572327, |
|
| 605 | - 0x99AFC8B0, 0x56C8C391, 0x6B65811C, 0x5E146119, |
|
| 606 | - 0x6E85CB75, 0xBE07C002, 0xC2325577, 0x893FF4EC, |
|
| 607 | - 0x5BBFC92D, 0xD0EC3B25, 0xB7801AB7, 0x8D6D3B24, |
|
| 608 | - 0x20C763EF, 0xC366A5FC, 0x9C382880, 0x0ACE3205, |
|
| 609 | - 0xAAC9548A, 0xECA1D7C7, 0x041AFA32, 0x1D16625A, |
|
| 610 | - 0x6701902C, 0x9B757A54, 0x31D477F7, 0x9126B031, |
|
| 611 | - 0x36CC6FDB, 0xC70B8B46, 0xD9E66A48, 0x56E55A79, |
|
| 612 | - 0x026A4CEB, 0x52437EFF, 0x2F8F76B4, 0x0DF980A5, |
|
| 613 | - 0x8674CDE3, 0xEDDA04EB, 0x17A9BE04, 0x2C18F4DF, |
|
| 614 | - 0xB7747F9D, 0xAB2AF7B4, 0xEFC34D20, 0x2E096B7C, |
|
| 615 | - 0x1741A254, 0xE5B6A035, 0x213D42F6, 0x2C1C7C26, |
|
| 616 | - 0x61C2F50F, 0x6552DAF9, 0xD2C231F8, 0x25130F69, |
|
| 617 | - 0xD8167FA2, 0x0418F2C8, 0x001A96A6, 0x0D1526AB, |
|
| 618 | - 0x63315C21, 0x5E0A72EC, 0x49BAFEFD, 0x187908D9, |
|
| 619 | - 0x8D0DBD86, 0x311170A7, 0x3E9B640C, 0xCC3E10D7, |
|
| 620 | - 0xD5CAD3B6, 0x0CAEC388, 0xF73001E1, 0x6C728AFF, |
|
| 621 | - 0x71EAE2A1, 0x1F9AF36E, 0xCFCBD12F, 0xC1DE8417, |
|
| 622 | - 0xAC07BE6B, 0xCB44A1D8, 0x8B9B0F56, 0x013988C3, |
|
| 623 | - 0xB1C52FCA, 0xB4BE31CD, 0xD8782806, 0x12A3A4E2, |
|
| 624 | - 0x6F7DE532, 0x58FD7EB6, 0xD01EE900, 0x24ADFFC2, |
|
| 625 | - 0xF4990FC5, 0x9711AAC5, 0x001D7B95, 0x82E5E7D2, |
|
| 626 | - 0x109873F6, 0x00613096, 0xC32D9521, 0xADA121FF, |
|
| 627 | - 0x29908415, 0x7FBB977F, 0xAF9EB3DB, 0x29C9ED2A, |
|
| 628 | - 0x5CE2A465, 0xA730F32C, 0xD0AA3FE8, 0x8A5CC091, |
|
| 629 | - 0xD49E2CE7, 0x0CE454A9, 0xD60ACD86, 0x015F1919, |
|
| 630 | - 0x77079103, 0xDEA03AF6, 0x78A8565E, 0xDEE356DF, |
|
| 631 | - 0x21F05CBE, 0x8B75E387, 0xB3C50651, 0xB8A5C3EF, |
|
| 632 | - 0xD8EEB6D2, 0xE523BE77, 0xC2154529, 0x2F69EFDF, |
|
| 633 | - 0xAFE67AFB, 0xF470C4B2, 0xF3E0EB5B, 0xD6CC9876, |
|
| 634 | - 0x39E4460C, 0x1FDA8538, 0x1987832F, 0xCA007367, |
|
| 635 | - 0xA99144F8, 0x296B299E, 0x492FC295, 0x9266BEAB, |
|
| 636 | - 0xB5676E69, 0x9BD3DDDA, 0xDF7E052F, 0xDB25701C, |
|
| 637 | - 0x1B5E51EE, 0xF65324E6, 0x6AFCE36C, 0x0316CC04, |
|
| 638 | - 0x8644213E, 0xB7DC59D0, 0x7965291F, 0xCCD6FD43, |
|
| 639 | - 0x41823979, 0x932BCDF6, 0xB657C34D, 0x4EDFD282, |
|
| 640 | - 0x7AE5290C, 0x3CB9536B, 0x851E20FE, 0x9833557E, |
|
| 641 | - 0x13ECF0B0, 0xD3FFB372, 0x3F85C5C1, 0x0AEF7ED2 |
|
| 642 | - ); |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - |
|
| 646 | - /** |
|
| 647 | - * Indicates this is a block cipher |
|
| 648 | - * |
|
| 649 | - * @return integer Returns Cipher::BLOCK |
|
| 650 | - */ |
|
| 651 | - public function type() |
|
| 652 | - { |
|
| 653 | - return parent::BLOCK; |
|
| 654 | - } |
|
| 41 | + /** @type integer BYTES_BLOCK The size of the block, in bytes */ |
|
| 42 | + const BYTES_BLOCK = 16; // 128 bits; |
|
| 43 | + |
|
| 44 | + //const BYTES_KEY = 0; // between 128, 160, 192, 224, 256 bits |
|
| 45 | + |
|
| 46 | + /** @type integer BYTES_KEY_MAX The max key size, in bytes */ |
|
| 47 | + const BYTES_KEY_MAX = 32; |
|
| 48 | + |
|
| 49 | + /** @type array $_s1 An array of 256 unsigned integers */ |
|
| 50 | + private static $_s1 = array(); |
|
| 51 | + |
|
| 52 | + /** @type array $_s2 An array of 256 unsigned integers */ |
|
| 53 | + private static $_s2 = array(); |
|
| 54 | + |
|
| 55 | + /** @type array $_s3 An array of 256 unsigned integers */ |
|
| 56 | + private static $_s3 = array(); |
|
| 57 | + |
|
| 58 | + /** @type array $_s4 An array of 256 unsigned integers */ |
|
| 59 | + private static $_s4 = array(); |
|
| 60 | + |
|
| 61 | + private static $_req_key_sizes = array(16, 20, 24, 28, 32); |
|
| 62 | + |
|
| 63 | + /** @type string $_mkey The 16 byte masking subkey */ |
|
| 64 | + private $_mkey = array(); |
|
| 65 | + |
|
| 66 | + /** @type string $_rkey The 16 byte rotate subkey */ |
|
| 67 | + private $_rkey = array(); |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Constructor |
|
| 72 | + * |
|
| 73 | + * @param string $key The key used for Encryption/Decryption |
|
| 74 | + * @return void |
|
| 75 | + */ |
|
| 76 | + public function __construct($key) |
|
| 77 | + { |
|
| 78 | + $keylen = strlen($key); |
|
| 79 | + |
|
| 80 | + if($keylen > self::BYTES_KEY_MAX) |
|
| 81 | + { |
|
| 82 | + $key = substr($key, 0, self::BYTES_KEY_MAX); |
|
| 83 | + $keylen = self::BYTES_KEY_MAX; |
|
| 84 | + } |
|
| 85 | + else if(!in_array($keylen, self::$_req_key_sizes)) |
|
| 86 | + { |
|
| 87 | + $msg = PHP_Crypt::CIPHER_CAST_256." requires a key size of 16, "; |
|
| 88 | + $msg .= "20, 24, 28, or 32 bytes."; |
|
| 89 | + trigger_error($msg, E_USER_WARNING); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + // set the key, make sure the required length is set in bytes |
|
| 93 | + parent::__construct(PHP_Crypt::CIPHER_CAST_256, $key, $keylen); |
|
| 94 | + |
|
| 95 | + // set the block size |
|
| 96 | + $this->blockSize(self::BYTES_BLOCK); |
|
| 97 | + |
|
| 98 | + // initialize the sboxes constants |
|
| 99 | + $this->initTables(); |
|
| 100 | + |
|
| 101 | + // create the sub keys using the sboxes |
|
| 102 | + $this->createSubKeys(); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Destructor |
|
| 108 | + * |
|
| 109 | + * @return void |
|
| 110 | + */ |
|
| 111 | + public function __destruct() |
|
| 112 | + { |
|
| 113 | + parent::__destruct(); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Encrypt plain text data |
|
| 119 | + * |
|
| 120 | + * @param string $data A 128 bit block of plain data |
|
| 121 | + * @return boolean Returns true |
|
| 122 | + */ |
|
| 123 | + public function encrypt(&$data) |
|
| 124 | + { |
|
| 125 | + $this->operation(parent::ENCRYPT); |
|
| 126 | + |
|
| 127 | + // first split the data into four 32 bit blocks, reverse |
|
| 128 | + // the string order of each block, convert the blocks of data to integers |
|
| 129 | + $data = str_split($data, 4); |
|
| 130 | + $data = array_map("strrev", $data); |
|
| 131 | + $data = array_map("parent::str2Dec", $data); |
|
| 132 | + |
|
| 133 | + // do the first 6 loops |
|
| 134 | + for($i = 0; $i < 6; ++$i) |
|
| 135 | + { |
|
| 136 | + |
|
| 137 | + $data[2] ^= $this->f1($data[3], $this->_mkey[$i][0], $this->_rkey[$i][0]); |
|
| 138 | + $data[1] ^= $this->f2($data[2], $this->_mkey[$i][1], $this->_rkey[$i][1]); |
|
| 139 | + $data[0] ^= $this->f3($data[1], $this->_mkey[$i][2], $this->_rkey[$i][2]); |
|
| 140 | + $data[3] ^= $this->f1($data[0], $this->_mkey[$i][3], $this->_rkey[$i][3]); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + // the second 6 loops are done in a different order |
|
| 144 | + for($i = 6; $i < 12; ++$i) |
|
| 145 | + { |
|
| 146 | + |
|
| 147 | + $data[3] ^= $this->f1($data[0], $this->_mkey[$i][3], $this->_rkey[$i][3]); |
|
| 148 | + $data[0] ^= $this->f3($data[1], $this->_mkey[$i][2], $this->_rkey[$i][2]); |
|
| 149 | + $data[1] ^= $this->f2($data[2], $this->_mkey[$i][1], $this->_rkey[$i][1]); |
|
| 150 | + $data[2] ^= $this->f1($data[3], $this->_mkey[$i][0], $this->_rkey[$i][0]); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + // convert the decimals back to a string, reverse the string so it's |
|
| 154 | + // in the correct order |
|
| 155 | + $data = array_map(function($v) { |
|
| 156 | + $v = Core::dec2Str($v, 4); |
|
| 157 | + return strrev($v); |
|
| 158 | + }, $data); |
|
| 159 | + |
|
| 160 | + // glue the string back together |
|
| 161 | + $data = implode("", $data); |
|
| 162 | + |
|
| 163 | + return true; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Decrypt an encrypted string, it does all the steps of encryption, |
|
| 169 | + * but in reverse. |
|
| 170 | + * |
|
| 171 | + * @param string $data A 128 bit block of encrypted data |
|
| 172 | + * @return boolean Returns true |
|
| 173 | + */ |
|
| 174 | + public function decrypt(&$data) |
|
| 175 | + { |
|
| 176 | + $this->operation(parent::DECRYPT); |
|
| 177 | + |
|
| 178 | + // first split the data into four 32 bit blocks, reverse |
|
| 179 | + // the string order of each block, convert the blocks of data to integers |
|
| 180 | + $data = str_split($data, 4); |
|
| 181 | + $data = array_map("strrev", $data); |
|
| 182 | + $data = array_map("parent::str2Dec", $data); |
|
| 183 | + |
|
| 184 | + // do the first 6 loops |
|
| 185 | + for($i = 11; $i >= 6; --$i) |
|
| 186 | + { |
|
| 187 | + $data[2] ^= $this->f1($data[3], $this->_mkey[$i][0], $this->_rkey[$i][0]); |
|
| 188 | + $data[1] ^= $this->f2($data[2], $this->_mkey[$i][1], $this->_rkey[$i][1]); |
|
| 189 | + $data[0] ^= $this->f3($data[1], $this->_mkey[$i][2], $this->_rkey[$i][2]); |
|
| 190 | + $data[3] ^= $this->f1($data[0], $this->_mkey[$i][3], $this->_rkey[$i][3]); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + // the second 6 loops are done in a different order |
|
| 194 | + for($i = 5; $i >= 0; --$i) |
|
| 195 | + { |
|
| 196 | + $data[3] ^= $this->f1($data[0], $this->_mkey[$i][3], $this->_rkey[$i][3]); |
|
| 197 | + $data[0] ^= $this->f3($data[1], $this->_mkey[$i][2], $this->_rkey[$i][2]); |
|
| 198 | + $data[1] ^= $this->f2($data[2], $this->_mkey[$i][1], $this->_rkey[$i][1]); |
|
| 199 | + $data[2] ^= $this->f1($data[3], $this->_mkey[$i][0], $this->_rkey[$i][0]); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + // convert the decimals back to a string, reverse the string so it's |
|
| 203 | + // in the correct order |
|
| 204 | + $data = array_map(function($v) { |
|
| 205 | + $v = Core::dec2Str($v, 4); |
|
| 206 | + return strrev($v); |
|
| 207 | + }, $data); |
|
| 208 | + |
|
| 209 | + // glue the string back together |
|
| 210 | + $data = implode("", $data); |
|
| 211 | + |
|
| 212 | + return true; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * CAST-256 F1 function |
|
| 218 | + * |
|
| 219 | + * @param $d integer The the data input |
|
| 220 | + * @param $m integer The 32 bit masking key |
|
| 221 | + * @param $r integer The round number |
|
| 222 | + * @return integer The value after the F1 calculation |
|
| 223 | + */ |
|
| 224 | + private function f1($d, $m, $r) |
|
| 225 | + { |
|
| 226 | + $n = parent::uInt32($m + $d); |
|
| 227 | + $n = parent::uInt32(parent::rotBitsLeft32($n, $r)); |
|
| 228 | + $n = parent::dec2Str($n, 4); |
|
| 229 | + |
|
| 230 | + return parent::uInt32( |
|
| 231 | + ((self::$_s1[ord($n[0])] ^ self::$_s2[ord($n[1])]) - |
|
| 232 | + self::$_s3[ord($n[2])]) + self::$_s4[ord($n[3])] |
|
| 233 | + ); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * CAST-256 F2 function |
|
| 239 | + * |
|
| 240 | + * @param $d integer The the data input |
|
| 241 | + * @param $m integer The 32 bit masking key |
|
| 242 | + * @param $r integer The round number |
|
| 243 | + * @return integer The value after the F2 calculation |
|
| 244 | + */ |
|
| 245 | + private function f2($d, $m, $r) |
|
| 246 | + { |
|
| 247 | + $n = parent::uInt32($m ^ $d); |
|
| 248 | + $n = parent::uInt32(parent::rotBitsLeft32($n, $r)); |
|
| 249 | + $n = parent::dec2Str($n, 4); |
|
| 250 | + |
|
| 251 | + return parent::uInt32( |
|
| 252 | + ((self::$_s1[ord($n[0])] - self::$_s2[ord($n[1])]) + |
|
| 253 | + self::$_s3[ord($n[2])]) ^ self::$_s4[ord($n[3])] |
|
| 254 | + ); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * CAST-256 F3 function |
|
| 260 | + * |
|
| 261 | + * @param $d integer The the data input |
|
| 262 | + * @param $m integer The 32 bit masking key |
|
| 263 | + * @param $r integer The round number |
|
| 264 | + * @return integer The value after the F3 calculation |
|
| 265 | + */ |
|
| 266 | + private function f3($d, $m, $r) |
|
| 267 | + { |
|
| 268 | + $n = parent::uInt32($m - $d); |
|
| 269 | + $n = parent::uInt32(parent::rotBitsLeft32($n, $r)); |
|
| 270 | + $n = parent::dec2Str($n, 4); |
|
| 271 | + |
|
| 272 | + return parent::uInt32( |
|
| 273 | + ((self::$_s1[ord($n[0])] + self::$_s2[ord($n[1])]) ^ |
|
| 274 | + self::$_s3[ord($n[2])]) - self::$_s4[ord($n[3])] |
|
| 275 | + ); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * Creates the subkeys $_mkey (the masking key) and |
|
| 281 | + * $_rkey (the rotate key) which are 16 bytes each. These are |
|
| 282 | + * created from the original key. The original key is null |
|
| 283 | + * padded up to 16 bytes and expanded to 32 bytes. It is then |
|
| 284 | + * split in half to create $_mkey and $_rkey |
|
| 285 | + * |
|
| 286 | + * @return void |
|
| 287 | + */ |
|
| 288 | + private function createSubKeys() |
|
| 289 | + { |
|
| 290 | + $cm = 0x5A827999; |
|
| 291 | + $mm = 0x6ED9EBA1; |
|
| 292 | + $cr = 19; |
|
| 293 | + $mr = 17; |
|
| 294 | + $tm = array(); |
|
| 295 | + $tr = array(); |
|
| 296 | + $xkey = $this->key(); |
|
| 297 | + $tmpkey = array(); |
|
| 298 | + |
|
| 299 | + // if the key is less than 32 bytes, pad it to 32 bytes |
|
| 300 | + // for the key expansion |
|
| 301 | + if($this->keySize() < 32) |
|
| 302 | + $xkey = str_pad($xkey, 32, "\0", STR_PAD_RIGHT); |
|
| 303 | + |
|
| 304 | + // split the key up into 4 byte parts, reverse the string, |
|
| 305 | + // then convert each part into a 32 bit integer |
|
| 306 | + $xkey = str_split($xkey, 4); |
|
| 307 | + $xkey = array_map("strrev", $xkey); |
|
| 308 | + $xkey = array_map("parent::str2Dec", $xkey); |
|
| 309 | + |
|
| 310 | + // set up the values need for creating round and masking keys |
|
| 311 | + for($i = 0; $i < 24; ++$i) |
|
| 312 | + { |
|
| 313 | + $tm[$i] = array(); |
|
| 314 | + $tr[$i] = array(); |
|
| 315 | + |
|
| 316 | + for($j = 0; $j < 8; ++$j) |
|
| 317 | + { |
|
| 318 | + $tm[$i][$j] = $cm; |
|
| 319 | + $cm = parent::uInt32($cm + $mm); |
|
| 320 | + $tr[$i][$j] = $cr; |
|
| 321 | + $cr = parent::uInt32($cr + $mr); |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + // now create the round and masking keys |
|
| 326 | + for($i = 0; $i < 12; ++$i) |
|
| 327 | + { |
|
| 328 | + $j = 2 * $i; |
|
| 329 | + |
|
| 330 | + $xkey[6] = parent::uInt32($xkey[6] ^ $this->f1($xkey[7], $tm[$j][0], $tr[$j][0])); |
|
| 331 | + $xkey[5] = parent::uInt32($xkey[5] ^ $this->f2($xkey[6], $tm[$j][1], $tr[$j][1])); |
|
| 332 | + $xkey[4] = parent::uInt32($xkey[4] ^ $this->f3($xkey[5], $tm[$j][2], $tr[$j][2])); |
|
| 333 | + $xkey[3] = parent::uInt32($xkey[3] ^ $this->f1($xkey[4], $tm[$j][3], $tr[$j][3])); |
|
| 334 | + $xkey[2] = parent::uInt32($xkey[2] ^ $this->f2($xkey[3], $tm[$j][4], $tr[$j][4])); |
|
| 335 | + $xkey[1] = parent::uInt32($xkey[1] ^ $this->f3($xkey[2], $tm[$j][5], $tr[$j][5])); |
|
| 336 | + $xkey[0] = parent::uInt32($xkey[0] ^ $this->f1($xkey[1], $tm[$j][6], $tr[$j][6])); |
|
| 337 | + $xkey[7] = parent::uInt32($xkey[7] ^ $this->f2($xkey[0], $tm[$j][7], $tr[$j][7])); |
|
| 338 | + |
|
| 339 | + $j = (2 * $i) + 1; |
|
| 340 | + $xkey[6] = parent::uInt32($xkey[6] ^ $this->f1($xkey[7], $tm[$j][0], $tr[$j][0])); |
|
| 341 | + $xkey[5] = parent::uInt32($xkey[5] ^ $this->f2($xkey[6], $tm[$j][1], $tr[$j][1])); |
|
| 342 | + $xkey[4] = parent::uInt32($xkey[4] ^ $this->f3($xkey[5], $tm[$j][2], $tr[$j][2])); |
|
| 343 | + $xkey[3] = parent::uInt32($xkey[3] ^ $this->f1($xkey[4], $tm[$j][3], $tr[$j][3])); |
|
| 344 | + $xkey[2] = parent::uInt32($xkey[2] ^ $this->f2($xkey[3], $tm[$j][4], $tr[$j][4])); |
|
| 345 | + $xkey[1] = parent::uInt32($xkey[1] ^ $this->f3($xkey[2], $tm[$j][5], $tr[$j][5])); |
|
| 346 | + $xkey[0] = parent::uInt32($xkey[0] ^ $this->f1($xkey[1], $tm[$j][6], $tr[$j][6])); |
|
| 347 | + $xkey[7] = parent::uInt32($xkey[7] ^ $this->f2($xkey[0], $tm[$j][7], $tr[$j][7])); |
|
| 348 | + |
|
| 349 | + // take the least 5 significant bits of each $xkey byte below and assign it |
|
| 350 | + // to the round key |
|
| 351 | + $this->_rkey[$i][0] = $xkey[0] & 31; |
|
| 352 | + $this->_rkey[$i][1] = $xkey[2] & 31; |
|
| 353 | + $this->_rkey[$i][2] = $xkey[4] & 31; |
|
| 354 | + $this->_rkey[$i][3] = $xkey[6] & 31; |
|
| 355 | + |
|
| 356 | + // now create 32 byte masking keys |
|
| 357 | + $this->_mkey[$i][0] = $xkey[7]; |
|
| 358 | + $this->_mkey[$i][1] = $xkey[5]; |
|
| 359 | + $this->_mkey[$i][2] = $xkey[3]; |
|
| 360 | + $this->_mkey[$i][3] = $xkey[1]; |
|
| 361 | + } |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * Initialize the tables |
|
| 367 | + * |
|
| 368 | + * @return void |
|
| 369 | + */ |
|
| 370 | + private function initTables() |
|
| 371 | + { |
|
| 372 | + // 256 unsigned 32 bit integers |
|
| 373 | + self::$_s1 = array( |
|
| 374 | + 0x30FB40D4, 0x9FA0FF0B, 0x6BECCD2F, 0x3F258C7A, |
|
| 375 | + 0x1E213F2F, 0x9C004DD3, 0x6003E540, 0xCF9FC949, |
|
| 376 | + 0xBFD4AF27, 0x88BBBDB5, 0xE2034090, 0x98D09675, |
|
| 377 | + 0x6E63A0E0, 0x15C361D2, 0xC2E7661D, 0x22D4FF8E, |
|
| 378 | + 0x28683B6F, 0xC07FD059, 0xFF2379C8, 0x775F50E2, |
|
| 379 | + 0x43C340D3, 0xDF2F8656, 0x887CA41A, 0xA2D2BD2D, |
|
| 380 | + 0xA1C9E0D6, 0x346C4819, 0x61B76D87, 0x22540F2F, |
|
| 381 | + 0x2ABE32E1, 0xAA54166B, 0x22568E3A, 0xA2D341D0, |
|
| 382 | + 0x66DB40C8, 0xA784392F, 0x004DFF2F, 0x2DB9D2DE, |
|
| 383 | + 0x97943FAC, 0x4A97C1D8, 0x527644B7, 0xB5F437A7, |
|
| 384 | + 0xB82CBAEF, 0xD751D159, 0x6FF7F0ED, 0x5A097A1F, |
|
| 385 | + 0x827B68D0, 0x90ECF52E, 0x22B0C054, 0xBC8E5935, |
|
| 386 | + 0x4B6D2F7F, 0x50BB64A2, 0xD2664910, 0xBEE5812D, |
|
| 387 | + 0xB7332290, 0xE93B159F, 0xB48EE411, 0x4BFF345D, |
|
| 388 | + 0xFD45C240, 0xAD31973F, 0xC4F6D02E, 0x55FC8165, |
|
| 389 | + 0xD5B1CAAD, 0xA1AC2DAE, 0xA2D4B76D, 0xC19B0C50, |
|
| 390 | + 0x882240F2, 0x0C6E4F38, 0xA4E4BFD7, 0x4F5BA272, |
|
| 391 | + 0x564C1D2F, 0xC59C5319, 0xB949E354, 0xB04669FE, |
|
| 392 | + 0xB1B6AB8A, 0xC71358DD, 0x6385C545, 0x110F935D, |
|
| 393 | + 0x57538AD5, 0x6A390493, 0xE63D37E0, 0x2A54F6B3, |
|
| 394 | + 0x3A787D5F, 0x6276A0B5, 0x19A6FCDF, 0x7A42206A, |
|
| 395 | + 0x29F9D4D5, 0xF61B1891, 0xBB72275E, 0xAA508167, |
|
| 396 | + 0x38901091, 0xC6B505EB, 0x84C7CB8C, 0x2AD75A0F, |
|
| 397 | + 0x874A1427, 0xA2D1936B, 0x2AD286AF, 0xAA56D291, |
|
| 398 | + 0xD7894360, 0x425C750D, 0x93B39E26, 0x187184C9, |
|
| 399 | + 0x6C00B32D, 0x73E2BB14, 0xA0BEBC3C, 0x54623779, |
|
| 400 | + 0x64459EAB, 0x3F328B82, 0x7718CF82, 0x59A2CEA6, |
|
| 401 | + 0x04EE002E, 0x89FE78E6, 0x3FAB0950, 0x325FF6C2, |
|
| 402 | + 0x81383F05, 0x6963C5C8, 0x76CB5AD6, 0xD49974C9, |
|
| 403 | + 0xCA180DCF, 0x380782D5, 0xC7FA5CF6, 0x8AC31511, |
|
| 404 | + 0x35E79E13, 0x47DA91D0, 0xF40F9086, 0xA7E2419E, |
|
| 405 | + 0x31366241, 0x051EF495, 0xAA573B04, 0x4A805D8D, |
|
| 406 | + 0x548300D0, 0x00322A3C, 0xBF64CDDF, 0xBA57A68E, |
|
| 407 | + 0x75C6372B, 0x50AFD341, 0xA7C13275, 0x915A0BF5, |
|
| 408 | + 0x6B54BFAB, 0x2B0B1426, 0xAB4CC9D7, 0x449CCD82, |
|
| 409 | + 0xF7FBF265, 0xAB85C5F3, 0x1B55DB94, 0xAAD4E324, |
|
| 410 | + 0xCFA4BD3F, 0x2DEAA3E2, 0x9E204D02, 0xC8BD25AC, |
|
| 411 | + 0xEADF55B3, 0xD5BD9E98, 0xE31231B2, 0x2AD5AD6C, |
|
| 412 | + 0x954329DE, 0xADBE4528, 0xD8710F69, 0xAA51C90F, |
|
| 413 | + 0xAA786BF6, 0x22513F1E, 0xAA51A79B, 0x2AD344CC, |
|
| 414 | + 0x7B5A41F0, 0xD37CFBAD, 0x1B069505, 0x41ECE491, |
|
| 415 | + 0xB4C332E6, 0x032268D4, 0xC9600ACC, 0xCE387E6D, |
|
| 416 | + 0xBF6BB16C, 0x6A70FB78, 0x0D03D9C9, 0xD4DF39DE, |
|
| 417 | + 0xE01063DA, 0x4736F464, 0x5AD328D8, 0xB347CC96, |
|
| 418 | + 0x75BB0FC3, 0x98511BFB, 0x4FFBCC35, 0xB58BCF6A, |
|
| 419 | + 0xE11F0ABC, 0xBFC5FE4A, 0xA70AEC10, 0xAC39570A, |
|
| 420 | + 0x3F04442F, 0x6188B153, 0xE0397A2E, 0x5727CB79, |
|
| 421 | + 0x9CEB418F, 0x1CACD68D, 0x2AD37C96, 0x0175CB9D, |
|
| 422 | + 0xC69DFF09, 0xC75B65F0, 0xD9DB40D8, 0xEC0E7779, |
|
| 423 | + 0x4744EAD4, 0xB11C3274, 0xDD24CB9E, 0x7E1C54BD, |
|
| 424 | + 0xF01144F9, 0xD2240EB1, 0x9675B3FD, 0xA3AC3755, |
|
| 425 | + 0xD47C27AF, 0x51C85F4D, 0x56907596, 0xA5BB15E6, |
|
| 426 | + 0x580304F0, 0xCA042CF1, 0x011A37EA, 0x8DBFAADB, |
|
| 427 | + 0x35BA3E4A, 0x3526FFA0, 0xC37B4D09, 0xBC306ED9, |
|
| 428 | + 0x98A52666, 0x5648F725, 0xFF5E569D, 0x0CED63D0, |
|
| 429 | + 0x7C63B2CF, 0x700B45E1, 0xD5EA50F1, 0x85A92872, |
|
| 430 | + 0xAF1FBDA7, 0xD4234870, 0xA7870BF3, 0x2D3B4D79, |
|
| 431 | + 0x42E04198, 0x0CD0EDE7, 0x26470DB8, 0xF881814C, |
|
| 432 | + 0x474D6AD7, 0x7C0C5E5C, 0xD1231959, 0x381B7298, |
|
| 433 | + 0xF5D2F4DB, 0xAB838653, 0x6E2F1E23, 0x83719C9E, |
|
| 434 | + 0xBD91E046, 0x9A56456E, 0xDC39200C, 0x20C8C571, |
|
| 435 | + 0x962BDA1C, 0xE1E696FF, 0xB141AB08, 0x7CCA89B9, |
|
| 436 | + 0x1A69E783, 0x02CC4843, 0xA2F7C579, 0x429EF47D, |
|
| 437 | + 0x427B169C, 0x5AC9F049, 0xDD8F0F00, 0x5C8165BF |
|
| 438 | + ); |
|
| 439 | + |
|
| 440 | + // 256 unsigned 32 bit integers |
|
| 441 | + self::$_s2 = array( |
|
| 442 | + 0x1F201094, 0xEF0BA75B, 0x69E3CF7E, 0x393F4380, |
|
| 443 | + 0xFE61CF7A, 0xEEC5207A, 0x55889C94, 0x72FC0651, |
|
| 444 | + 0xADA7EF79, 0x4E1D7235, 0xD55A63CE, 0xDE0436BA, |
|
| 445 | + 0x99C430EF, 0x5F0C0794, 0x18DCDB7D, 0xA1D6EFF3, |
|
| 446 | + 0xA0B52F7B, 0x59E83605, 0xEE15B094, 0xE9FFD909, |
|
| 447 | + 0xDC440086, 0xEF944459, 0xBA83CCB3, 0xE0C3CDFB, |
|
| 448 | + 0xD1DA4181, 0x3B092AB1, 0xF997F1C1, 0xA5E6CF7B, |
|
| 449 | + 0x01420DDB, 0xE4E7EF5B, 0x25A1FF41, 0xE180F806, |
|
| 450 | + 0x1FC41080, 0x179BEE7A, 0xD37AC6A9, 0xFE5830A4, |
|
| 451 | + 0x98DE8B7F, 0x77E83F4E, 0x79929269, 0x24FA9F7B, |
|
| 452 | + 0xE113C85B, 0xACC40083, 0xD7503525, 0xF7EA615F, |
|
| 453 | + 0x62143154, 0x0D554B63, 0x5D681121, 0xC866C359, |
|
| 454 | + 0x3D63CF73, 0xCEE234C0, 0xD4D87E87, 0x5C672B21, |
|
| 455 | + 0x071F6181, 0x39F7627F, 0x361E3084, 0xE4EB573B, |
|
| 456 | + 0x602F64A4, 0xD63ACD9C, 0x1BBC4635, 0x9E81032D, |
|
| 457 | + 0x2701F50C, 0x99847AB4, 0xA0E3DF79, 0xBA6CF38C, |
|
| 458 | + 0x10843094, 0x2537A95E, 0xF46F6FFE, 0xA1FF3B1F, |
|
| 459 | + 0x208CFB6A, 0x8F458C74, 0xD9E0A227, 0x4EC73A34, |
|
| 460 | + 0xFC884F69, 0x3E4DE8DF, 0xEF0E0088, 0x3559648D, |
|
| 461 | + 0x8A45388C, 0x1D804366, 0x721D9BFD, 0xA58684BB, |
|
| 462 | + 0xE8256333, 0x844E8212, 0x128D8098, 0xFED33FB4, |
|
| 463 | + 0xCE280AE1, 0x27E19BA5, 0xD5A6C252, 0xE49754BD, |
|
| 464 | + 0xC5D655DD, 0xEB667064, 0x77840B4D, 0xA1B6A801, |
|
| 465 | + 0x84DB26A9, 0xE0B56714, 0x21F043B7, 0xE5D05860, |
|
| 466 | + 0x54F03084, 0x066FF472, 0xA31AA153, 0xDADC4755, |
|
| 467 | + 0xB5625DBF, 0x68561BE6, 0x83CA6B94, 0x2D6ED23B, |
|
| 468 | + 0xECCF01DB, 0xA6D3D0BA, 0xB6803D5C, 0xAF77A709, |
|
| 469 | + 0x33B4A34C, 0x397BC8D6, 0x5EE22B95, 0x5F0E5304, |
|
| 470 | + 0x81ED6F61, 0x20E74364, 0xB45E1378, 0xDE18639B, |
|
| 471 | + 0x881CA122, 0xB96726D1, 0x8049A7E8, 0x22B7DA7B, |
|
| 472 | + 0x5E552D25, 0x5272D237, 0x79D2951C, 0xC60D894C, |
|
| 473 | + 0x488CB402, 0x1BA4FE5B, 0xA4B09F6B, 0x1CA815CF, |
|
| 474 | + 0xA20C3005, 0x8871DF63, 0xB9DE2FCB, 0x0CC6C9E9, |
|
| 475 | + 0x0BEEFF53, 0xE3214517, 0xB4542835, 0x9F63293C, |
|
| 476 | + 0xEE41E729, 0x6E1D2D7C, 0x50045286, 0x1E6685F3, |
|
| 477 | + 0xF33401C6, 0x30A22C95, 0x31A70850, 0x60930F13, |
|
| 478 | + 0x73F98417, 0xA1269859, 0xEC645C44, 0x52C877A9, |
|
| 479 | + 0xCDFF33A6, 0xA02B1741, 0x7CBAD9A2, 0x2180036F, |
|
| 480 | + 0x50D99C08, 0xCB3F4861, 0xC26BD765, 0x64A3F6AB, |
|
| 481 | + 0x80342676, 0x25A75E7B, 0xE4E6D1FC, 0x20C710E6, |
|
| 482 | + 0xCDF0B680, 0x17844D3B, 0x31EEF84D, 0x7E0824E4, |
|
| 483 | + 0x2CCB49EB, 0x846A3BAE, 0x8FF77888, 0xEE5D60F6, |
|
| 484 | + 0x7AF75673, 0x2FDD5CDB, 0xA11631C1, 0x30F66F43, |
|
| 485 | + 0xB3FAEC54, 0x157FD7FA, 0xEF8579CC, 0xD152DE58, |
|
| 486 | + 0xDB2FFD5E, 0x8F32CE19, 0x306AF97A, 0x02F03EF8, |
|
| 487 | + 0x99319AD5, 0xC242FA0F, 0xA7E3EBB0, 0xC68E4906, |
|
| 488 | + 0xB8DA230C, 0x80823028, 0xDCDEF3C8, 0xD35FB171, |
|
| 489 | + 0x088A1BC8, 0xBEC0C560, 0x61A3C9E8, 0xBCA8F54D, |
|
| 490 | + 0xC72FEFFA, 0x22822E99, 0x82C570B4, 0xD8D94E89, |
|
| 491 | + 0x8B1C34BC, 0x301E16E6, 0x273BE979, 0xB0FFEAA6, |
|
| 492 | + 0x61D9B8C6, 0x00B24869, 0xB7FFCE3F, 0x08DC283B, |
|
| 493 | + 0x43DAF65A, 0xF7E19798, 0x7619B72F, 0x8F1C9BA4, |
|
| 494 | + 0xDC8637A0, 0x16A7D3B1, 0x9FC393B7, 0xA7136EEB, |
|
| 495 | + 0xC6BCC63E, 0x1A513742, 0xEF6828BC, 0x520365D6, |
|
| 496 | + 0x2D6A77AB, 0x3527ED4B, 0x821FD216, 0x095C6E2E, |
|
| 497 | + 0xDB92F2FB, 0x5EEA29CB, 0x145892F5, 0x91584F7F, |
|
| 498 | + 0x5483697B, 0x2667A8CC, 0x85196048, 0x8C4BACEA, |
|
| 499 | + 0x833860D4, 0x0D23E0F9, 0x6C387E8A, 0x0AE6D249, |
|
| 500 | + 0xB284600C, 0xD835731D, 0xDCB1C647, 0xAC4C56EA, |
|
| 501 | + 0x3EBD81B3, 0x230EABB0, 0x6438BC87, 0xF0B5B1FA, |
|
| 502 | + 0x8F5EA2B3, 0xFC184642, 0x0A036B7A, 0x4FB089BD, |
|
| 503 | + 0x649DA589, 0xA345415E, 0x5C038323, 0x3E5D3BB9, |
|
| 504 | + 0x43D79572, 0x7E6DD07C, 0x06DFDF1E, 0x6C6CC4EF, |
|
| 505 | + 0x7160A539, 0x73BFBE70, 0x83877605, 0x4523ECF1 |
|
| 506 | + ); |
|
| 507 | + |
|
| 508 | + // 256 unsigned 32 bit integers |
|
| 509 | + self::$_s3 = array( |
|
| 510 | + 0x8DEFC240, 0x25FA5D9F, 0xEB903DBF, 0xE810C907, |
|
| 511 | + 0x47607FFF, 0x369FE44B, 0x8C1FC644, 0xAECECA90, |
|
| 512 | + 0xBEB1F9BF, 0xEEFBCAEA, 0xE8CF1950, 0x51DF07AE, |
|
| 513 | + 0x920E8806, 0xF0AD0548, 0xE13C8D83, 0x927010D5, |
|
| 514 | + 0x11107D9F, 0x07647DB9, 0xB2E3E4D4, 0x3D4F285E, |
|
| 515 | + 0xB9AFA820, 0xFADE82E0, 0xA067268B, 0x8272792E, |
|
| 516 | + 0x553FB2C0, 0x489AE22B, 0xD4EF9794, 0x125E3FBC, |
|
| 517 | + 0x21FFFCEE, 0x825B1BFD, 0x9255C5ED, 0x1257A240, |
|
| 518 | + 0x4E1A8302, 0xBAE07FFF, 0x528246E7, 0x8E57140E, |
|
| 519 | + 0x3373F7BF, 0x8C9F8188, 0xA6FC4EE8, 0xC982B5A5, |
|
| 520 | + 0xA8C01DB7, 0x579FC264, 0x67094F31, 0xF2BD3F5F, |
|
| 521 | + 0x40FFF7C1, 0x1FB78DFC, 0x8E6BD2C1, 0x437BE59B, |
|
| 522 | + 0x99B03DBF, 0xB5DBC64B, 0x638DC0E6, 0x55819D99, |
|
| 523 | + 0xA197C81C, 0x4A012D6E, 0xC5884A28, 0xCCC36F71, |
|
| 524 | + 0xB843C213, 0x6C0743F1, 0x8309893C, 0x0FEDDD5F, |
|
| 525 | + 0x2F7FE850, 0xD7C07F7E, 0x02507FBF, 0x5AFB9A04, |
|
| 526 | + 0xA747D2D0, 0x1651192E, 0xAF70BF3E, 0x58C31380, |
|
| 527 | + 0x5F98302E, 0x727CC3C4, 0x0A0FB402, 0x0F7FEF82, |
|
| 528 | + 0x8C96FDAD, 0x5D2C2AAE, 0x8EE99A49, 0x50DA88B8, |
|
| 529 | + 0x8427F4A0, 0x1EAC5790, 0x796FB449, 0x8252DC15, |
|
| 530 | + 0xEFBD7D9B, 0xA672597D, 0xADA840D8, 0x45F54504, |
|
| 531 | + 0xFA5D7403, 0xE83EC305, 0x4F91751A, 0x925669C2, |
|
| 532 | + 0x23EFE941, 0xA903F12E, 0x60270DF2, 0x0276E4B6, |
|
| 533 | + 0x94FD6574, 0x927985B2, 0x8276DBCB, 0x02778176, |
|
| 534 | + 0xF8AF918D, 0x4E48F79E, 0x8F616DDF, 0xE29D840E, |
|
| 535 | + 0x842F7D83, 0x340CE5C8, 0x96BBB682, 0x93B4B148, |
|
| 536 | + 0xEF303CAB, 0x984FAF28, 0x779FAF9B, 0x92DC560D, |
|
| 537 | + 0x224D1E20, 0x8437AA88, 0x7D29DC96, 0x2756D3DC, |
|
| 538 | + 0x8B907CEE, 0xB51FD240, 0xE7C07CE3, 0xE566B4A1, |
|
| 539 | + 0xC3E9615E, 0x3CF8209D, 0x6094D1E3, 0xCD9CA341, |
|
| 540 | + 0x5C76460E, 0x00EA983B, 0xD4D67881, 0xFD47572C, |
|
| 541 | + 0xF76CEDD9, 0xBDA8229C, 0x127DADAA, 0x438A074E, |
|
| 542 | + 0x1F97C090, 0x081BDB8A, 0x93A07EBE, 0xB938CA15, |
|
| 543 | + 0x97B03CFF, 0x3DC2C0F8, 0x8D1AB2EC, 0x64380E51, |
|
| 544 | + 0x68CC7BFB, 0xD90F2788, 0x12490181, 0x5DE5FFD4, |
|
| 545 | + 0xDD7EF86A, 0x76A2E214, 0xB9A40368, 0x925D958F, |
|
| 546 | + 0x4B39FFFA, 0xBA39AEE9, 0xA4FFD30B, 0xFAF7933B, |
|
| 547 | + 0x6D498623, 0x193CBCFA, 0x27627545, 0x825CF47A, |
|
| 548 | + 0x61BD8BA0, 0xD11E42D1, 0xCEAD04F4, 0x127EA392, |
|
| 549 | + 0x10428DB7, 0x8272A972, 0x9270C4A8, 0x127DE50B, |
|
| 550 | + 0x285BA1C8, 0x3C62F44F, 0x35C0EAA5, 0xE805D231, |
|
| 551 | + 0x428929FB, 0xB4FCDF82, 0x4FB66A53, 0x0E7DC15B, |
|
| 552 | + 0x1F081FAB, 0x108618AE, 0xFCFD086D, 0xF9FF2889, |
|
| 553 | + 0x694BCC11, 0x236A5CAE, 0x12DECA4D, 0x2C3F8CC5, |
|
| 554 | + 0xD2D02DFE, 0xF8EF5896, 0xE4CF52DA, 0x95155B67, |
|
| 555 | + 0x494A488C, 0xB9B6A80C, 0x5C8F82BC, 0x89D36B45, |
|
| 556 | + 0x3A609437, 0xEC00C9A9, 0x44715253, 0x0A874B49, |
|
| 557 | + 0xD773BC40, 0x7C34671C, 0x02717EF6, 0x4FEB5536, |
|
| 558 | + 0xA2D02FFF, 0xD2BF60C4, 0xD43F03C0, 0x50B4EF6D, |
|
| 559 | + 0x07478CD1, 0x006E1888, 0xA2E53F55, 0xB9E6D4BC, |
|
| 560 | + 0xA2048016, 0x97573833, 0xD7207D67, 0xDE0F8F3D, |
|
| 561 | + 0x72F87B33, 0xABCC4F33, 0x7688C55D, 0x7B00A6B0, |
|
| 562 | + 0x947B0001, 0x570075D2, 0xF9BB88F8, 0x8942019E, |
|
| 563 | + 0x4264A5FF, 0x856302E0, 0x72DBD92B, 0xEE971B69, |
|
| 564 | + 0x6EA22FDE, 0x5F08AE2B, 0xAF7A616D, 0xE5C98767, |
|
| 565 | + 0xCF1FEBD2, 0x61EFC8C2, 0xF1AC2571, 0xCC8239C2, |
|
| 566 | + 0x67214CB8, 0xB1E583D1, 0xB7DC3E62, 0x7F10BDCE, |
|
| 567 | + 0xF90A5C38, 0x0FF0443D, 0x606E6DC6, 0x60543A49, |
|
| 568 | + 0x5727C148, 0x2BE98A1D, 0x8AB41738, 0x20E1BE24, |
|
| 569 | + 0xAF96DA0F, 0x68458425, 0x99833BE5, 0x600D457D, |
|
| 570 | + 0x282F9350, 0x8334B362, 0xD91D1120, 0x2B6D8DA0, |
|
| 571 | + 0x642B1E31, 0x9C305A00, 0x52BCE688, 0x1B03588A, |
|
| 572 | + 0xF7BAEFD5, 0x4142ED9C, 0xA4315C11, 0x83323EC5, |
|
| 573 | + 0xDFEF4636, 0xA133C501, 0xE9D3531C, 0xEE353783 |
|
| 574 | + ); |
|
| 575 | + |
|
| 576 | + // 256 unsigned 32 bit integers |
|
| 577 | + self::$_s4 = array( |
|
| 578 | + 0x9DB30420, 0x1FB6E9DE, 0xA7BE7BEF, 0xD273A298, |
|
| 579 | + 0x4A4F7BDB, 0x64AD8C57, 0x85510443, 0xFA020ED1, |
|
| 580 | + 0x7E287AFF, 0xE60FB663, 0x095F35A1, 0x79EBF120, |
|
| 581 | + 0xFD059D43, 0x6497B7B1, 0xF3641F63, 0x241E4ADF, |
|
| 582 | + 0x28147F5F, 0x4FA2B8CD, 0xC9430040, 0x0CC32220, |
|
| 583 | + 0xFDD30B30, 0xC0A5374F, 0x1D2D00D9, 0x24147B15, |
|
| 584 | + 0xEE4D111A, 0x0FCA5167, 0x71FF904C, 0x2D195FFE, |
|
| 585 | + 0x1A05645F, 0x0C13FEFE, 0x081B08CA, 0x05170121, |
|
| 586 | + 0x80530100, 0xE83E5EFE, 0xAC9AF4F8, 0x7FE72701, |
|
| 587 | + 0xD2B8EE5F, 0x06DF4261, 0xBB9E9B8A, 0x7293EA25, |
|
| 588 | + 0xCE84FFDF, 0xF5718801, 0x3DD64B04, 0xA26F263B, |
|
| 589 | + 0x7ED48400, 0x547EEBE6, 0x446D4CA0, 0x6CF3D6F5, |
|
| 590 | + 0x2649ABDF, 0xAEA0C7F5, 0x36338CC1, 0x503F7E93, |
|
| 591 | + 0xD3772061, 0x11B638E1, 0x72500E03, 0xF80EB2BB, |
|
| 592 | + 0xABE0502E, 0xEC8D77DE, 0x57971E81, 0xE14F6746, |
|
| 593 | + 0xC9335400, 0x6920318F, 0x081DBB99, 0xFFC304A5, |
|
| 594 | + 0x4D351805, 0x7F3D5CE3, 0xA6C866C6, 0x5D5BCCA9, |
|
| 595 | + 0xDAEC6FEA, 0x9F926F91, 0x9F46222F, 0x3991467D, |
|
| 596 | + 0xA5BF6D8E, 0x1143C44F, 0x43958302, 0xD0214EEB, |
|
| 597 | + 0x022083B8, 0x3FB6180C, 0x18F8931E, 0x281658E6, |
|
| 598 | + 0x26486E3E, 0x8BD78A70, 0x7477E4C1, 0xB506E07C, |
|
| 599 | + 0xF32D0A25, 0x79098B02, 0xE4EABB81, 0x28123B23, |
|
| 600 | + 0x69DEAD38, 0x1574CA16, 0xDF871B62, 0x211C40B7, |
|
| 601 | + 0xA51A9EF9, 0x0014377B, 0x041E8AC8, 0x09114003, |
|
| 602 | + 0xBD59E4D2, 0xE3D156D5, 0x4FE876D5, 0x2F91A340, |
|
| 603 | + 0x557BE8DE, 0x00EAE4A7, 0x0CE5C2EC, 0x4DB4BBA6, |
|
| 604 | + 0xE756BDFF, 0xDD3369AC, 0xEC17B035, 0x06572327, |
|
| 605 | + 0x99AFC8B0, 0x56C8C391, 0x6B65811C, 0x5E146119, |
|
| 606 | + 0x6E85CB75, 0xBE07C002, 0xC2325577, 0x893FF4EC, |
|
| 607 | + 0x5BBFC92D, 0xD0EC3B25, 0xB7801AB7, 0x8D6D3B24, |
|
| 608 | + 0x20C763EF, 0xC366A5FC, 0x9C382880, 0x0ACE3205, |
|
| 609 | + 0xAAC9548A, 0xECA1D7C7, 0x041AFA32, 0x1D16625A, |
|
| 610 | + 0x6701902C, 0x9B757A54, 0x31D477F7, 0x9126B031, |
|
| 611 | + 0x36CC6FDB, 0xC70B8B46, 0xD9E66A48, 0x56E55A79, |
|
| 612 | + 0x026A4CEB, 0x52437EFF, 0x2F8F76B4, 0x0DF980A5, |
|
| 613 | + 0x8674CDE3, 0xEDDA04EB, 0x17A9BE04, 0x2C18F4DF, |
|
| 614 | + 0xB7747F9D, 0xAB2AF7B4, 0xEFC34D20, 0x2E096B7C, |
|
| 615 | + 0x1741A254, 0xE5B6A035, 0x213D42F6, 0x2C1C7C26, |
|
| 616 | + 0x61C2F50F, 0x6552DAF9, 0xD2C231F8, 0x25130F69, |
|
| 617 | + 0xD8167FA2, 0x0418F2C8, 0x001A96A6, 0x0D1526AB, |
|
| 618 | + 0x63315C21, 0x5E0A72EC, 0x49BAFEFD, 0x187908D9, |
|
| 619 | + 0x8D0DBD86, 0x311170A7, 0x3E9B640C, 0xCC3E10D7, |
|
| 620 | + 0xD5CAD3B6, 0x0CAEC388, 0xF73001E1, 0x6C728AFF, |
|
| 621 | + 0x71EAE2A1, 0x1F9AF36E, 0xCFCBD12F, 0xC1DE8417, |
|
| 622 | + 0xAC07BE6B, 0xCB44A1D8, 0x8B9B0F56, 0x013988C3, |
|
| 623 | + 0xB1C52FCA, 0xB4BE31CD, 0xD8782806, 0x12A3A4E2, |
|
| 624 | + 0x6F7DE532, 0x58FD7EB6, 0xD01EE900, 0x24ADFFC2, |
|
| 625 | + 0xF4990FC5, 0x9711AAC5, 0x001D7B95, 0x82E5E7D2, |
|
| 626 | + 0x109873F6, 0x00613096, 0xC32D9521, 0xADA121FF, |
|
| 627 | + 0x29908415, 0x7FBB977F, 0xAF9EB3DB, 0x29C9ED2A, |
|
| 628 | + 0x5CE2A465, 0xA730F32C, 0xD0AA3FE8, 0x8A5CC091, |
|
| 629 | + 0xD49E2CE7, 0x0CE454A9, 0xD60ACD86, 0x015F1919, |
|
| 630 | + 0x77079103, 0xDEA03AF6, 0x78A8565E, 0xDEE356DF, |
|
| 631 | + 0x21F05CBE, 0x8B75E387, 0xB3C50651, 0xB8A5C3EF, |
|
| 632 | + 0xD8EEB6D2, 0xE523BE77, 0xC2154529, 0x2F69EFDF, |
|
| 633 | + 0xAFE67AFB, 0xF470C4B2, 0xF3E0EB5B, 0xD6CC9876, |
|
| 634 | + 0x39E4460C, 0x1FDA8538, 0x1987832F, 0xCA007367, |
|
| 635 | + 0xA99144F8, 0x296B299E, 0x492FC295, 0x9266BEAB, |
|
| 636 | + 0xB5676E69, 0x9BD3DDDA, 0xDF7E052F, 0xDB25701C, |
|
| 637 | + 0x1B5E51EE, 0xF65324E6, 0x6AFCE36C, 0x0316CC04, |
|
| 638 | + 0x8644213E, 0xB7DC59D0, 0x7965291F, 0xCCD6FD43, |
|
| 639 | + 0x41823979, 0x932BCDF6, 0xB657C34D, 0x4EDFD282, |
|
| 640 | + 0x7AE5290C, 0x3CB9536B, 0x851E20FE, 0x9833557E, |
|
| 641 | + 0x13ECF0B0, 0xD3FFB372, 0x3F85C5C1, 0x0AEF7ED2 |
|
| 642 | + ); |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + |
|
| 646 | + /** |
|
| 647 | + * Indicates this is a block cipher |
|
| 648 | + * |
|
| 649 | + * @return integer Returns Cipher::BLOCK |
|
| 650 | + */ |
|
| 651 | + public function type() |
|
| 652 | + { |
|
| 653 | + return parent::BLOCK; |
|
| 654 | + } |
|
| 655 | 655 | } |
| 656 | 656 | ?> |
@@ -39,205 +39,205 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | class Cipher_Skipjack extends Cipher |
| 41 | 41 | { |
| 42 | - /** @type integer BYTES_BLOCK The size of the block, in bytes */ |
|
| 43 | - const BYTES_BLOCK = 8; // 64 bits |
|
| 42 | + /** @type integer BYTES_BLOCK The size of the block, in bytes */ |
|
| 43 | + const BYTES_BLOCK = 8; // 64 bits |
|
| 44 | 44 | |
| 45 | - /** @type integer BYTES_KEY The size of the key, in bytes */ |
|
| 46 | - const BYTES_KEY = 10; // 80 bits |
|
| 45 | + /** @type integer BYTES_KEY The size of the key, in bytes */ |
|
| 46 | + const BYTES_KEY = 10; // 80 bits |
|
| 47 | 47 | |
| 48 | - /** @type string $expanded_key The expanded key */ |
|
| 49 | - private $expanded_key = ""; |
|
| 48 | + /** @type string $expanded_key The expanded key */ |
|
| 49 | + private $expanded_key = ""; |
|
| 50 | 50 | |
| 51 | - /** @type array $_f The Skipjack F-Table, this is a constant */ |
|
| 52 | - private static $_f = array(); |
|
| 51 | + /** @type array $_f The Skipjack F-Table, this is a constant */ |
|
| 52 | + private static $_f = array(); |
|
| 53 | 53 | |
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Constructor |
|
| 57 | - * |
|
| 58 | - * @param string $key The key used for Encryption/Decryption |
|
| 59 | - * @return void |
|
| 60 | - */ |
|
| 61 | - public function __construct($key) |
|
| 62 | - { |
|
| 63 | - // set the Skipjack key |
|
| 64 | - parent::__construct(PHP_Crypt::CIPHER_SKIPJACK, $key, self::BYTES_KEY); |
|
| 65 | - |
|
| 66 | - // initialize variables |
|
| 67 | - $this->initTables(); |
|
| 68 | - |
|
| 69 | - // set the block size used |
|
| 70 | - $this->blockSize(self::BYTES_BLOCK); |
|
| 71 | - |
|
| 72 | - // expand the key from 10 bytes to 128 bytes |
|
| 73 | - $this->expandKey(); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Destructor |
|
| 79 | - * |
|
| 80 | - * @return void |
|
| 81 | - */ |
|
| 82 | - public function __destruct() |
|
| 83 | - { |
|
| 84 | - parent::__destruct(); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Encrypt plain text data using Skipjack |
|
| 90 | - * |
|
| 91 | - * @param string $data A plain text string, 8 bytes long |
|
| 92 | - * @return boolean Returns true |
|
| 93 | - */ |
|
| 94 | - public function encrypt(&$text) |
|
| 95 | - { |
|
| 96 | - $this->operation(parent::ENCRYPT); |
|
| 97 | - |
|
| 98 | - for($i = 1; $i <= 32; ++$i) |
|
| 99 | - { |
|
| 100 | - $pos = (4 * $i) - 4; |
|
| 101 | - $subkey = substr($this->expanded_key, $pos, 4); |
|
| 102 | - |
|
| 103 | - if($i >= 1 && $i <= 8) |
|
| 104 | - $this->ruleA($text, $subkey, $i); |
|
| 105 | - |
|
| 106 | - if($i >= 9 && $i <= 16) |
|
| 107 | - $this->ruleB($text, $subkey, $i); |
|
| 108 | - |
|
| 109 | - if($i >= 17 && $i <= 24) |
|
| 110 | - $this->ruleA($text, $subkey, $i); |
|
| 111 | - |
|
| 112 | - if($i >= 25 && $i <= 32) |
|
| 113 | - $this->ruleB($text, $subkey, $i); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - return true; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Decrypt a Skipjack encrypted string |
|
| 122 | - * |
|
| 123 | - * @param string $encrypted A Skipjack encrypted string, 8 bytes long |
|
| 124 | - * @return boolean Returns true |
|
| 125 | - */ |
|
| 126 | - public function decrypt(&$text) |
|
| 127 | - { |
|
| 128 | - $this->operation(parent::DECRYPT); |
|
| 129 | - |
|
| 130 | - for($i = 32; $i >= 1; --$i) |
|
| 131 | - { |
|
| 132 | - $pos = ($i - 1) * 4; |
|
| 133 | - $subkey = substr($this->expanded_key, $pos, 4); |
|
| 134 | - |
|
| 135 | - if($i <= 32 && $i >= 25) |
|
| 136 | - $this->ruleB($text, $subkey, $i); |
|
| 137 | - |
|
| 138 | - if($i <= 24 && $i >= 17) |
|
| 139 | - $this->ruleA($text, $subkey, $i); |
|
| 140 | - |
|
| 141 | - if($i <= 16 && $i >= 9) |
|
| 142 | - $this->ruleB($text, $subkey, $i); |
|
| 143 | - |
|
| 144 | - if($i <= 8 && $i >= 1) |
|
| 145 | - $this->ruleA($text, $subkey, $i); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - return true; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * For the G Permutations, the input data is 2 Bytes The first byte is |
|
| 154 | - * the left side and the second is the right side.The round key is 4 bytes |
|
| 155 | - * long (Indices 8*i-8 to 8*i), which is split as 4 pieces: K0, K1, K2, K3 |
|
| 156 | - * |
|
| 157 | - * @param string $bytes A 2 byte string |
|
| 158 | - * @param string $key 4 bytes of $this->expanded_key |
|
| 159 | - * @return string A 2 byte string, the G Permutation of $bytes |
|
| 160 | - */ |
|
| 161 | - private function gPermutation($bytes, $key) |
|
| 162 | - { |
|
| 163 | - $left = ord($bytes[0]); |
|
| 164 | - $right = ord($bytes[1]); |
|
| 165 | - |
|
| 166 | - if($this->operation() == parent::ENCRYPT) |
|
| 167 | - { |
|
| 168 | - for($i = 0; $i < 4; ++$i) |
|
| 169 | - { |
|
| 170 | - if($i == 0 || $i == 2) |
|
| 171 | - { |
|
| 172 | - $pos = $right ^ $this->str2Dec($key[$i]); |
|
| 173 | - $left = $left ^ self::$_f[$pos]; |
|
| 174 | - } |
|
| 175 | - else |
|
| 176 | - { |
|
| 177 | - $pos = $left ^ $this->str2Dec($key[$i]); |
|
| 178 | - $right = $right ^ self::$_f[$pos]; |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - else // parent::DECRYPT |
|
| 183 | - { |
|
| 184 | - // we do the same as in encryption, but apply the key backwards, |
|
| 185 | - // from key[3] to key[0] |
|
| 186 | - for($i = 3; $i >= 0; --$i) |
|
| 187 | - { |
|
| 188 | - if($i == 0 || $i == 2) |
|
| 189 | - { |
|
| 190 | - $pos = $right ^ $this->str2Dec($key[$i]); |
|
| 191 | - $left = $left ^ self::$_f[$pos]; |
|
| 192 | - } |
|
| 193 | - else |
|
| 194 | - { |
|
| 195 | - $pos = $left ^ $this->str2Dec($key[$i]); |
|
| 196 | - $right = $right ^ self::$_f[$pos]; |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - return $this->dec2Str($left).$this->dec2Str($right); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * Perform SkipJacks RuleA function. Split the data into 4 parts, |
|
| 207 | - * 2 bytes each: W0, W1, W2, W3. |
|
| 208 | - * |
|
| 209 | - * @param string $bytes An 8 byte string |
|
| 210 | - * @param string $key 4 bytes of $this->expanded_key |
|
| 211 | - * @param integer $i The round number |
|
| 212 | - * @return void |
|
| 213 | - */ |
|
| 214 | - private function ruleA(&$bytes, $key, $i) |
|
| 215 | - { |
|
| 216 | - $w = str_split($bytes, 2); |
|
| 217 | - |
|
| 218 | - if($this->operation() == parent::ENCRYPT) |
|
| 219 | - { |
|
| 220 | - /* |
|
| 55 | + /** |
|
| 56 | + * Constructor |
|
| 57 | + * |
|
| 58 | + * @param string $key The key used for Encryption/Decryption |
|
| 59 | + * @return void |
|
| 60 | + */ |
|
| 61 | + public function __construct($key) |
|
| 62 | + { |
|
| 63 | + // set the Skipjack key |
|
| 64 | + parent::__construct(PHP_Crypt::CIPHER_SKIPJACK, $key, self::BYTES_KEY); |
|
| 65 | + |
|
| 66 | + // initialize variables |
|
| 67 | + $this->initTables(); |
|
| 68 | + |
|
| 69 | + // set the block size used |
|
| 70 | + $this->blockSize(self::BYTES_BLOCK); |
|
| 71 | + |
|
| 72 | + // expand the key from 10 bytes to 128 bytes |
|
| 73 | + $this->expandKey(); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Destructor |
|
| 79 | + * |
|
| 80 | + * @return void |
|
| 81 | + */ |
|
| 82 | + public function __destruct() |
|
| 83 | + { |
|
| 84 | + parent::__destruct(); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Encrypt plain text data using Skipjack |
|
| 90 | + * |
|
| 91 | + * @param string $data A plain text string, 8 bytes long |
|
| 92 | + * @return boolean Returns true |
|
| 93 | + */ |
|
| 94 | + public function encrypt(&$text) |
|
| 95 | + { |
|
| 96 | + $this->operation(parent::ENCRYPT); |
|
| 97 | + |
|
| 98 | + for($i = 1; $i <= 32; ++$i) |
|
| 99 | + { |
|
| 100 | + $pos = (4 * $i) - 4; |
|
| 101 | + $subkey = substr($this->expanded_key, $pos, 4); |
|
| 102 | + |
|
| 103 | + if($i >= 1 && $i <= 8) |
|
| 104 | + $this->ruleA($text, $subkey, $i); |
|
| 105 | + |
|
| 106 | + if($i >= 9 && $i <= 16) |
|
| 107 | + $this->ruleB($text, $subkey, $i); |
|
| 108 | + |
|
| 109 | + if($i >= 17 && $i <= 24) |
|
| 110 | + $this->ruleA($text, $subkey, $i); |
|
| 111 | + |
|
| 112 | + if($i >= 25 && $i <= 32) |
|
| 113 | + $this->ruleB($text, $subkey, $i); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + return true; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Decrypt a Skipjack encrypted string |
|
| 122 | + * |
|
| 123 | + * @param string $encrypted A Skipjack encrypted string, 8 bytes long |
|
| 124 | + * @return boolean Returns true |
|
| 125 | + */ |
|
| 126 | + public function decrypt(&$text) |
|
| 127 | + { |
|
| 128 | + $this->operation(parent::DECRYPT); |
|
| 129 | + |
|
| 130 | + for($i = 32; $i >= 1; --$i) |
|
| 131 | + { |
|
| 132 | + $pos = ($i - 1) * 4; |
|
| 133 | + $subkey = substr($this->expanded_key, $pos, 4); |
|
| 134 | + |
|
| 135 | + if($i <= 32 && $i >= 25) |
|
| 136 | + $this->ruleB($text, $subkey, $i); |
|
| 137 | + |
|
| 138 | + if($i <= 24 && $i >= 17) |
|
| 139 | + $this->ruleA($text, $subkey, $i); |
|
| 140 | + |
|
| 141 | + if($i <= 16 && $i >= 9) |
|
| 142 | + $this->ruleB($text, $subkey, $i); |
|
| 143 | + |
|
| 144 | + if($i <= 8 && $i >= 1) |
|
| 145 | + $this->ruleA($text, $subkey, $i); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + return true; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * For the G Permutations, the input data is 2 Bytes The first byte is |
|
| 154 | + * the left side and the second is the right side.The round key is 4 bytes |
|
| 155 | + * long (Indices 8*i-8 to 8*i), which is split as 4 pieces: K0, K1, K2, K3 |
|
| 156 | + * |
|
| 157 | + * @param string $bytes A 2 byte string |
|
| 158 | + * @param string $key 4 bytes of $this->expanded_key |
|
| 159 | + * @return string A 2 byte string, the G Permutation of $bytes |
|
| 160 | + */ |
|
| 161 | + private function gPermutation($bytes, $key) |
|
| 162 | + { |
|
| 163 | + $left = ord($bytes[0]); |
|
| 164 | + $right = ord($bytes[1]); |
|
| 165 | + |
|
| 166 | + if($this->operation() == parent::ENCRYPT) |
|
| 167 | + { |
|
| 168 | + for($i = 0; $i < 4; ++$i) |
|
| 169 | + { |
|
| 170 | + if($i == 0 || $i == 2) |
|
| 171 | + { |
|
| 172 | + $pos = $right ^ $this->str2Dec($key[$i]); |
|
| 173 | + $left = $left ^ self::$_f[$pos]; |
|
| 174 | + } |
|
| 175 | + else |
|
| 176 | + { |
|
| 177 | + $pos = $left ^ $this->str2Dec($key[$i]); |
|
| 178 | + $right = $right ^ self::$_f[$pos]; |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + else // parent::DECRYPT |
|
| 183 | + { |
|
| 184 | + // we do the same as in encryption, but apply the key backwards, |
|
| 185 | + // from key[3] to key[0] |
|
| 186 | + for($i = 3; $i >= 0; --$i) |
|
| 187 | + { |
|
| 188 | + if($i == 0 || $i == 2) |
|
| 189 | + { |
|
| 190 | + $pos = $right ^ $this->str2Dec($key[$i]); |
|
| 191 | + $left = $left ^ self::$_f[$pos]; |
|
| 192 | + } |
|
| 193 | + else |
|
| 194 | + { |
|
| 195 | + $pos = $left ^ $this->str2Dec($key[$i]); |
|
| 196 | + $right = $right ^ self::$_f[$pos]; |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + return $this->dec2Str($left).$this->dec2Str($right); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * Perform SkipJacks RuleA function. Split the data into 4 parts, |
|
| 207 | + * 2 bytes each: W0, W1, W2, W3. |
|
| 208 | + * |
|
| 209 | + * @param string $bytes An 8 byte string |
|
| 210 | + * @param string $key 4 bytes of $this->expanded_key |
|
| 211 | + * @param integer $i The round number |
|
| 212 | + * @return void |
|
| 213 | + */ |
|
| 214 | + private function ruleA(&$bytes, $key, $i) |
|
| 215 | + { |
|
| 216 | + $w = str_split($bytes, 2); |
|
| 217 | + |
|
| 218 | + if($this->operation() == parent::ENCRYPT) |
|
| 219 | + { |
|
| 220 | + /* |
|
| 221 | 221 | * Set the W3 as the old W2 |
| 222 | 222 | * Set the W2 as the old W1 |
| 223 | 223 | * Set the W1 as the G(W0) |
| 224 | 224 | * Set the W0 as the W1 xor W4 xor i |
| 225 | 225 | */ |
| 226 | 226 | |
| 227 | - $w[4] = $w[3]; |
|
| 228 | - $w[3] = $w[2]; |
|
| 229 | - $w[2] = $w[1]; |
|
| 230 | - $w[1] = $this->gPermutation($w[0], $key); |
|
| 231 | - |
|
| 232 | - $hex1 = $this->str2Hex($w[1]); |
|
| 233 | - $hex4 = $this->str2Hex($w[4]); |
|
| 234 | - $hexi = $this->dec2Hex($i); |
|
| 235 | - $w[0] = $this->xorHex($hex1, $hex4, $hexi); |
|
| 236 | - $w[0] = $this->hex2Str($w[0]); |
|
| 237 | - } |
|
| 238 | - else // parent::DECRYPT |
|
| 239 | - { |
|
| 240 | - /* |
|
| 227 | + $w[4] = $w[3]; |
|
| 228 | + $w[3] = $w[2]; |
|
| 229 | + $w[2] = $w[1]; |
|
| 230 | + $w[1] = $this->gPermutation($w[0], $key); |
|
| 231 | + |
|
| 232 | + $hex1 = $this->str2Hex($w[1]); |
|
| 233 | + $hex4 = $this->str2Hex($w[4]); |
|
| 234 | + $hexi = $this->dec2Hex($i); |
|
| 235 | + $w[0] = $this->xorHex($hex1, $hex4, $hexi); |
|
| 236 | + $w[0] = $this->hex2Str($w[0]); |
|
| 237 | + } |
|
| 238 | + else // parent::DECRYPT |
|
| 239 | + { |
|
| 240 | + /* |
|
| 241 | 241 | * Set W4 as W0 xor W1 xor i |
| 242 | 242 | * Set W0 as Inverse G(W1) |
| 243 | 243 | * Set W1 as the old W2 |
@@ -245,60 +245,60 @@ discard block |
||
| 245 | 245 | * Set W3 as W4 |
| 246 | 246 | */ |
| 247 | 247 | |
| 248 | - $hex0 = $this->str2Hex($w[0]); |
|
| 249 | - $hex1 = $this->str2Hex($w[1]); |
|
| 250 | - $hexi = $this->dec2Hex($i); |
|
| 251 | - $w[4] = $this->xorHex($hex0, $hex1, $hexi); |
|
| 252 | - $w[4] = $this->hex2Str($w[4]); |
|
| 253 | - |
|
| 254 | - $w[0] = $this->gPermutation($w[1], $key); |
|
| 255 | - $w[1] = $w[2]; |
|
| 256 | - $w[2] = $w[3]; |
|
| 257 | - $w[3] = $w[4]; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - // glue all the pieces back together |
|
| 261 | - $bytes = $w[0].$w[1].$w[2].$w[3]; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * Perform SkipJacks RuleB function. Split the data into 4 parts, |
|
| 267 | - * 2 bytes each: W0, W1, W2, W3. |
|
| 268 | - * |
|
| 269 | - * @param string $bytes An 8 bytes string |
|
| 270 | - * @param string $key 4 bytes of $this->expanded_key |
|
| 271 | - * @param integer $i The round number |
|
| 272 | - * @return void |
|
| 273 | - */ |
|
| 274 | - private function ruleB(&$bytes, $key, $i) |
|
| 275 | - { |
|
| 276 | - $w = str_split($bytes, 2); |
|
| 277 | - |
|
| 278 | - if($this->operation() == parent::ENCRYPT) |
|
| 279 | - { |
|
| 280 | - /* |
|
| 248 | + $hex0 = $this->str2Hex($w[0]); |
|
| 249 | + $hex1 = $this->str2Hex($w[1]); |
|
| 250 | + $hexi = $this->dec2Hex($i); |
|
| 251 | + $w[4] = $this->xorHex($hex0, $hex1, $hexi); |
|
| 252 | + $w[4] = $this->hex2Str($w[4]); |
|
| 253 | + |
|
| 254 | + $w[0] = $this->gPermutation($w[1], $key); |
|
| 255 | + $w[1] = $w[2]; |
|
| 256 | + $w[2] = $w[3]; |
|
| 257 | + $w[3] = $w[4]; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + // glue all the pieces back together |
|
| 261 | + $bytes = $w[0].$w[1].$w[2].$w[3]; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * Perform SkipJacks RuleB function. Split the data into 4 parts, |
|
| 267 | + * 2 bytes each: W0, W1, W2, W3. |
|
| 268 | + * |
|
| 269 | + * @param string $bytes An 8 bytes string |
|
| 270 | + * @param string $key 4 bytes of $this->expanded_key |
|
| 271 | + * @param integer $i The round number |
|
| 272 | + * @return void |
|
| 273 | + */ |
|
| 274 | + private function ruleB(&$bytes, $key, $i) |
|
| 275 | + { |
|
| 276 | + $w = str_split($bytes, 2); |
|
| 277 | + |
|
| 278 | + if($this->operation() == parent::ENCRYPT) |
|
| 279 | + { |
|
| 280 | + /* |
|
| 281 | 281 | * Set the new W3 as the old W2 |
| 282 | 282 | * Set the new W2 as the old W0 xor old W1 xor i |
| 283 | 283 | * Set the new W1 as G(old W0) |
| 284 | 284 | * Set the new W0 as the old W3 |
| 285 | 285 | */ |
| 286 | 286 | |
| 287 | - $w[4] = $w[3]; |
|
| 288 | - $w[3] = $w[2]; |
|
| 289 | - |
|
| 290 | - $hex0 = $this->str2Hex($w[0]); |
|
| 291 | - $hex1 = $this->str2Hex($w[1]); |
|
| 292 | - $hexi = $this->dec2Hex($i); |
|
| 293 | - $w[2] = $this->xorHex($hex0, $hex1, $hexi); |
|
| 294 | - $w[2] = $this->hex2Str($w[2]); |
|
| 295 | - |
|
| 296 | - $w[1] = $this->gPermutation($w[0], $key); |
|
| 297 | - $w[0] = $w[4]; |
|
| 298 | - } |
|
| 299 | - else // parent::DECRYPT |
|
| 300 | - { |
|
| 301 | - /* |
|
| 287 | + $w[4] = $w[3]; |
|
| 288 | + $w[3] = $w[2]; |
|
| 289 | + |
|
| 290 | + $hex0 = $this->str2Hex($w[0]); |
|
| 291 | + $hex1 = $this->str2Hex($w[1]); |
|
| 292 | + $hexi = $this->dec2Hex($i); |
|
| 293 | + $w[2] = $this->xorHex($hex0, $hex1, $hexi); |
|
| 294 | + $w[2] = $this->hex2Str($w[2]); |
|
| 295 | + |
|
| 296 | + $w[1] = $this->gPermutation($w[0], $key); |
|
| 297 | + $w[0] = $w[4]; |
|
| 298 | + } |
|
| 299 | + else // parent::DECRYPT |
|
| 300 | + { |
|
| 301 | + /* |
|
| 302 | 302 | * Set W4 as the old W0 |
| 303 | 303 | * Set new W0 as Inverse G(old W1) |
| 304 | 304 | * Set new W1 as Inverse G(old W1) xor old W2 xor i |
@@ -306,86 +306,86 @@ discard block |
||
| 306 | 306 | * Set new W0 as the old W4 |
| 307 | 307 | */ |
| 308 | 308 | |
| 309 | - $w[4] = $w[0]; |
|
| 310 | - $w[0] = $this->gPermutation($w[1], $key); |
|
| 311 | - |
|
| 312 | - $hex0 = $this->str2Hex($w[0]); |
|
| 313 | - $hex2 = $this->str2Hex($w[2]); |
|
| 314 | - $hexi = $this->dec2Hex($i); |
|
| 315 | - $w[1] = $this->xorHex($hex0, $hex2, $hexi); |
|
| 316 | - $w[1] = $this->hex2Str($w[1]); |
|
| 317 | - |
|
| 318 | - $w[2] = $w[3]; |
|
| 319 | - $w[3] = $w[4]; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - $bytes = $w[0].$w[1].$w[2].$w[3]; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * Expands the key from 10 bytes, to 128 bytes |
|
| 328 | - * This is done by copying the key 1 byte at a time and |
|
| 329 | - * appending it to $this->expanded_key, when we reach the |
|
| 330 | - * end of the key, we start over at position 0 and continue |
|
| 331 | - * until we reach 128 bytes |
|
| 332 | - * |
|
| 333 | - * @return void |
|
| 334 | - */ |
|
| 335 | - private function expandKey() |
|
| 336 | - { |
|
| 337 | - $this->expanded_key = ""; |
|
| 338 | - $key_bytes = $this->keySize(); |
|
| 339 | - $key = $this->key(); |
|
| 340 | - $pos = 0; |
|
| 341 | - |
|
| 342 | - for($i = 0; $i < 128; ++$i) |
|
| 343 | - { |
|
| 344 | - if($pos == $key_bytes) |
|
| 345 | - $pos = 0; |
|
| 346 | - |
|
| 347 | - $this->expanded_key .= $key[$pos]; |
|
| 348 | - ++$pos; |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * Initialize all the tables, this function is called inside the constructor |
|
| 355 | - * |
|
| 356 | - * @return void |
|
| 357 | - */ |
|
| 358 | - private function initTables() |
|
| 359 | - { |
|
| 360 | - self::$_f = array( |
|
| 361 | - 0xa3, 0xd7, 0x09, 0x83, 0xf8, 0x48, 0xf6, 0xf4, 0xb3, 0x21, 0x15, 0x78, 0x99, 0xb1, 0xaf, 0xf9, |
|
| 362 | - 0xe7, 0x2d, 0x4d, 0x8a, 0xce, 0x4c, 0xca, 0x2e, 0x52, 0x95, 0xd9, 0x1e, 0x4e, 0x38, 0x44, 0x28, |
|
| 363 | - 0x0a, 0xdf, 0x02, 0xa0, 0x17, 0xf1, 0x60, 0x68, 0x12, 0xb7, 0x7a, 0xc3, 0xe9, 0xfa, 0x3d, 0x53, |
|
| 364 | - 0x96, 0x84, 0x6b, 0xba, 0xf2, 0x63, 0x9a, 0x19, 0x7c, 0xae, 0xe5, 0xf5, 0xf7, 0x16, 0x6a, 0xa2, |
|
| 365 | - 0x39, 0xb6, 0x7b, 0x0f, 0xc1, 0x93, 0x81, 0x1b, 0xee, 0xb4, 0x1a, 0xea, 0xd0, 0x91, 0x2f, 0xb8, |
|
| 366 | - 0x55, 0xb9, 0xda, 0x85, 0x3f, 0x41, 0xbf, 0xe0, 0x5a, 0x58, 0x80, 0x5f, 0x66, 0x0b, 0xd8, 0x90, |
|
| 367 | - 0x35, 0xd5, 0xc0, 0xa7, 0x33, 0x06, 0x65, 0x69, 0x45, 0x00, 0x94, 0x56, 0x6d, 0x98, 0x9b, 0x76, |
|
| 368 | - 0x97, 0xfc, 0xb2, 0xc2, 0xb0, 0xfe, 0xdb, 0x20, 0xe1, 0xeb, 0xd6, 0xe4, 0xdd, 0x47, 0x4a, 0x1d, |
|
| 369 | - 0x42, 0xed, 0x9e, 0x6e, 0x49, 0x3c, 0xcd, 0x43, 0x27, 0xd2, 0x07, 0xd4, 0xde, 0xc7, 0x67, 0x18, |
|
| 370 | - 0x89, 0xcb, 0x30, 0x1f, 0x8d, 0xc6, 0x8f, 0xaa, 0xc8, 0x74, 0xdc, 0xc9, 0x5d, 0x5c, 0x31, 0xa4, |
|
| 371 | - 0x70, 0x88, 0x61, 0x2c, 0x9f, 0x0d, 0x2b, 0x87, 0x50, 0x82, 0x54, 0x64, 0x26, 0x7d, 0x03, 0x40, |
|
| 372 | - 0x34, 0x4b, 0x1c, 0x73, 0xd1, 0xc4, 0xfd, 0x3b, 0xcc, 0xfb, 0x7f, 0xab, 0xe6, 0x3e, 0x5b, 0xa5, |
|
| 373 | - 0xad, 0x04, 0x23, 0x9c, 0x14, 0x51, 0x22, 0xf0, 0x29, 0x79, 0x71, 0x7e, 0xff, 0x8c, 0x0e, 0xe2, |
|
| 374 | - 0x0c, 0xef, 0xbc, 0x72, 0x75, 0x6f, 0x37, 0xa1, 0xec, 0xd3, 0x8e, 0x62, 0x8b, 0x86, 0x10, 0xe8, |
|
| 375 | - 0x08, 0x77, 0x11, 0xbe, 0x92, 0x4f, 0x24, 0xc5, 0x32, 0x36, 0x9d, 0xcf, 0xf3, 0xa6, 0xbb, 0xac, |
|
| 376 | - 0x5e, 0x6c, 0xa9, 0x13, 0x57, 0x25, 0xb5, 0xe3, 0xbd, 0xa8, 0x3a, 0x01, 0x05, 0x59, 0x2a, 0x46 |
|
| 377 | - ); |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * Indicates that this is a block cipher |
|
| 383 | - * |
|
| 384 | - * @return integer Returns Cipher::BLOCK |
|
| 385 | - */ |
|
| 386 | - public function type() |
|
| 387 | - { |
|
| 388 | - return parent::BLOCK; |
|
| 389 | - } |
|
| 309 | + $w[4] = $w[0]; |
|
| 310 | + $w[0] = $this->gPermutation($w[1], $key); |
|
| 311 | + |
|
| 312 | + $hex0 = $this->str2Hex($w[0]); |
|
| 313 | + $hex2 = $this->str2Hex($w[2]); |
|
| 314 | + $hexi = $this->dec2Hex($i); |
|
| 315 | + $w[1] = $this->xorHex($hex0, $hex2, $hexi); |
|
| 316 | + $w[1] = $this->hex2Str($w[1]); |
|
| 317 | + |
|
| 318 | + $w[2] = $w[3]; |
|
| 319 | + $w[3] = $w[4]; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + $bytes = $w[0].$w[1].$w[2].$w[3]; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * Expands the key from 10 bytes, to 128 bytes |
|
| 328 | + * This is done by copying the key 1 byte at a time and |
|
| 329 | + * appending it to $this->expanded_key, when we reach the |
|
| 330 | + * end of the key, we start over at position 0 and continue |
|
| 331 | + * until we reach 128 bytes |
|
| 332 | + * |
|
| 333 | + * @return void |
|
| 334 | + */ |
|
| 335 | + private function expandKey() |
|
| 336 | + { |
|
| 337 | + $this->expanded_key = ""; |
|
| 338 | + $key_bytes = $this->keySize(); |
|
| 339 | + $key = $this->key(); |
|
| 340 | + $pos = 0; |
|
| 341 | + |
|
| 342 | + for($i = 0; $i < 128; ++$i) |
|
| 343 | + { |
|
| 344 | + if($pos == $key_bytes) |
|
| 345 | + $pos = 0; |
|
| 346 | + |
|
| 347 | + $this->expanded_key .= $key[$pos]; |
|
| 348 | + ++$pos; |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * Initialize all the tables, this function is called inside the constructor |
|
| 355 | + * |
|
| 356 | + * @return void |
|
| 357 | + */ |
|
| 358 | + private function initTables() |
|
| 359 | + { |
|
| 360 | + self::$_f = array( |
|
| 361 | + 0xa3, 0xd7, 0x09, 0x83, 0xf8, 0x48, 0xf6, 0xf4, 0xb3, 0x21, 0x15, 0x78, 0x99, 0xb1, 0xaf, 0xf9, |
|
| 362 | + 0xe7, 0x2d, 0x4d, 0x8a, 0xce, 0x4c, 0xca, 0x2e, 0x52, 0x95, 0xd9, 0x1e, 0x4e, 0x38, 0x44, 0x28, |
|
| 363 | + 0x0a, 0xdf, 0x02, 0xa0, 0x17, 0xf1, 0x60, 0x68, 0x12, 0xb7, 0x7a, 0xc3, 0xe9, 0xfa, 0x3d, 0x53, |
|
| 364 | + 0x96, 0x84, 0x6b, 0xba, 0xf2, 0x63, 0x9a, 0x19, 0x7c, 0xae, 0xe5, 0xf5, 0xf7, 0x16, 0x6a, 0xa2, |
|
| 365 | + 0x39, 0xb6, 0x7b, 0x0f, 0xc1, 0x93, 0x81, 0x1b, 0xee, 0xb4, 0x1a, 0xea, 0xd0, 0x91, 0x2f, 0xb8, |
|
| 366 | + 0x55, 0xb9, 0xda, 0x85, 0x3f, 0x41, 0xbf, 0xe0, 0x5a, 0x58, 0x80, 0x5f, 0x66, 0x0b, 0xd8, 0x90, |
|
| 367 | + 0x35, 0xd5, 0xc0, 0xa7, 0x33, 0x06, 0x65, 0x69, 0x45, 0x00, 0x94, 0x56, 0x6d, 0x98, 0x9b, 0x76, |
|
| 368 | + 0x97, 0xfc, 0xb2, 0xc2, 0xb0, 0xfe, 0xdb, 0x20, 0xe1, 0xeb, 0xd6, 0xe4, 0xdd, 0x47, 0x4a, 0x1d, |
|
| 369 | + 0x42, 0xed, 0x9e, 0x6e, 0x49, 0x3c, 0xcd, 0x43, 0x27, 0xd2, 0x07, 0xd4, 0xde, 0xc7, 0x67, 0x18, |
|
| 370 | + 0x89, 0xcb, 0x30, 0x1f, 0x8d, 0xc6, 0x8f, 0xaa, 0xc8, 0x74, 0xdc, 0xc9, 0x5d, 0x5c, 0x31, 0xa4, |
|
| 371 | + 0x70, 0x88, 0x61, 0x2c, 0x9f, 0x0d, 0x2b, 0x87, 0x50, 0x82, 0x54, 0x64, 0x26, 0x7d, 0x03, 0x40, |
|
| 372 | + 0x34, 0x4b, 0x1c, 0x73, 0xd1, 0xc4, 0xfd, 0x3b, 0xcc, 0xfb, 0x7f, 0xab, 0xe6, 0x3e, 0x5b, 0xa5, |
|
| 373 | + 0xad, 0x04, 0x23, 0x9c, 0x14, 0x51, 0x22, 0xf0, 0x29, 0x79, 0x71, 0x7e, 0xff, 0x8c, 0x0e, 0xe2, |
|
| 374 | + 0x0c, 0xef, 0xbc, 0x72, 0x75, 0x6f, 0x37, 0xa1, 0xec, 0xd3, 0x8e, 0x62, 0x8b, 0x86, 0x10, 0xe8, |
|
| 375 | + 0x08, 0x77, 0x11, 0xbe, 0x92, 0x4f, 0x24, 0xc5, 0x32, 0x36, 0x9d, 0xcf, 0xf3, 0xa6, 0xbb, 0xac, |
|
| 376 | + 0x5e, 0x6c, 0xa9, 0x13, 0x57, 0x25, 0xb5, 0xe3, 0xbd, 0xa8, 0x3a, 0x01, 0x05, 0x59, 0x2a, 0x46 |
|
| 377 | + ); |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * Indicates that this is a block cipher |
|
| 383 | + * |
|
| 384 | + * @return integer Returns Cipher::BLOCK |
|
| 385 | + */ |
|
| 386 | + public function type() |
|
| 387 | + { |
|
| 388 | + return parent::BLOCK; |
|
| 389 | + } |
|
| 390 | 390 | } |
| 391 | 391 | ?> |