@@ -974,6 +974,53 @@ public function test128ByteRC2Key()
974
974
}
975
975
}
976
976
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
+
977
1024
public function mcryptModuleNameProvider ()
978
1025
{
979
1026
return array (
@@ -1009,6 +1056,7 @@ public function mcryptBlockModuleNameProvider()
1009
1056
array ('ctr ' , true ),
1010
1057
array ('ecb ' , true ),
1011
1058
array ('cfb ' , true ),
1059
+ array ('ofb ' , true ),
1012
1060
array ('ncfb ' , true ),
1013
1061
array ('nofb ' , true ),
1014
1062
array ('invalid-mode ' , false )
0 commit comments