Skip to content

Commit 35349ab

Browse files
committed
added extra doFinal test (relates to github #2035)
1 parent 316c2a4 commit 35349ab

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

prov/src/test/java/org/bouncycastle/jce/provider/test/BlockCipherTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.io.ObjectInputStream;
88
import java.io.ObjectOutputStream;
99
import java.security.AlgorithmParameters;
10+
import java.security.GeneralSecurityException;
1011
import java.security.InvalidAlgorithmParameterException;
1112
import java.security.InvalidKeyException;
1213
import java.security.InvalidParameterException;
@@ -1738,6 +1739,29 @@ public void performTest()
17381739

17391740
testExceptions();
17401741
testIncorrectCipherModes();
1742+
doFinalTest();
1743+
}
1744+
1745+
private void doFinalTest()
1746+
{
1747+
try
1748+
{
1749+
int INPUT_LENGTH = 32;
1750+
int offset = 1;
1751+
byte[] PT = new byte[INPUT_LENGTH + offset];
1752+
SecretKey KEY = new SecretKeySpec(new byte[16], "AES");
1753+
Cipher c = Cipher.getInstance("AES/ECB/NoPadding", "BC");
1754+
c.init(Cipher.ENCRYPT_MODE, KEY);
1755+
int len = c.doFinal(PT, 0, INPUT_LENGTH, PT, offset);
1756+
1757+
byte[] expected = Hex.decode("0066e94bd4ef8a2c3b884cfa59ca342b2e66e94bd4ef8a2c3b884cfa59ca342b2e");
1758+
1759+
isTrue("expected not match PT", areEqual(expected, PT));
1760+
}
1761+
catch (GeneralSecurityException e)
1762+
{
1763+
fail(e.toString());
1764+
}
17411765
}
17421766

17431767
public static void main(

0 commit comments

Comments
 (0)