8129567: CRYPTO_MECHANISM_PARAM_INVALID occurs if GCM mode parameter which is used as an IV is set to all zeros

Reviewed-by: mullan
This commit is contained in:
Bhanu Prakash Gopularam 2015-12-16 08:38:10 -08:00 committed by Artem Smotrakov
parent bc11b9c8b5
commit 739de56c11
2 changed files with 9 additions and 2 deletions

View File

@ -65,7 +65,10 @@ public class TestCICOWithGCMAndAAD extends UcryptoTest {
byte[] aad2 = aad.clone();
aad2[50]++;
GCMParameterSpec spec = new GCMParameterSpec(128, new byte[16]);
byte[] iv = new byte[16];
rdm.nextBytes(iv);
GCMParameterSpec spec = new GCMParameterSpec(128, iv);
Cipher encCipher = Cipher.getInstance("AES/GCM/NoPadding", p);
encCipher.init(Cipher.ENCRYPT_MODE, key, spec);
encCipher.updateAAD(aad);

View File

@ -126,7 +126,11 @@ public class TestGCMKeyAndIvCheck extends UcryptoTest {
}
// Now try to encrypt again using a different parameter; should work
c.init(Cipher.ENCRYPT_MODE, key, new GCMParameterSpec(128, new byte[30]));
byte[] rdm_iv = new byte[30];
Random rdm = new Random();
rdm.nextBytes(rdm_iv);
c.init(Cipher.ENCRYPT_MODE, key, new GCMParameterSpec(128, rdm_iv));
c.updateAAD(AAD);
c.doFinal(PT);
// subsequent encryption should fail unless re-init w/ different key+iv