private void runTestCase( GCMMultiplier encM, GCMMultiplier decM, String testName, byte[] K, byte[] IV, byte[] A, byte[] P, byte[] C, byte[] T) throws InvalidCipherTextException { byte[] fa = new byte[A.length / 2]; byte[] la = new byte[A.length - (A.length / 2)]; System.arraycopy(A, 0, fa, 0, fa.length); System.arraycopy(A, fa.length, la, 0, la.length); runTestCase(encM, decM, testName + " all initial associated data", K, IV, A, null, P, C, T); runTestCase(encM, decM, testName + " all subsequent associated data", K, IV, null, A, P, C, T); runTestCase(encM, decM, testName + " split associated data", K, IV, fa, la, P, C, T); }
private void runTestCase( GCMMultiplier encM, GCMMultiplier decM, String testName, byte[] K, byte[] IV, byte[] A, byte[] SA, byte[] P, byte[] C, byte[] T) throws InvalidCipherTextException { AEADParameters parameters = new AEADParameters(new KeyParameter(K), T.length * 8, IV, A); GCMBlockCipher encCipher = initCipher(encM, true, parameters); GCMBlockCipher decCipher = initCipher(decM, false, parameters); checkTestCase(encCipher, decCipher, testName, SA, P, C, T); checkTestCase(encCipher, decCipher, testName + " (reused)", SA, P, C, T); // Key reuse AEADParameters keyReuseParams = AEADTestUtil.reuseKey(parameters); encCipher.init(true, keyReuseParams); decCipher.init(false, keyReuseParams); checkTestCase(encCipher, decCipher, testName + " (key reuse)", SA, P, C, T); }
private void runTestCase( GCMMultiplier encM, GCMMultiplier decM, String testName, byte[] K, byte[] IV, byte[] A, byte[] SA, byte[] P, byte[] C, byte[] T) throws InvalidCipherTextException { AEADParameters parameters = new AEADParameters(new KeyParameter(K), T.length * 8, IV, A); GCMBlockCipher encCipher = initCipher(encM, true, parameters); GCMBlockCipher decCipher = initCipher(decM, false, parameters); checkTestCase(encCipher, decCipher, testName, SA, P, C, T); checkTestCase(encCipher, decCipher, testName + " (reused)", SA, P, C, T); // Key reuse AEADParameters keyReuseParams = new AEADParameters(null, parameters.getMacSize(), parameters.getNonce(), parameters.getAssociatedText()); encCipher.init(true, keyReuseParams); decCipher.init(false, keyReuseParams); checkTestCase(encCipher, decCipher, testName + " (key reuse)", SA, P, C, T); checkTestCase(encCipher, decCipher, testName + " (key reuse)", SA, P, C, T); }
private void randomTests(SecureRandom srng, GCMMultiplier m) throws InvalidCipherTextException { for (int i = 0; i < 10; ++i) { randomTest(srng, m); } }
private GCMBlockCipher initCipher(GCMMultiplier m, boolean forEncryption, AEADParameters parameters) { GCMBlockCipher c = new GCMBlockCipher(createAESEngine(), m); c.init(forEncryption, parameters); return c; }
private GCMBlockCipher initCipher(GCMMultiplier m, boolean forEncryption, AEADParameters parameters) { GCMBlockCipher c = new GCMBlockCipher(new AESFastEngine(), m); c.init(forEncryption, parameters); return c; }