CryptoAnalysis
CryptoAnalysis copied to clipboard
OR-ing of 2 or 3 predicates only works for ENSURE section with non-conditional predicates
The below test case verifies the usage of GCMBlockCipher
with AEADParameters
OR ParametersWithIV
. But the test case is failing currently since the ENSURES section in GCMBlockCipher
has the conditional predicate generatedGCMBlockCipherMode[this] after Cons;
.
@Test
public void testORingTwoPredicates2() throws GeneralSecurityException, IllegalStateException, InvalidCipherTextException {
SecureRandom random = new SecureRandom();
byte[] genSeed = random.generateSeed(128);
KeyParameter keyParam = new KeyParameter(genSeed);
byte[] nonce = random.generateSeed(128);
AEADParameters aeadParam = new AEADParameters(keyParam, 128, nonce);
Assertions.hasEnsuredPredicate(aeadParam);
Assertions.mustBeInAcceptingState(aeadParam);
AESEngine engine = new AESEngine();
Assertions.hasEnsuredPredicate(engine);
byte[] input = new byte[100];
byte[] output = new byte[100];
GCMBlockCipher cipher1 = new GCMBlockCipher(engine);
cipher1.init(false, aeadParam);
cipher1.processAADBytes(input, 0, input.length);
cipher1.doFinal(output, 0);
Assertions.hasEnsuredPredicate(cipher1);
Assertions.mustBeInAcceptingState(cipher1);
ParametersWithIV ivParam = new ParametersWithIV(keyParam, genSeed);
Assertions.hasEnsuredPredicate(ivParam);
Assertions.mustBeInAcceptingState(ivParam);
GCMBlockCipher cipher2 = new GCMBlockCipher(engine);
cipher2.init(false, ivParam);
// cipher2.processAADBytes(input, 0, input.length);
// cipher2.doFinal(output, 0);
Assertions.hasEnsuredPredicate(cipher2);
Assertions.mustNotBeInAcceptingState(cipher2);
}
OUTPUT
Expected a predicate for cipher1 (BouncyCastlesUsagePatternTest.testORingTwoPredicates4) @ staticinvoke <test.assertions.Assertions: void hasEnsuredPredicate(java.lang.Object)>(cipher1)
Expected a predicate for cipher2 (BouncyCastlesUsagePatternTest.testORingTwoPredicates4) @ staticinvoke <test.assertions.Assertions: void hasEnsuredPredicate(java.lang.Object)>(cipher2)
However, when this conditional predicate is changed into normal predicate and the method calls in testORingTwoPredicates2
are modified as below, the test case passes. This verifies that the OR operator currently works for rules with non-conditional predicates in ENSURES section
...
GCMBlockCipher cipher2 = new GCMBlockCipher(engine);
cipher2.init(false, ivParam);
cipher2.processAADBytes(input, 0, input.length); // because now `generatedGCMBlockCipherMode` predicate is only generated after `Cons, init, process+, doFinal`
cipher2.doFinal(output, 0);
Assertions.hasEnsuredPredicate(cipher2);
Assertions.mustBeInAcceptingState(cipher2);
...
```
@kruegers I've added test cases for verifying OR-ing predicates in the pull request #214
The reason for the above behaviour was because the next method call i.e. init
from ORDER section is negating the ensured predicate generatedGCMBlockCipherMode
generated after constructor call of GCMBlockCipher
. However when the conditional predicate is changed to normal predicate namely generatedGCMBlockCipherMode[this];
then the corresponding predicate is only generated after last method call in ORDER section i.e. doFinal
. Since we have Assertions.hasEnsuredPredicate
immediately after this method call, both the assertions results to true.