Skip to content

Commit

Permalink
Merge pull request #29 from canonical/iv-size-aes
Browse files Browse the repository at this point in the history
tests: Use IV of size 16 bytes in CipherTests
  • Loading branch information
pushkarnk authored Aug 13, 2024
2 parents 229daeb + 02f2615 commit 50e3ae0
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions src/test/java/CipherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@
import static org.junit.Assert.assertArrayEquals;

public class CipherTest {
List<String> flakyTests = List.of(
"AES192/GCM/ISO10126_2",
"AES128/GCM/PKCS7",
"AES256/CTR/NONE",
"AES128/CBC/NONE",
"AES128/CBC/PKCS5",
"AES128/CTR/PKCS5",
"AES128/CFB1/X9_23"
);

String [] paddings = {
"NONE",
Expand Down Expand Up @@ -130,7 +121,7 @@ private void runTestMultipleUpdates(String nameKeySizeAndMode, String padding) t

sr.nextBytes(key);

byte[] iv = new byte[8];
byte[] iv = new byte[16];
sr.nextBytes(iv);

byte[] input = new byte[16];
Expand Down Expand Up @@ -159,8 +150,6 @@ private void runTestMultipleUpdates(String nameKeySizeAndMode, String padding) t
decipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key, "AES"), spec, sr);
byte[] output = decipher.doFinal(fullEnc, 0, encLen);

if (flakyTests.contains(cipherName))
return;
assertArrayEquals("Multi-update cipher test for " + cipherName + " failed", fullInput, output);
}

Expand All @@ -183,7 +172,7 @@ private void runTestSingleUpdate(String nameKeySizeAndMode, String padding) thro

sr.nextBytes(key);

byte[] iv = new byte[8];
byte[] iv = new byte[16];
sr.nextBytes(iv);

AlgorithmParameterSpec spec = new IvParameterSpec(iv);
Expand All @@ -200,9 +189,6 @@ private void runTestSingleUpdate(String nameKeySizeAndMode, String padding) thro
decipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key, "AES"), spec, sr);
byte[] output = decipher.doFinal(outFinal, 0, outFinal.length);

if (flakyTests.contains(cipherName)) {
return;
}
assertArrayEquals("Single update cipher test for " + cipherName + " failed", input, output);
}

Expand Down

0 comments on commit 50e3ae0

Please sign in to comment.