1
1
<?php
2
+
2
3
/**
3
4
* mcrypt polyfill
4
5
*
@@ -311,6 +312,99 @@ function phpseclib_mcrypt_enc_get_key_size(Base $td)
311
312
return $ backup ->getKeyLength () >> 3 ;
312
313
}
313
314
315
+ /**
316
+ * Gets the name of the specified cipher
317
+ *
318
+ * @param string $cipher
319
+ * @return mixed
320
+ * @access public
321
+ */
322
+ function phpseclib_mcrypt_get_cipher_name ($ cipher )
323
+ {
324
+ switch ($ cipher ) {
325
+ case 'rijndael-128 ' :
326
+ return 'Rijndael-128 ' ;
327
+ case 'twofish ' :
328
+ return 'Twofish ' ;
329
+ case 'rijndael-192 ' :
330
+ return 'Rijndael-192 ' ;
331
+ case 'des ' :
332
+ return 'DES ' ;
333
+ case 'rijndael-256 ' :
334
+ return 'Rijndael-256 ' ;
335
+ case 'blowfish ' :
336
+ return 'Blowfish ' ;
337
+ case 'rc2 ' :
338
+ return 'RC2 ' ;
339
+ case 'tripledes ' :
340
+ return '3DES ' ;
341
+ case 'arcfour ' :
342
+ return 'RC4 ' ;
343
+ default :
344
+ return false ;
345
+ }
346
+ }
347
+
348
+ /**
349
+ * Gets the block size of the specified cipher
350
+ *
351
+ * @param string $cipher
352
+ * @param string $mode optional
353
+ * @return int
354
+ * @access public
355
+ */
356
+ function phpseclib_mcrypt_get_block_size ($ cipher , $ mode = false )
357
+ {
358
+ if (!$ mode ) {
359
+ $ mode = $ cipher == 'rc4 ' ? 'stream ' : 'cbc ' ;
360
+ }
361
+ $ td = @phpseclib_mcrypt_module_open ($ cipher , '' , $ mode , '' );
362
+ if ($ td === false ) {
363
+ trigger_error ('mcrypt_get_block_size(): Module initialization failed ' , E_USER_WARNING );
364
+ return false ;
365
+ }
366
+ return phpseclib_mcrypt_enc_get_block_size ($ td );
367
+ }
368
+
369
+ /**
370
+ * Gets the key size of the specified cipher
371
+ *
372
+ * @param string $cipher
373
+ * @param string $mode optional
374
+ * @return int
375
+ * @access public
376
+ */
377
+ function phpseclib_mcrypt_get_key_size ($ cipher , $ mode = false )
378
+ {
379
+ if (!$ mode ) {
380
+ $ mode = $ cipher == 'rc4 ' ? 'stream ' : 'cbc ' ;
381
+ }
382
+ $ td = @phpseclib_mcrypt_module_open ($ cipher , '' , $ mode , '' );
383
+ if ($ td === false ) {
384
+ trigger_error ('mcrypt_get_key_size(): Module initialization failed ' , E_USER_WARNING );
385
+ return false ;
386
+ }
387
+ return phpseclib_mcrypt_enc_get_key_size ($ td );
388
+ }
389
+
390
+ /**
391
+ * Returns the size of the IV belonging to a specific cipher/mode combination
392
+ *
393
+ * @param string $cipher
394
+ * @param string $mode
395
+ * @return int
396
+ * @access public
397
+ */
398
+ function phpseclib_mcrypt_get_iv_size ($ cipher , $ mode )
399
+ {
400
+ $ td = @phpseclib_mcrypt_module_open ($ cipher , '' , $ mode , '' );
401
+ if ($ td === false ) {
402
+ trigger_error ('mcrypt_get_iv_size(): Module initialization failed ' , E_USER_WARNING );
403
+ return false ;
404
+ }
405
+ return phpseclib_mcrypt_enc_get_iv_size ($ td );
406
+ }
407
+
314
408
/**
315
409
* Returns the maximum supported keysize of the opened mode
316
410
*
@@ -325,6 +419,10 @@ function phpseclib_mcrypt_module_get_algo_key_size($algorithm, $lib_dir = '')
325
419
{
326
420
$ mode = $ algorithm == 'rc4 ' ? 'stream ' : 'cbc ' ;
327
421
$ td = @phpseclib_mcrypt_module_open ($ algorithm , '' , $ mode , '' );
422
+ if ($ td === false ) {
423
+ trigger_error ('mcrypt_module_get_algo_key_size(): Module initialization failed ' , E_USER_WARNING );
424
+ return false ;
425
+ }
328
426
return phpseclib_mcrypt_enc_get_key_size ($ td );
329
427
}
330
428
@@ -669,7 +767,6 @@ function phpseclib_mcrypt_module_get_supported_key_sizes($algorithm, $lib_dir =
669
767
return array (24 );
670
768
//case 'arcfour':
671
769
//case 'blowfish':
672
- //case 'blowfish-compat':
673
770
//case 'rc2':
674
771
default :
675
772
return array ();
@@ -730,7 +827,6 @@ function phpseclib_mcrypt_module_is_block_algorithm($algorithm, $lib_dir = '')
730
827
case 'rijndael-128 ' :
731
828
case 'twofish ' :
732
829
case 'rijndael-192 ' :
733
- case 'blowfish-compat ' :
734
830
case 'des ' :
735
831
case 'rijndael-256 ' :
736
832
case 'blowfish ' :
@@ -1119,6 +1215,26 @@ function mcrypt_module_get_algo_block_size($algorithm, $lib_dir = '')
1119
1215
return phpseclib_mcrypt_module_get_algo_block_size ($ algorithm , $ lib_dir );
1120
1216
}
1121
1217
1218
+ function mcrypt_get_block_size ($ cipher , $ mode = '' )
1219
+ {
1220
+ return phpseclib_mcrypt_get_block_size ($ cipher , $ mode );
1221
+ }
1222
+
1223
+ function mcrypt_get_cipher_name ($ cipher )
1224
+ {
1225
+ return phpseclib_mcrypt_get_cipher_name ($ cipher );
1226
+ }
1227
+
1228
+ function mcrypt_get_key_size ($ cipher , $ mode = false )
1229
+ {
1230
+ return phpseclib_mcrypt_get_key_size ($ cipher , $ mode );
1231
+ }
1232
+
1233
+ function mcrypt_get_iv_size ($ cipher , $ mode )
1234
+ {
1235
+ return phpseclib_mcrypt_get_iv_size ($ cipher , $ mode );
1236
+ }
1237
+
1122
1238
function mcrypt_module_get_algo_key_size ($ algorithm , $ lib_dir = '' )
1123
1239
{
1124
1240
return phpseclib_mcrypt_module_get_algo_key_size ($ algorithm , $ lib_dir );
0 commit comments