Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8df2ea0

Browse filesBrowse files
committed
Merge branch '2.0'
2 parents 0233794 + 2365f83 commit 8df2ea0
Copy full SHA for 8df2ea0

File tree

2 files changed

+52
-1
lines changed
Filter options

2 files changed

+52
-1
lines changed

‎lib/mcrypt.php

Copy file name to clipboardExpand all lines: lib/mcrypt.php
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ function phpseclib_mcrypt_list_modes($lib_dir = '')
226226
'ecb',
227227
'ncfb',
228228
'nofb',
229-
//'ofb',
229+
'ofb',
230230
'stream'
231231
);
232232
}
@@ -273,6 +273,7 @@ function phpseclib_mcrypt_module_open($algorithm, $algorithm_directory, $mode, $
273273
'ecb' => 'ecb',
274274
'cbc' => 'cbc',
275275
'cfb' => 'cfb8',
276+
'ofb' => 'ofb8',
276277
'ncfb'=> 'cfb',
277278
'nofb'=> 'ofb',
278279
'stream' => 'stream'
@@ -571,6 +572,7 @@ function phpseclib_mcrypt_enc_get_modes_name(Base $td)
571572
case 'ofb';
572573
return 'n' . strtoupper($mode);
573574
case 'cfb8':
575+
case 'ofb8':
574576
return strtoupper(substr($mode, 0, 3));
575577
default:
576578
return strtoupper($mode);
@@ -847,6 +849,7 @@ function phpseclib_mcrypt_module_is_block_algorithm_mode($mode, $lib_dir = '')
847849
case 'ctr':
848850
case 'ecb':
849851
case 'cfb':
852+
case 'ofb':
850853
case 'ncfb':
851854
case 'nofb':
852855
return true;

‎tests/MCryptCompatTest.php

Copy file name to clipboardExpand all lines: tests/MCryptCompatTest.php
+48Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,53 @@ public function test128ByteRC2Key()
974974
}
975975
}
976976

977+
public function testOFB()
978+
{
979+
$key = str_repeat('x', 32);
980+
$iv = str_repeat('x', 32);
981+
$plaintext = 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz';
982+
$ciphertext = '3d49c7fab4f20c3cc2a54e5c0a22a4feceffb6fc758ee3800380614042c567731a35cf';
983+
984+
$td = phpseclib_mcrypt_module_open('rijndael-256', '', 'ofb', '');
985+
phpseclib_mcrypt_generic_init($td, $key, $iv);
986+
$mcrypt = bin2hex(phpseclib_mcrypt_generic($td, $plaintext));
987+
988+
$this->assertEquals(
989+
$ciphertext,
990+
$mcrypt
991+
);
992+
993+
$td = phpseclib_mcrypt_module_open('rijndael-256', '', 'ofb', '');
994+
phpseclib_mcrypt_generic_init($td, $key, $iv);
995+
$mcrypt = bin2hex(phpseclib_mcrypt_generic($td, substr($plaintext, 0, -1)));
996+
$mcrypt.= bin2hex(phpseclib_mcrypt_generic($td, substr($plaintext, -1)));
997+
998+
$this->assertEquals(
999+
$ciphertext,
1000+
$mcrypt
1001+
);
1002+
1003+
$td = phpseclib_mcrypt_module_open('rijndael-256', '', 'ofb', '');
1004+
phpseclib_mcrypt_generic_init($td, $key, $iv);
1005+
$reference = phpseclib_mdecrypt_generic($td, pack('H*', $ciphertext));
1006+
1007+
$this->assertEquals(
1008+
$plaintext,
1009+
$reference
1010+
);
1011+
1012+
if (extension_loaded('mcrypt')) {
1013+
$td = mcrypt_module_open('rijndael-256', '', 'ofb', '');
1014+
mcrypt_generic_init($td, $key, $iv);
1015+
$mcrypt = bin2hex(mcrypt_generic($td, $plaintext));
1016+
1017+
$this->assertEquals(
1018+
$ciphertext,
1019+
$mcrypt
1020+
);
1021+
}
1022+
}
1023+
9771024
public function mcryptModuleNameProvider()
9781025
{
9791026
return array(
@@ -1009,6 +1056,7 @@ public function mcryptBlockModuleNameProvider()
10091056
array('ctr', true),
10101057
array('ecb', true),
10111058
array('cfb', true),
1059+
array('ofb', true),
10121060
array('ncfb', true),
10131061
array('nofb', true),
10141062
array('invalid-mode', false)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.