@@ -962,6 +962,53 @@ public function test128ByteRC2Key()
962
962
}
963
963
}
964
964
965
+ public function testOFB ()
966
+ {
967
+ $ key = str_repeat ('x ' , 32 );
968
+ $ iv = str_repeat ('x ' , 32 );
969
+ $ plaintext = 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz ' ;
970
+ $ ciphertext = '3d49c7fab4f20c3cc2a54e5c0a22a4feceffb6fc758ee3800380614042c567731a35cf ' ;
971
+
972
+ $ td = phpseclib_mcrypt_module_open ('rijndael-256 ' , '' , 'ofb ' , '' );
973
+ phpseclib_mcrypt_generic_init ($ td , $ key , $ iv );
974
+ $ mcrypt = bin2hex (phpseclib_mcrypt_generic ($ td , $ plaintext ));
975
+
976
+ $ this ->assertEquals (
977
+ $ ciphertext ,
978
+ $ mcrypt
979
+ );
980
+
981
+ $ td = phpseclib_mcrypt_module_open ('rijndael-256 ' , '' , 'ofb ' , '' );
982
+ phpseclib_mcrypt_generic_init ($ td , $ key , $ iv );
983
+ $ mcrypt = bin2hex (phpseclib_mcrypt_generic ($ td , substr ($ plaintext , 0 , -1 )));
984
+ $ mcrypt .= bin2hex (phpseclib_mcrypt_generic ($ td , substr ($ plaintext , -1 )));
985
+
986
+ $ this ->assertEquals (
987
+ $ ciphertext ,
988
+ $ mcrypt
989
+ );
990
+
991
+ $ td = phpseclib_mcrypt_module_open ('rijndael-256 ' , '' , 'ofb ' , '' );
992
+ phpseclib_mcrypt_generic_init ($ td , $ key , $ iv );
993
+ $ reference = phpseclib_mdecrypt_generic ($ td , pack ('H* ' , $ ciphertext ));
994
+
995
+ $ this ->assertEquals (
996
+ $ plaintext ,
997
+ $ reference
998
+ );
999
+
1000
+ if (extension_loaded ('mcrypt ' )) {
1001
+ $ td = mcrypt_module_open ('rijndael-256 ' , '' , 'ofb ' , '' );
1002
+ mcrypt_generic_init ($ td , $ key , $ iv );
1003
+ $ mcrypt = bin2hex (mcrypt_generic ($ td , $ plaintext ));
1004
+
1005
+ $ this ->assertEquals (
1006
+ $ ciphertext ,
1007
+ $ mcrypt
1008
+ );
1009
+ }
1010
+ }
1011
+
965
1012
public function mcryptModuleNameProvider ()
966
1013
{
967
1014
return array (
@@ -997,6 +1044,7 @@ public function mcryptBlockModuleNameProvider()
997
1044
array ('ctr ' , true ),
998
1045
array ('ecb ' , true ),
999
1046
array ('cfb ' , true ),
1047
+ array ('ofb ' , true ),
1000
1048
array ('ncfb ' , true ),
1001
1049
array ('nofb ' , true ),
1002
1050
array ('invalid-mode ' , false )
0 commit comments