private void Grain128Test1(CipherParameters params) { StreamCipher grain = new Grain128Engine(); byte[] in = new byte[16]; byte[] out = new byte[16]; grain.init(true, params); grain.processBytes(in, 0, in.length, out, 0); if (!areEqual(out, Hex.decode(keyStream1))) { mismatch("Keystream 1", keyStream1, out); } grain.reset(); grain.processBytes(in, 0, in.length, out, 0); if (!areEqual(out, Hex.decode(keyStream1))) { mismatch("Keystream 1", keyStream1, out); } }
private void Grain128Test2(CipherParameters params) { StreamCipher grain = new Grain128Engine(); byte[] in = new byte[16]; byte[] out = new byte[16]; grain.init(true, params); grain.processBytes(in, 0, in.length, out, 0); if (!areEqual(out, Hex.decode(keyStream2))) { mismatch("Keystream 2", keyStream2, out); } grain.reset(); grain.processBytes(in, 0, in.length, out, 0); if (!areEqual(out, Hex.decode(keyStream2))) { mismatch("Keystream 2", keyStream2, out); } }
private void Grain128Test3(CipherParameters params) { StreamCipher grain = new Grain128Engine(); byte[] in = "Encrypt me!".getBytes(); byte[] cipher = new byte[in.length]; byte[] clear = new byte[in.length]; grain.init(true, params); grain.processBytes(in, 0, in.length, cipher, 0); grain.reset(); grain.processBytes(cipher, 0, cipher.length, clear, 0); if (!areEqual(in, clear)) { mismatch("Test 3", new String(Hex.encode(in)), clear); } }
public void performTest() throws Exception { testReset(new Salsa20Engine(), new Salsa20Engine(), new ParametersWithIV(new KeyParameter(random(32)), random(8))); testReset(new Salsa20Engine(), new Salsa20Engine(), new ParametersWithIV(new KeyParameter(random(16)), random(8))); testReset(new XSalsa20Engine(), new XSalsa20Engine(), new ParametersWithIV(new KeyParameter(random(32)), random(24))); testReset(new ChaChaEngine(), new ChaChaEngine(), new ParametersWithIV(new KeyParameter(random(32)), random(8))); testReset(new ChaChaEngine(), new ChaChaEngine(), new ParametersWithIV(new KeyParameter(random(16)), random(8))); testReset(new RC4Engine(), new RC4Engine(), new KeyParameter(random(16))); testReset(new ISAACEngine(), new ISAACEngine(), new KeyParameter(random(16))); testReset(new HC128Engine(), new HC128Engine(), new ParametersWithIV(new KeyParameter(random(16)), random(16))); testReset(new HC256Engine(), new HC256Engine(), new ParametersWithIV(new KeyParameter(random(16)), random(16))); testReset(new Grainv1Engine(), new Grainv1Engine(), new ParametersWithIV(new KeyParameter(random(16)), random(8))); testReset(new Grain128Engine(), new Grain128Engine(), new ParametersWithIV(new KeyParameter(random(16)), random(12))); }
@Override public int getIVSize() { if (ivSize < 0) { if (delegate instanceof Grainv1Engine) ivSize = 8; else if (delegate instanceof Grain128Engine) ivSize = 12; else if (delegate instanceof HC128Engine) ivSize = 16; else if (delegate instanceof HC256Engine) ivSize = 32; else if (delegate instanceof ISAACEngine) ivSize = 0; else if (delegate instanceof RC4Engine) ivSize = 0; else if (delegate instanceof Salsa20Engine) ivSize = 8; else throw new UnsupportedOperationException("For this delegate cipher type, this operation is not yet supported!"); } return ivSize; }
private void performTests() throws Exception { testModes(new BlowfishEngine(), new BlowfishEngine(), 16); testModes(new DESEngine(), new DESEngine(), 8); testModes(new DESedeEngine(), new DESedeEngine(), 24); testModes(new TEAEngine(), new TEAEngine(), 16); testModes(new CAST5Engine(), new CAST5Engine(), 16); testModes(new RC2Engine(), new RC2Engine(), 16); testModes(new XTEAEngine(), new XTEAEngine(), 16); testModes(new AESEngine(), new AESEngine(), 16); testModes(new NoekeonEngine(), new NoekeonEngine(), 16); testModes(new TwofishEngine(), new TwofishEngine(), 16); testModes(new CAST6Engine(), new CAST6Engine(), 16); testModes(new SEEDEngine(), new SEEDEngine(), 16); testModes(new SerpentEngine(), new SerpentEngine(), 16); testModes(new RC6Engine(), new RC6Engine(), 16); testModes(new CamelliaEngine(), new CamelliaEngine(), 16); testModes(new ThreefishEngine(ThreefishEngine.BLOCKSIZE_512), new ThreefishEngine(ThreefishEngine.BLOCKSIZE_512), 64); testMode(new RC4Engine(), new KeyParameter(new byte[16])); testMode(new Salsa20Engine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[8])); testMode(new XSalsa20Engine(), new ParametersWithIV(new KeyParameter(new byte[32]), new byte[24])); testMode(new ChaChaEngine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[8])); testMode(new Grainv1Engine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[8])); testMode(new Grain128Engine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[12])); testMode(new HC128Engine(), new KeyParameter(new byte[16])); testMode(new HC256Engine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[16])); testSkipping(new Salsa20Engine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[8])); testSkipping(new SICBlockCipher(new AESEngine()), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[16])); }
public Base() { super(new Grain128Engine(), 12); }