PluginProbe
Contact Forms by Cimatti / 2.2.4
Contact Forms by Cimatti v2.2.4
2.3.6 2.3.5 2.3.0 2.2.32 2.2.4 2.2.0 2.1.2 2.1.1 trunk 1.0 1.1 1.2 1.2.1 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 All 62 releases
contact-forms / phpseclib-crypt / AES.php

AES.php in Contact Forms by Cimatti 2.2.4, at phpseclib-crypt/AES.php

205 lines 6.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * phpseclib AES - Third-party library
4 * @package phpseclib
5 */
6 if ( ! defined( 'ABSPATH' ) ) exit;
7
8 // phpcs:disable WordPress.Security.EscapeOutput, WordPress.NamingConventions.PrefixAllGlobals, Generic.PHP.ForbiddenFunctions, WordPress.PHP.DevelopmentFunctions, WordPress.WP.AlternativeFunctions -- Third-party cryptographic library
9
10 /**
11 * Pure-PHP implementation of AES.
12 *
13 * Uses mcrypt, if available/possible, and an internal implementation, otherwise.
14 *
15 * PHP versions 4 and 5
16 *
17 * NOTE: Since AES.php is (for compatibility and phpseclib-historical reasons) virtually
18 * just a wrapper to Rijndael.php you may consider using Rijndael.php instead of
19 * to save one include_once().
20 *
21 * If {@link self::setKeyLength() setKeyLength()} isn't called, it'll be calculated from
22 * {@link self::setKey() setKey()}. ie. if the key is 128-bits, the key length will be 128-bits. If it's 136-bits
23 * it'll be null-padded to 192-bits and 192 bits will be the key length until {@link self::setKey() setKey()}
24 * is called, again, at which point, it'll be recalculated.
25 *
26 * Since Crypt_AES extends Crypt_Rijndael, some functions are available to be called that, in the context of AES, don't
27 * make a whole lot of sense. {@link self::setBlockLength() setBlockLength()}, for instance. Calling that function,
28 * however possible, won't do anything (AES has a fixed block length whereas Rijndael has a variable one).
29 *
30 * Here's a short example of how to use this library:
31 * <code>
32 * <?php
33 * include 'Crypt/AES.php';
34 *
35 * $aes = new Crypt_AES();
36 *
37 * $aes->setKey('abcdefghijklmnop');
38 *
39 * $size = 10 * 1024;
40 * $plaintext = '';
41 * for ($i = 0; $i < $size; $i++) {
42 * $plaintext.= 'a';
43 * }
44 *
45 * echo $aes->decrypt($aes->encrypt($plaintext));
46 * ?>
47 * </code>
48 *
49 * LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
50 * of this software and associated documentation files (the "Software"), to deal
51 * in the Software without restriction, including without limitation the rights
52 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
53 * copies of the Software, and to permit persons to whom the Software is
54 * furnished to do so, subject to the following conditions:
55 *
56 * The above copyright notice and this permission notice shall be included in
57 * all copies or substantial portions of the Software.
58 *
59 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
60 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
61 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
62 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
63 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
64 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
65 * THE SOFTWARE.
66 *
67 * @category Crypt
68 * @package Crypt_AES
69 * @author Jim Wigginton <terrafrost@php.net>
70 * @copyright 2008 Jim Wigginton
71 * @license http://www.opensource.org/licenses/mit-license.html MIT License
72 * @link http://phpseclib.sourceforge.net
73 */
74
75 /**
76 * Include Crypt_Rijndael
77 */
78 if (!class_exists('Crypt_Rijndael')) {
79 include_once 'Rijndael.php';
80 }
81
82 /**#@+
83 * @access public
84 * @see self::encrypt()
85 * @see self::decrypt()
86 */
87 /**
88 * Encrypt / decrypt using the Counter mode.
89 *
90 * Set to -1 since that's what Crypt/Random.php uses to index the CTR mode.
91 *
92 * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29
93 */
94 define('CRYPT_AES_MODE_CTR', CRYPT_MODE_CTR);
95 /**
96 * Encrypt / decrypt using the Electronic Code Book mode.
97 *
98 * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
99 */
100 define('CRYPT_AES_MODE_ECB', CRYPT_MODE_ECB);
101 /**
102 * Encrypt / decrypt using the Code Book Chaining mode.
103 *
104 * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29
105 */
106 define('CRYPT_AES_MODE_CBC', CRYPT_MODE_CBC);
107 /**
108 * Encrypt / decrypt using the Cipher Feedback mode.
109 *
110 * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher_feedback_.28CFB.29
111 */
112 define('CRYPT_AES_MODE_CFB', CRYPT_MODE_CFB);
113 /**
114 * Encrypt / decrypt using the Cipher Feedback mode.
115 *
116 * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Output_feedback_.28OFB.29
117 */
118 define('CRYPT_AES_MODE_OFB', CRYPT_MODE_OFB);
119 /**#@-*/
120
121 /**
122 * Pure-PHP implementation of AES.
123 *
124 * @package Crypt_AES
125 * @author Jim Wigginton <terrafrost@php.net>
126 * @access public
127 */
128 class Crypt_AES extends Crypt_Rijndael
129 {
130 /**
131 * The namespace used by the cipher for its constants.
132 *
133 * @see Crypt_Base::const_namespace
134 * @var string
135 * @access private
136 */
137 var $const_namespace = 'AES';
138
139 /**
140 * Dummy function
141 *
142 * Since Crypt_AES extends Crypt_Rijndael, this function is, technically, available, but it doesn't do anything.
143 *
144 * @see Crypt_Rijndael::setBlockLength()
145 * @access public
146 * @param int $length
147 */
148 function setBlockLength($length)
149 {
150 return;
151 }
152
153 /**
154 * Sets the key length
155 *
156 * Valid key lengths are 128, 192, and 256. If the length is less than 128, it will be rounded up to
157 * 128. If the length is greater than 128 and invalid, it will be rounded down to the closest valid amount.
158 *
159 * @see Crypt_Rijndael:setKeyLength()
160 * @access public
161 * @param int $length
162 */
163 function setKeyLength($length)
164 {
165 switch ($length) {
166 case 160:
167 $length = 192;
168 break;
169 case 224:
170 $length = 256;
171 }
172 parent::setKeyLength($length);
173 }
174
175 /**
176 * Sets the key.
177 *
178 * Rijndael supports five different key lengths, AES only supports three.
179 *
180 * @see Crypt_Rijndael:setKey()
181 * @see setKeyLength()
182 * @access public
183 * @param string $key
184 */
185 function setKey($key)
186 {
187 parent::setKey($key);
188
189 if (!$this->explicit_key_length) {
190 $length = strlen($key);
191 switch (true) {
192 case $length <= 16:
193 $this->key_length = 16;
194 break;
195 case $length <= 24:
196 $this->key_length = 24;
197 break;
198 default:
199 $this->key_length = 32;
200 }
201 $this->_setEngine();
202 }
203 }
204 }
205