Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/worker/src/PHPSecLi.../Crypt
File: RC2.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Pure-PHP implementation of RC2.
[3] Fix | Delete
*
[4] Fix | Delete
* Uses mcrypt, if available, and an internal implementation, otherwise.
[5] Fix | Delete
*
[6] Fix | Delete
* PHP versions 4 and 5
[7] Fix | Delete
*
[8] Fix | Delete
* Useful resources are as follows:
[9] Fix | Delete
*
[10] Fix | Delete
* - {@link http://tools.ietf.org/html/rfc2268}
[11] Fix | Delete
*
[12] Fix | Delete
* Here's a short example of how to use this library:
[13] Fix | Delete
* <code>
[14] Fix | Delete
* <?php
[15] Fix | Delete
* include 'Crypt/RC2.php';
[16] Fix | Delete
*
[17] Fix | Delete
* $rc2 = new Crypt_RC2();
[18] Fix | Delete
*
[19] Fix | Delete
* $rc2->setKey('abcdefgh');
[20] Fix | Delete
*
[21] Fix | Delete
* $plaintext = str_repeat('a', 1024);
[22] Fix | Delete
*
[23] Fix | Delete
* echo $rc2->decrypt($rc2->encrypt($plaintext));
[24] Fix | Delete
* ?>
[25] Fix | Delete
* </code>
[26] Fix | Delete
*
[27] Fix | Delete
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
[28] Fix | Delete
* of this software and associated documentation files (the "Software"), to deal
[29] Fix | Delete
* in the Software without restriction, including without limitation the rights
[30] Fix | Delete
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
[31] Fix | Delete
* copies of the Software, and to permit persons to whom the Software is
[32] Fix | Delete
* furnished to do so, subject to the following conditions:
[33] Fix | Delete
*
[34] Fix | Delete
* The above copyright notice and this permission notice shall be included in
[35] Fix | Delete
* all copies or substantial portions of the Software.
[36] Fix | Delete
*
[37] Fix | Delete
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
[38] Fix | Delete
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
[39] Fix | Delete
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
[40] Fix | Delete
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
[41] Fix | Delete
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
[42] Fix | Delete
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
[43] Fix | Delete
* THE SOFTWARE.
[44] Fix | Delete
*
[45] Fix | Delete
* @category Crypt
[46] Fix | Delete
* @package Crypt_RC2
[47] Fix | Delete
* @author Patrick Monnerat <pm@datasphere.ch>
[48] Fix | Delete
* @license http://www.opensource.org/licenses/mit-license.html MIT License
[49] Fix | Delete
* @link http://phpseclib.sourceforge.net
[50] Fix | Delete
*/
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* Include Crypt_Base
[54] Fix | Delete
*
[55] Fix | Delete
* Base cipher class
[56] Fix | Delete
*/
[57] Fix | Delete
if (!class_exists('Crypt_Base')) {
[58] Fix | Delete
require_once dirname(__FILE__).'/Base.php';
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
/**#@+
[62] Fix | Delete
* @access public
[63] Fix | Delete
* @see Crypt_RC2::encrypt()
[64] Fix | Delete
* @see Crypt_RC2::decrypt()
[65] Fix | Delete
*/
[66] Fix | Delete
/**
[67] Fix | Delete
* Encrypt / decrypt using the Counter mode.
[68] Fix | Delete
*
[69] Fix | Delete
* Set to -1 since that's what Crypt/Random.php uses to index the CTR mode.
[70] Fix | Delete
*
[71] Fix | Delete
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29
[72] Fix | Delete
*/
[73] Fix | Delete
define('CRYPT_RC2_MODE_CTR', CRYPT_MODE_CTR);
[74] Fix | Delete
/**
[75] Fix | Delete
* Encrypt / decrypt using the Electronic Code Book mode.
[76] Fix | Delete
*
[77] Fix | Delete
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
[78] Fix | Delete
*/
[79] Fix | Delete
define('CRYPT_RC2_MODE_ECB', CRYPT_MODE_ECB);
[80] Fix | Delete
/**
[81] Fix | Delete
* Encrypt / decrypt using the Code Book Chaining mode.
[82] Fix | Delete
*
[83] Fix | Delete
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29
[84] Fix | Delete
*/
[85] Fix | Delete
define('CRYPT_RC2_MODE_CBC', CRYPT_MODE_CBC);
[86] Fix | Delete
/**
[87] Fix | Delete
* Encrypt / decrypt using the Cipher Feedback mode.
[88] Fix | Delete
*
[89] Fix | Delete
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher_feedback_.28CFB.29
[90] Fix | Delete
*/
[91] Fix | Delete
define('CRYPT_RC2_MODE_CFB', CRYPT_MODE_CFB);
[92] Fix | Delete
/**
[93] Fix | Delete
* Encrypt / decrypt using the Cipher Feedback mode.
[94] Fix | Delete
*
[95] Fix | Delete
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Output_feedback_.28OFB.29
[96] Fix | Delete
*/
[97] Fix | Delete
define('CRYPT_RC2_MODE_OFB', CRYPT_MODE_OFB);
[98] Fix | Delete
/**#@-*/
[99] Fix | Delete
[100] Fix | Delete
/**#@+
[101] Fix | Delete
* @access private
[102] Fix | Delete
* @see Crypt_RC2::Crypt_RC2()
[103] Fix | Delete
*/
[104] Fix | Delete
/**
[105] Fix | Delete
* Toggles the internal implementation
[106] Fix | Delete
*/
[107] Fix | Delete
define('CRYPT_RC2_MODE_INTERNAL', CRYPT_MODE_INTERNAL);
[108] Fix | Delete
/**
[109] Fix | Delete
* Toggles the mcrypt implementation
[110] Fix | Delete
*/
[111] Fix | Delete
define('CRYPT_RC2_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
[112] Fix | Delete
/**#@-*/
[113] Fix | Delete
[114] Fix | Delete
/**
[115] Fix | Delete
* Pure-PHP implementation of RC2.
[116] Fix | Delete
*
[117] Fix | Delete
* @package Crypt_RC2
[118] Fix | Delete
* @access public
[119] Fix | Delete
*/
[120] Fix | Delete
class Crypt_RC2 extends Crypt_Base
[121] Fix | Delete
{
[122] Fix | Delete
/**
[123] Fix | Delete
* Block Length of the cipher
[124] Fix | Delete
*
[125] Fix | Delete
* @see Crypt_Base::block_size
[126] Fix | Delete
* @var Integer
[127] Fix | Delete
* @access private
[128] Fix | Delete
*/
[129] Fix | Delete
public $block_size = 8;
[130] Fix | Delete
[131] Fix | Delete
/**
[132] Fix | Delete
* The Key
[133] Fix | Delete
*
[134] Fix | Delete
* @see Crypt_Base::key
[135] Fix | Delete
* @see setKey()
[136] Fix | Delete
* @var String
[137] Fix | Delete
* @access private
[138] Fix | Delete
*/
[139] Fix | Delete
public $key = "\0";
[140] Fix | Delete
[141] Fix | Delete
/**
[142] Fix | Delete
* The default password key_size used by setPassword()
[143] Fix | Delete
*
[144] Fix | Delete
* @see Crypt_Base::password_key_size
[145] Fix | Delete
* @see Crypt_Base::setPassword()
[146] Fix | Delete
* @var Integer
[147] Fix | Delete
* @access private
[148] Fix | Delete
*/
[149] Fix | Delete
public $password_key_size = 16; // = 128 bits
[150] Fix | Delete
[151] Fix | Delete
/**
[152] Fix | Delete
* The namespace used by the cipher for its constants.
[153] Fix | Delete
*
[154] Fix | Delete
* @see Crypt_Base::const_namespace
[155] Fix | Delete
* @var String
[156] Fix | Delete
* @access private
[157] Fix | Delete
*/
[158] Fix | Delete
public $const_namespace = 'RC2';
[159] Fix | Delete
[160] Fix | Delete
/**
[161] Fix | Delete
* The mcrypt specific name of the cipher
[162] Fix | Delete
*
[163] Fix | Delete
* @see Crypt_Base::cipher_name_mcrypt
[164] Fix | Delete
* @var String
[165] Fix | Delete
* @access private
[166] Fix | Delete
*/
[167] Fix | Delete
public $cipher_name_mcrypt = 'rc2';
[168] Fix | Delete
[169] Fix | Delete
/**
[170] Fix | Delete
* Optimizing value while CFB-encrypting
[171] Fix | Delete
*
[172] Fix | Delete
* @see Crypt_Base::cfb_init_len
[173] Fix | Delete
* @var Integer
[174] Fix | Delete
* @access private
[175] Fix | Delete
*/
[176] Fix | Delete
public $cfb_init_len = 500;
[177] Fix | Delete
[178] Fix | Delete
/**
[179] Fix | Delete
* The key length in bits.
[180] Fix | Delete
*
[181] Fix | Delete
* @see Crypt_RC2::setKeyLength()
[182] Fix | Delete
* @see Crypt_RC2::setKey()
[183] Fix | Delete
* @var Integer
[184] Fix | Delete
* @access private
[185] Fix | Delete
* @internal Should be in range [1..1024].
[186] Fix | Delete
* @internal Changing this value after setting the key has no effect.
[187] Fix | Delete
*/
[188] Fix | Delete
public $default_key_length = 1024;
[189] Fix | Delete
[190] Fix | Delete
/**
[191] Fix | Delete
* The Key Schedule
[192] Fix | Delete
*
[193] Fix | Delete
* @see Crypt_RC2::_setupKey()
[194] Fix | Delete
* @var Array
[195] Fix | Delete
* @access private
[196] Fix | Delete
*/
[197] Fix | Delete
public $keys;
[198] Fix | Delete
[199] Fix | Delete
/**
[200] Fix | Delete
* Key expansion randomization table.
[201] Fix | Delete
* Twice the same 256-value sequence to save a modulus in key expansion.
[202] Fix | Delete
*
[203] Fix | Delete
* @see Crypt_RC2::setKey()
[204] Fix | Delete
* @var Array
[205] Fix | Delete
* @access private
[206] Fix | Delete
*/
[207] Fix | Delete
var $pitable = array(
[208] Fix | Delete
0xD9, 0x78, 0xF9, 0xC4, 0x19, 0xDD, 0xB5, 0xED,
[209] Fix | Delete
0x28, 0xE9, 0xFD, 0x79, 0x4A, 0xA0, 0xD8, 0x9D,
[210] Fix | Delete
0xC6, 0x7E, 0x37, 0x83, 0x2B, 0x76, 0x53, 0x8E,
[211] Fix | Delete
0x62, 0x4C, 0x64, 0x88, 0x44, 0x8B, 0xFB, 0xA2,
[212] Fix | Delete
0x17, 0x9A, 0x59, 0xF5, 0x87, 0xB3, 0x4F, 0x13,
[213] Fix | Delete
0x61, 0x45, 0x6D, 0x8D, 0x09, 0x81, 0x7D, 0x32,
[214] Fix | Delete
0xBD, 0x8F, 0x40, 0xEB, 0x86, 0xB7, 0x7B, 0x0B,
[215] Fix | Delete
0xF0, 0x95, 0x21, 0x22, 0x5C, 0x6B, 0x4E, 0x82,
[216] Fix | Delete
0x54, 0xD6, 0x65, 0x93, 0xCE, 0x60, 0xB2, 0x1C,
[217] Fix | Delete
0x73, 0x56, 0xC0, 0x14, 0xA7, 0x8C, 0xF1, 0xDC,
[218] Fix | Delete
0x12, 0x75, 0xCA, 0x1F, 0x3B, 0xBE, 0xE4, 0xD1,
[219] Fix | Delete
0x42, 0x3D, 0xD4, 0x30, 0xA3, 0x3C, 0xB6, 0x26,
[220] Fix | Delete
0x6F, 0xBF, 0x0E, 0xDA, 0x46, 0x69, 0x07, 0x57,
[221] Fix | Delete
0x27, 0xF2, 0x1D, 0x9B, 0xBC, 0x94, 0x43, 0x03,
[222] Fix | Delete
0xF8, 0x11, 0xC7, 0xF6, 0x90, 0xEF, 0x3E, 0xE7,
[223] Fix | Delete
0x06, 0xC3, 0xD5, 0x2F, 0xC8, 0x66, 0x1E, 0xD7,
[224] Fix | Delete
0x08, 0xE8, 0xEA, 0xDE, 0x80, 0x52, 0xEE, 0xF7,
[225] Fix | Delete
0x84, 0xAA, 0x72, 0xAC, 0x35, 0x4D, 0x6A, 0x2A,
[226] Fix | Delete
0x96, 0x1A, 0xD2, 0x71, 0x5A, 0x15, 0x49, 0x74,
[227] Fix | Delete
0x4B, 0x9F, 0xD0, 0x5E, 0x04, 0x18, 0xA4, 0xEC,
[228] Fix | Delete
0xC2, 0xE0, 0x41, 0x6E, 0x0F, 0x51, 0xCB, 0xCC,
[229] Fix | Delete
0x24, 0x91, 0xAF, 0x50, 0xA1, 0xF4, 0x70, 0x39,
[230] Fix | Delete
0x99, 0x7C, 0x3A, 0x85, 0x23, 0xB8, 0xB4, 0x7A,
[231] Fix | Delete
0xFC, 0x02, 0x36, 0x5B, 0x25, 0x55, 0x97, 0x31,
[232] Fix | Delete
0x2D, 0x5D, 0xFA, 0x98, 0xE3, 0x8A, 0x92, 0xAE,
[233] Fix | Delete
0x05, 0xDF, 0x29, 0x10, 0x67, 0x6C, 0xBA, 0xC9,
[234] Fix | Delete
0xD3, 0x00, 0xE6, 0xCF, 0xE1, 0x9E, 0xA8, 0x2C,
[235] Fix | Delete
0x63, 0x16, 0x01, 0x3F, 0x58, 0xE2, 0x89, 0xA9,
[236] Fix | Delete
0x0D, 0x38, 0x34, 0x1B, 0xAB, 0x33, 0xFF, 0xB0,
[237] Fix | Delete
0xBB, 0x48, 0x0C, 0x5F, 0xB9, 0xB1, 0xCD, 0x2E,
[238] Fix | Delete
0xC5, 0xF3, 0xDB, 0x47, 0xE5, 0xA5, 0x9C, 0x77,
[239] Fix | Delete
0x0A, 0xA6, 0x20, 0x68, 0xFE, 0x7F, 0xC1, 0xAD,
[240] Fix | Delete
0xD9, 0x78, 0xF9, 0xC4, 0x19, 0xDD, 0xB5, 0xED,
[241] Fix | Delete
0x28, 0xE9, 0xFD, 0x79, 0x4A, 0xA0, 0xD8, 0x9D,
[242] Fix | Delete
0xC6, 0x7E, 0x37, 0x83, 0x2B, 0x76, 0x53, 0x8E,
[243] Fix | Delete
0x62, 0x4C, 0x64, 0x88, 0x44, 0x8B, 0xFB, 0xA2,
[244] Fix | Delete
0x17, 0x9A, 0x59, 0xF5, 0x87, 0xB3, 0x4F, 0x13,
[245] Fix | Delete
0x61, 0x45, 0x6D, 0x8D, 0x09, 0x81, 0x7D, 0x32,
[246] Fix | Delete
0xBD, 0x8F, 0x40, 0xEB, 0x86, 0xB7, 0x7B, 0x0B,
[247] Fix | Delete
0xF0, 0x95, 0x21, 0x22, 0x5C, 0x6B, 0x4E, 0x82,
[248] Fix | Delete
0x54, 0xD6, 0x65, 0x93, 0xCE, 0x60, 0xB2, 0x1C,
[249] Fix | Delete
0x73, 0x56, 0xC0, 0x14, 0xA7, 0x8C, 0xF1, 0xDC,
[250] Fix | Delete
0x12, 0x75, 0xCA, 0x1F, 0x3B, 0xBE, 0xE4, 0xD1,
[251] Fix | Delete
0x42, 0x3D, 0xD4, 0x30, 0xA3, 0x3C, 0xB6, 0x26,
[252] Fix | Delete
0x6F, 0xBF, 0x0E, 0xDA, 0x46, 0x69, 0x07, 0x57,
[253] Fix | Delete
0x27, 0xF2, 0x1D, 0x9B, 0xBC, 0x94, 0x43, 0x03,
[254] Fix | Delete
0xF8, 0x11, 0xC7, 0xF6, 0x90, 0xEF, 0x3E, 0xE7,
[255] Fix | Delete
0x06, 0xC3, 0xD5, 0x2F, 0xC8, 0x66, 0x1E, 0xD7,
[256] Fix | Delete
0x08, 0xE8, 0xEA, 0xDE, 0x80, 0x52, 0xEE, 0xF7,
[257] Fix | Delete
0x84, 0xAA, 0x72, 0xAC, 0x35, 0x4D, 0x6A, 0x2A,
[258] Fix | Delete
0x96, 0x1A, 0xD2, 0x71, 0x5A, 0x15, 0x49, 0x74,
[259] Fix | Delete
0x4B, 0x9F, 0xD0, 0x5E, 0x04, 0x18, 0xA4, 0xEC,
[260] Fix | Delete
0xC2, 0xE0, 0x41, 0x6E, 0x0F, 0x51, 0xCB, 0xCC,
[261] Fix | Delete
0x24, 0x91, 0xAF, 0x50, 0xA1, 0xF4, 0x70, 0x39,
[262] Fix | Delete
0x99, 0x7C, 0x3A, 0x85, 0x23, 0xB8, 0xB4, 0x7A,
[263] Fix | Delete
0xFC, 0x02, 0x36, 0x5B, 0x25, 0x55, 0x97, 0x31,
[264] Fix | Delete
0x2D, 0x5D, 0xFA, 0x98, 0xE3, 0x8A, 0x92, 0xAE,
[265] Fix | Delete
0x05, 0xDF, 0x29, 0x10, 0x67, 0x6C, 0xBA, 0xC9,
[266] Fix | Delete
0xD3, 0x00, 0xE6, 0xCF, 0xE1, 0x9E, 0xA8, 0x2C,
[267] Fix | Delete
0x63, 0x16, 0x01, 0x3F, 0x58, 0xE2, 0x89, 0xA9,
[268] Fix | Delete
0x0D, 0x38, 0x34, 0x1B, 0xAB, 0x33, 0xFF, 0xB0,
[269] Fix | Delete
0xBB, 0x48, 0x0C, 0x5F, 0xB9, 0xB1, 0xCD, 0x2E,
[270] Fix | Delete
0xC5, 0xF3, 0xDB, 0x47, 0xE5, 0xA5, 0x9C, 0x77,
[271] Fix | Delete
0x0A, 0xA6, 0x20, 0x68, 0xFE, 0x7F, 0xC1, 0xAD,
[272] Fix | Delete
);
[273] Fix | Delete
[274] Fix | Delete
/**
[275] Fix | Delete
* Inverse key expansion randomization table.
[276] Fix | Delete
*
[277] Fix | Delete
* @see Crypt_RC2::setKey()
[278] Fix | Delete
* @var Array
[279] Fix | Delete
* @access private
[280] Fix | Delete
*/
[281] Fix | Delete
var $invpitable = array(
[282] Fix | Delete
0xD1, 0xDA, 0xB9, 0x6F, 0x9C, 0xC8, 0x78, 0x66,
[283] Fix | Delete
0x80, 0x2C, 0xF8, 0x37, 0xEA, 0xE0, 0x62, 0xA4,
[284] Fix | Delete
0xCB, 0x71, 0x50, 0x27, 0x4B, 0x95, 0xD9, 0x20,
[285] Fix | Delete
0x9D, 0x04, 0x91, 0xE3, 0x47, 0x6A, 0x7E, 0x53,
[286] Fix | Delete
0xFA, 0x3A, 0x3B, 0xB4, 0xA8, 0xBC, 0x5F, 0x68,
[287] Fix | Delete
0x08, 0xCA, 0x8F, 0x14, 0xD7, 0xC0, 0xEF, 0x7B,
[288] Fix | Delete
0x5B, 0xBF, 0x2F, 0xE5, 0xE2, 0x8C, 0xBA, 0x12,
[289] Fix | Delete
0xE1, 0xAF, 0xB2, 0x54, 0x5D, 0x59, 0x76, 0xDB,
[290] Fix | Delete
0x32, 0xA2, 0x58, 0x6E, 0x1C, 0x29, 0x64, 0xF3,
[291] Fix | Delete
0xE9, 0x96, 0x0C, 0x98, 0x19, 0x8D, 0x3E, 0x26,
[292] Fix | Delete
0xAB, 0xA5, 0x85, 0x16, 0x40, 0xBD, 0x49, 0x67,
[293] Fix | Delete
0xDC, 0x22, 0x94, 0xBB, 0x3C, 0xC1, 0x9B, 0xEB,
[294] Fix | Delete
0x45, 0x28, 0x18, 0xD8, 0x1A, 0x42, 0x7D, 0xCC,
[295] Fix | Delete
0xFB, 0x65, 0x8E, 0x3D, 0xCD, 0x2A, 0xA3, 0x60,
[296] Fix | Delete
0xAE, 0x93, 0x8A, 0x48, 0x97, 0x51, 0x15, 0xF7,
[297] Fix | Delete
0x01, 0x0B, 0xB7, 0x36, 0xB1, 0x2E, 0x11, 0xFD,
[298] Fix | Delete
0x84, 0x2D, 0x3F, 0x13, 0x88, 0xB3, 0x34, 0x24,
[299] Fix | Delete
0x1B, 0xDE, 0xC5, 0x1D, 0x4D, 0x2B, 0x17, 0x31,
[300] Fix | Delete
0x74, 0xA9, 0xC6, 0x43, 0x6D, 0x39, 0x90, 0xBE,
[301] Fix | Delete
0xC3, 0xB0, 0x21, 0x6B, 0xF6, 0x0F, 0xD5, 0x99,
[302] Fix | Delete
0x0D, 0xAC, 0x1F, 0x5C, 0x9E, 0xF5, 0xF9, 0x4C,
[303] Fix | Delete
0xD6, 0xDF, 0x89, 0xE4, 0x8B, 0xFF, 0xC7, 0xAA,
[304] Fix | Delete
0xE7, 0xED, 0x46, 0x25, 0xB6, 0x06, 0x5E, 0x35,
[305] Fix | Delete
0xB5, 0xEC, 0xCE, 0xE8, 0x6C, 0x30, 0x55, 0x61,
[306] Fix | Delete
0x4A, 0xFE, 0xA0, 0x79, 0x03, 0xF0, 0x10, 0x72,
[307] Fix | Delete
0x7C, 0xCF, 0x52, 0xA6, 0xA7, 0xEE, 0x44, 0xD3,
[308] Fix | Delete
0x9A, 0x57, 0x92, 0xD0, 0x5A, 0x7A, 0x41, 0x7F,
[309] Fix | Delete
0x0E, 0x00, 0x63, 0xF2, 0x4F, 0x05, 0x83, 0xC9,
[310] Fix | Delete
0xA1, 0xD4, 0xDD, 0xC4, 0x56, 0xF4, 0xD2, 0x77,
[311] Fix | Delete
0x81, 0x09, 0x82, 0x33, 0x9F, 0x07, 0x86, 0x75,
[312] Fix | Delete
0x38, 0x4E, 0x69, 0xF1, 0xAD, 0x23, 0x73, 0x87,
[313] Fix | Delete
0x70, 0x02, 0xC2, 0x1E, 0xB8, 0x0A, 0xFC, 0xE6,
[314] Fix | Delete
);
[315] Fix | Delete
[316] Fix | Delete
/**
[317] Fix | Delete
* Default Constructor.
[318] Fix | Delete
*
[319] Fix | Delete
* Determines whether or not the mcrypt extension should be used.
[320] Fix | Delete
*
[321] Fix | Delete
* $mode could be:
[322] Fix | Delete
*
[323] Fix | Delete
* - CRYPT_RC2_MODE_ECB
[324] Fix | Delete
*
[325] Fix | Delete
* - CRYPT_RC2_MODE_CBC
[326] Fix | Delete
*
[327] Fix | Delete
* - CRYPT_RC2_MODE_CTR
[328] Fix | Delete
*
[329] Fix | Delete
* - CRYPT_RC2_MODE_CFB
[330] Fix | Delete
*
[331] Fix | Delete
* - CRYPT_RC2_MODE_OFB
[332] Fix | Delete
*
[333] Fix | Delete
* If not explicitly set, CRYPT_RC2_MODE_CBC will be used.
[334] Fix | Delete
*
[335] Fix | Delete
* @see Crypt_Base::Crypt_Base()
[336] Fix | Delete
*
[337] Fix | Delete
* @param optional Integer $mode
[338] Fix | Delete
*
[339] Fix | Delete
* @access public
[340] Fix | Delete
*/
[341] Fix | Delete
public function __construct($mode = CRYPT_RC2_MODE_CBC)
[342] Fix | Delete
{
[343] Fix | Delete
parent::__construct($mode);
[344] Fix | Delete
$this->setKey('');
[345] Fix | Delete
}
[346] Fix | Delete
[347] Fix | Delete
/**
[348] Fix | Delete
* Sets the key length
[349] Fix | Delete
*
[350] Fix | Delete
* Valid key lengths are 1 to 1024.
[351] Fix | Delete
* Calling this function after setting the key has no effect until the next
[352] Fix | Delete
* Crypt_RC2::setKey() call.
[353] Fix | Delete
*
[354] Fix | Delete
* @access public
[355] Fix | Delete
*
[356] Fix | Delete
* @param Integer $length in bits
[357] Fix | Delete
*/
[358] Fix | Delete
public function setKeyLength($length)
[359] Fix | Delete
{
[360] Fix | Delete
if ($length >= 1 && $length <= 1024) {
[361] Fix | Delete
$this->default_key_length = $length;
[362] Fix | Delete
}
[363] Fix | Delete
}
[364] Fix | Delete
[365] Fix | Delete
/**
[366] Fix | Delete
* Sets the key.
[367] Fix | Delete
*
[368] Fix | Delete
* Keys can be of any length. RC2, itself, uses 1 to 1024 bit keys (eg.
[369] Fix | Delete
* strlen($key) <= 128), however, we only use the first 128 bytes if $key
[370] Fix | Delete
* has more then 128 bytes in it, and set $key to a single null byte if
[371] Fix | Delete
* it is empty.
[372] Fix | Delete
*
[373] Fix | Delete
* If the key is not explicitly set, it'll be assumed to be a single
[374] Fix | Delete
* null byte.
[375] Fix | Delete
*
[376] Fix | Delete
* @see Crypt_Base::setKey()
[377] Fix | Delete
* @access public
[378] Fix | Delete
*
[379] Fix | Delete
* @param String $key
[380] Fix | Delete
* @param Integer $t1 optional Effective key length in bits.
[381] Fix | Delete
*/
[382] Fix | Delete
public function setKey($key, $t1 = 0)
[383] Fix | Delete
{
[384] Fix | Delete
if ($t1 <= 0) {
[385] Fix | Delete
$t1 = $this->default_key_length;
[386] Fix | Delete
} elseif ($t1 > 1024) {
[387] Fix | Delete
$t1 = 1024;
[388] Fix | Delete
}
[389] Fix | Delete
// Key byte count should be 1..128.
[390] Fix | Delete
$key = strlen($key) ? substr($key, 0, 128) : "\x00";
[391] Fix | Delete
$t = strlen($key);
[392] Fix | Delete
[393] Fix | Delete
// The mcrypt RC2 implementation only supports effective key length
[394] Fix | Delete
// of 1024 bits. It is however possible to handle effective key
[395] Fix | Delete
// lengths in range 1..1024 by expanding the key and applying
[396] Fix | Delete
// inverse pitable mapping to the first byte before submitting it
[397] Fix | Delete
// to mcrypt.
[398] Fix | Delete
[399] Fix | Delete
// Key expansion.
[400] Fix | Delete
$l = array_values(unpack('C*', $key));
[401] Fix | Delete
$t8 = ($t1 + 7) >> 3;
[402] Fix | Delete
$tm = 0xFF >> (8 * $t8 - $t1);
[403] Fix | Delete
[404] Fix | Delete
// Expand key.
[405] Fix | Delete
$pitable = $this->pitable;
[406] Fix | Delete
for ($i = $t; $i < 128; $i++) {
[407] Fix | Delete
$l[$i] = $pitable[$l[$i - 1] + $l[$i - $t]];
[408] Fix | Delete
}
[409] Fix | Delete
$i = 128 - $t8;
[410] Fix | Delete
$l[$i] = $pitable[$l[$i] & $tm];
[411] Fix | Delete
while ($i--) {
[412] Fix | Delete
$l[$i] = $pitable[$l[$i + 1] ^ $l[$i + $t8]];
[413] Fix | Delete
}
[414] Fix | Delete
[415] Fix | Delete
// Prepare the key for mcrypt.
[416] Fix | Delete
$l[0] = $this->invpitable[$l[0]];
[417] Fix | Delete
array_unshift($l, 'C*');
[418] Fix | Delete
parent::setKey(call_user_func_array('pack', $l));
[419] Fix | Delete
}
[420] Fix | Delete
[421] Fix | Delete
/**
[422] Fix | Delete
* Encrypts a block
[423] Fix | Delete
*
[424] Fix | Delete
* @see Crypt_Base::_encryptBlock()
[425] Fix | Delete
* @see Crypt_Base::encrypt()
[426] Fix | Delete
* @access private
[427] Fix | Delete
*
[428] Fix | Delete
* @param String $in
[429] Fix | Delete
*
[430] Fix | Delete
* @return String
[431] Fix | Delete
*/
[432] Fix | Delete
public function _encryptBlock($in)
[433] Fix | Delete
{
[434] Fix | Delete
list($r0, $r1, $r2, $r3) = array_values(unpack('v*', $in));
[435] Fix | Delete
$keys = $this->keys;
[436] Fix | Delete
$limit = 20;
[437] Fix | Delete
$actions = array($limit => 44, 44 => 64);
[438] Fix | Delete
$j = 0;
[439] Fix | Delete
[440] Fix | Delete
for (;;) {
[441] Fix | Delete
// Mixing round.
[442] Fix | Delete
$r0 = (($r0 + $keys[$j++] + ((($r1 ^ $r2) & $r3) ^ $r1)) & 0xFFFF) << 1;
[443] Fix | Delete
$r0 |= $r0 >> 16;
[444] Fix | Delete
$r1 = (($r1 + $keys[$j++] + ((($r2 ^ $r3) & $r0) ^ $r2)) & 0xFFFF) << 2;
[445] Fix | Delete
$r1 |= $r1 >> 16;
[446] Fix | Delete
$r2 = (($r2 + $keys[$j++] + ((($r3 ^ $r0) & $r1) ^ $r3)) & 0xFFFF) << 3;
[447] Fix | Delete
$r2 |= $r2 >> 16;
[448] Fix | Delete
$r3 = (($r3 + $keys[$j++] + ((($r0 ^ $r1) & $r2) ^ $r0)) & 0xFFFF) << 5;
[449] Fix | Delete
$r3 |= $r3 >> 16;
[450] Fix | Delete
[451] Fix | Delete
if ($j === $limit) {
[452] Fix | Delete
if ($limit === 64) {
[453] Fix | Delete
break;
[454] Fix | Delete
}
[455] Fix | Delete
[456] Fix | Delete
// Mashing round.
[457] Fix | Delete
$r0 += $keys[$r3 & 0x3F];
[458] Fix | Delete
$r1 += $keys[$r0 & 0x3F];
[459] Fix | Delete
$r2 += $keys[$r1 & 0x3F];
[460] Fix | Delete
$r3 += $keys[$r2 & 0x3F];
[461] Fix | Delete
$limit = $actions[$limit];
[462] Fix | Delete
}
[463] Fix | Delete
}
[464] Fix | Delete
[465] Fix | Delete
return pack('vvvv', $r0, $r1, $r2, $r3);
[466] Fix | Delete
}
[467] Fix | Delete
[468] Fix | Delete
/**
[469] Fix | Delete
* Decrypts a block
[470] Fix | Delete
*
[471] Fix | Delete
* @see Crypt_Base::_decryptBlock()
[472] Fix | Delete
* @see Crypt_Base::decrypt()
[473] Fix | Delete
* @access private
[474] Fix | Delete
*
[475] Fix | Delete
* @param String $in
[476] Fix | Delete
*
[477] Fix | Delete
* @return String
[478] Fix | Delete
*/
[479] Fix | Delete
public function _decryptBlock($in)
[480] Fix | Delete
{
[481] Fix | Delete
list($r0, $r1, $r2, $r3) = array_values(unpack('v*', $in));
[482] Fix | Delete
$keys = $this->keys;
[483] Fix | Delete
$limit = 44;
[484] Fix | Delete
$actions = array($limit => 20, 20 => 0);
[485] Fix | Delete
$j = 64;
[486] Fix | Delete
[487] Fix | Delete
for (;;) {
[488] Fix | Delete
// R-mixing round.
[489] Fix | Delete
$r3 = ($r3 | ($r3 << 16)) >> 5;
[490] Fix | Delete
$r3 = ($r3 - $keys[--$j] - ((($r0 ^ $r1) & $r2) ^ $r0)) & 0xFFFF;
[491] Fix | Delete
$r2 = ($r2 | ($r2 << 16)) >> 3;
[492] Fix | Delete
$r2 = ($r2 - $keys[--$j] - ((($r3 ^ $r0) & $r1) ^ $r3)) & 0xFFFF;
[493] Fix | Delete
$r1 = ($r1 | ($r1 << 16)) >> 2;
[494] Fix | Delete
$r1 = ($r1 - $keys[--$j] - ((($r2 ^ $r3) & $r0) ^ $r2)) & 0xFFFF;
[495] Fix | Delete
$r0 = ($r0 | ($r0 << 16)) >> 1;
[496] Fix | Delete
$r0 = ($r0 - $keys[--$j] - ((($r1 ^ $r2) & $r3) ^ $r1)) & 0xFFFF;
[497] Fix | Delete
[498] Fix | Delete
if ($j === $limit) {
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function