Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	pom.xml
  • Loading branch information
overheadhunter committed Feb 9, 2021
2 parents cc96bd6 + b684321 commit 2890ab7
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;
Expand All @@ -29,7 +30,7 @@
public class FileHeaderCryptorImplTest {

private static final SecureRandom RANDOM_MOCK = SecureRandomMock.NULL_RANDOM;
private static final SecureRandom ANTI_REUSE_PRNG = SecureRandomMock.cycle((byte) 0x13, (byte) 0x37);
private static final SecureRandom ANTI_REUSE_PRNG = SecureRandomMock.PRNG_RANDOM;

private FileHeaderCryptorImpl headerCryptor;

Expand All @@ -38,10 +39,12 @@ public void setup() {
SecretKey encKey = new SecretKeySpec(new byte[32], "AES");
headerCryptor = new FileHeaderCryptorImpl(encKey, RANDOM_MOCK);

// init cipher with distinct IV to avoid cipher-internal anti-reuse checking
// create new (unused) cipher, just to cipher.init() internally. This is an attempt to avoid
// InvalidAlgorithmParameterExceptions due to IV-reuse, when the actual unit tests use constant IVs
byte[] nonce = new byte[GCM_NONCE_SIZE];
ANTI_REUSE_PRNG.nextBytes(nonce);
CipherSupplier.AES_GCM.forEncryption(encKey, new GCMParameterSpec(GCM_TAG_SIZE * Byte.SIZE, nonce));
Cipher cipher = CipherSupplier.AES_GCM.forEncryption(encKey, new GCMParameterSpec(GCM_TAG_SIZE * Byte.SIZE, nonce));
Assertions.assertNotNull(cipher);
}

@Test
Expand Down

0 comments on commit 2890ab7

Please sign in to comment.