@@ -1802,6 +1802,7 @@ public void performTest()
18021802 doFinalTest ();
18031803 testOverlapping ();
18041804 testOverlapping2 ();
1805+ testOverlap ();
18051806 }
18061807
18071808 private void doFinalTest ()
@@ -1896,6 +1897,63 @@ private void testOverlapping2()
18961897 }
18971898 }
18981899
1900+ public void testOverlap ()
1901+ {
1902+ try
1903+ {
1904+ int l = 32 ;
1905+ byte [] msg = new byte [l ];
1906+ Arrays .fill (msg , (byte )1 );
1907+
1908+ byte [] workingArray = new byte [l * 2 ];
1909+ Arrays .fill (workingArray , (byte )1 );
1910+ System .arraycopy (msg , 0 , workingArray , 0 , msg .length );
1911+
1912+ byte [] originalWorkingArray = new byte [workingArray .length ];
1913+ System .arraycopy (workingArray , 0 , originalWorkingArray , 0 , workingArray .length );
1914+
1915+ Cipher javaEncrypt = Cipher .getInstance ("AES/ECB/NoPadding" , BouncyCastleProvider .PROVIDER_NAME );
1916+ javaEncrypt .init (Cipher .ENCRYPT_MODE , new SecretKeySpec (new byte [16 ], "AES" ));
1917+
1918+ //
1919+ // Expected encryption
1920+ //
1921+ byte [] expectedOutput = new byte [msg .length ];
1922+ javaEncrypt .doFinal (msg , 0 , msg .length , expectedOutput , 0 );
1923+
1924+
1925+ //
1926+ // We expect to see the "expectedOutput" being written at each offset.
1927+ //
1928+ for (int outputOffset = 0 ; outputOffset < msg .length ; outputOffset ++)
1929+ {
1930+ javaEncrypt .doFinal (workingArray , 0 , msg .length , workingArray , outputOffset );
1931+
1932+ // Grab a copy of the produced cipher text
1933+ byte [] ct = Arrays .copyOfRange (workingArray , outputOffset , outputOffset + msg .length );
1934+ System .out .println ("\n Output Offset: " + outputOffset );
1935+ System .out .println ("Expected: " + pad (outputOffset * 2 ) + Hex .toHexString (expectedOutput ));
1936+ System .out .println ("Actual : " + Hex .toHexString (workingArray ));
1937+
1938+ isTrue (Arrays .areEqual (ct , expectedOutput ));
1939+
1940+ System .arraycopy (originalWorkingArray , 0 , workingArray , 0 , originalWorkingArray .length );
1941+ }
1942+ }
1943+ catch (Exception e )
1944+ {
1945+ fail (e .getMessage (), e );
1946+ }
1947+
1948+ }
1949+
1950+ public String pad (int len )
1951+ {
1952+ char [] buf = new char [len ];
1953+ Arrays .fill (buf , ' ' );
1954+ return new String (buf );
1955+ }
1956+
18991957 public static void main (
19001958 String [] args )
19011959 {
0 commit comments