public FrameCodec(EncryptionHandshake.Secrets secrets) { this.mac = secrets.mac; BlockCipher cipher; enc = new SICBlockCipher(cipher = new AESEngine()); enc.init(true, new ParametersWithIV(new KeyParameter(secrets.aes), new byte[cipher.getBlockSize()])); dec = new SICBlockCipher(cipher = new AESEngine()); dec.init(false, new ParametersWithIV(new KeyParameter(secrets.aes), new byte[cipher.getBlockSize()])); egressMac = secrets.egressMac; ingressMac = secrets.ingressMac; }
protected void updateIV(StreamCipher cipher, boolean forEncryption, long seqNo) { byte[] nonce = new byte[8]; TlsUtils.writeUint64(seqNo, nonce, 0); cipher.init(forEncryption, new ParametersWithIV(null, nonce)); } }
protected KeyParameter initRecord(StreamCipher cipher, boolean forEncryption, long seqNo, byte[] iv) { byte[] nonce = calculateNonce(seqNo, iv); cipher.init(forEncryption, new ParametersWithIV(null, nonce)); return generateRecordMACKey(cipher); }
public void doChaCha(boolean encrypt, InputStream is, OutputStream os, byte[] key, byte[] iv) throws IOException { CipherParameters cp = new KeyParameter(key); ParametersWithIV params = new ParametersWithIV(cp, iv); StreamCipher engine = new ChaChaEngine(); engine.init(encrypt, params); byte in[] = new byte[8192]; byte out[] = new byte[8192]; int len = 0; while(-1 != (len = is.read(in))) { len = engine.processBytes(in, 0 , len, out, 0); os.write(out, 0, len); } } public void encChaCha(InputStream is, OutputStream os, byte[] key, byte[] iv) throws IOException { doChaCha(true, is, os, key, iv); } public void decChaCha(InputStream is, OutputStream os, byte[] key, byte[] iv) throws IOException { doChaCha(false, is, os, key, iv); }
static void prg(byte[] r, int rOff, long rlen, byte[] key, int keyOff) { byte[] nonce = new byte[8]; StreamCipher cipher = new ChaChaEngine(12); cipher.init(true, new ParametersWithIV(new KeyParameter(key, keyOff, 32), nonce)); cipher.processBytes(r, rOff, (int)rlen, r, rOff); //crypto_stream_chacha12(r, rlen, nonce, key); } }
cipher.init(forEncryption, encKey);
cipher.init(forEncryption, encKey);