private void runTestCase(String[] testVector, int macLength) throws InvalidCipherTextException { int pos = 0; String testName = testVector[pos++]; byte[] K = Hex.decode(testVector[pos++]); byte[] P = Hex.decode(testVector[pos++]); byte[] A = Hex.decode(testVector[pos++]); byte[] IV = Hex.decode(testVector[pos++]); byte[] C = Hex.decode(testVector[pos++]); // For short MAC, take leading bytes byte[] t = Hex.decode(testVector[pos++]); byte[] T = new byte[macLength]; System.arraycopy(t, 0, T, 0, T.length); // Default multiplier runTestCase(null, null, testName, K, IV, A, P, C, T); runTestCase(new BasicGCMMultiplier(), new BasicGCMMultiplier(), testName, K, IV, A, P, C, T); runTestCase(new Tables8kGCMMultiplier(), new Tables8kGCMMultiplier(), testName, K, IV, A, P, C, T); runTestCase(new Tables64kGCMMultiplier(), new Tables64kGCMMultiplier(), testName, K, IV, A, P, C, T); }
private void randomTests() throws InvalidCipherTextException { SecureRandom srng = new SecureRandom(); srng.setSeed(Times.nanoTime()); randomTests(srng, null); randomTests(srng, new BasicGCMMultiplier()); randomTests(srng, new Tables8kGCMMultiplier()); randomTests(srng, new Tables64kGCMMultiplier()); }
private void randomTests() throws InvalidCipherTextException { SecureRandom srng = new SecureRandom(); for (int i = 0; i < 10; ++i) { randomTest(srng, null); randomTest(srng, new BasicGCMMultiplier()); randomTest(srng, new Tables8kGCMMultiplier()); randomTest(srng, new Tables64kGCMMultiplier()); } }
private void outputSizeTests() { byte[] K = new byte[16]; byte[] A = null; byte[] IV = new byte[16]; GCMBlockCipher cipher = new GCMBlockCipher(new AESFastEngine(), new BasicGCMMultiplier()); AEADParameters parameters = new AEADParameters(new KeyParameter(K), 16 * 8, IV, A); cipher.init(true, parameters); if (cipher.getUpdateOutputSize(0) != 0) { fail("incorrect getUpdateOutputSize for initial 0 bytes encryption"); } if (cipher.getOutputSize(0) != 16) { fail("incorrect getOutputSize for initial 0 bytes encryption"); } cipher.init(false, parameters); if (cipher.getUpdateOutputSize(0) != 0) { fail("incorrect getUpdateOutputSize for initial 0 bytes decryption"); } // NOTE: 0 bytes would be truncated data, but we want it to fail in the doFinal, not here if (cipher.getOutputSize(0) != 0) { fail("fragile getOutputSize for initial 0 bytes decryption"); } if (cipher.getOutputSize(16) != 0) { fail("incorrect getOutputSize for initial MAC-size bytes decryption"); } }