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; }
/** * initialise the underlying cipher. * * @param forEncryption true if we are setting up for encryption, false otherwise. * @param params the necessary parameters for the underlying cipher to be initialised. */ public void init( boolean forEncryption, CipherParameters params) { cipher.init(forEncryption, params); }
public int doFinal(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset) { int blockSize = cipher.getBlockSize(); for (int i = 0; i < inputLength; i += blockSize) { cipher.processBlock(input, inputOffset + i, output, outputOffset + i); } return inputLength; }
public void reset() { if (initialised) { engine.processBlock(this.iv, 0, ofbV, 0); } engine.reset(); byteCount = 0; }
private void E(byte[] key, byte[] s, int sOff, byte[] in, int inOff) { cipher.init(true, new KeyParameter(key)); cipher.processBlock(in, inOff, s, sOff); }
private void BCC(byte[] bccOut, byte[] k, byte[] iV, byte[] data) { int outlen = _engine.getBlockSize(); byte[] chainingValue = new byte[outlen]; // initial values = 0 int n = data.length / outlen; byte[] inputBlock = new byte[outlen]; _engine.init(true, new KeyParameter(expandKey(k))); _engine.processBlock(iV, 0, chainingValue, 0); for (int i = 0; i < n; i++) { XOR(inputBlock, chainingValue, data, i*outlen); _engine.processBlock(inputBlock, 0, chainingValue, 0); } System.arraycopy(chainingValue, 0, bccOut, 0, bccOut.length); }
public void setKey(byte[] key, int keyOff, int keyLen) { this.key = new KeyParameter(key, keyOff, keyLen); cipher.init(isEncrypting, new ParametersWithIV(this.key, new byte[cipher.getBlockSize()])); }
public void update( byte in) { if (bufOff == buf.length) { cipher.processBlock(buf, 0, mac, 0); bufOff = 0; } buf[bufOff++] = in; }
/** * return the algorithm name and mode. * * @return the name of the underlying algorithm followed by "/PGPCFB" * and the block size in bits. */ public String getAlgorithmName() { return cipher.getAlgorithmName() + "/OpenPGPCFB"; }
public void reset() { this.H = new byte[engine.getBlockSize()]; this.b = new byte[engine.getBlockSize()]; this.temp = new byte[engine.getBlockSize()]; this.lambda_c = 0; this.lambda_o = 0; engine.reset(); data.reset(); associatedText.reset(); if (initialAssociatedText != null) { processAADBytes(initialAssociatedText, 0, initialAssociatedText.length); } }
/** * reset the underlying cipher. This leaves it in the same state * it was at after the last init (if there was one). */ public void reset() { cipher.reset(); } }
private void E(byte[] key, byte[] s, int sOff, byte[] in, int inOff) { cipher.init(true, new KeyParameter(key)); cipher.processBlock(in, inOff, s, sOff); }
protected void initCipher(boolean forEncryption, BlockCipher cipher, byte[] key_block, int key_size, int key_offset, int iv_offset) { KeyParameter key_parameter = new KeyParameter(key_block, key_offset, key_size); ParametersWithIV parameters_with_iv = new ParametersWithIV(key_parameter, key_block, iv_offset, cipher.getBlockSize()); cipher.init(forEncryption, parameters_with_iv); }
public void update(byte in) { if (bufOff == buf.length) { cipher.processBlock(buf, 0, mac, 0); bufOff = 0; } buf[bufOff++] = in; }
/** * return the algorithm name and mode. * * @return the name of the underlying algorithm followed by "/OpenPGPCFB" * and the block size in bits. */ public String getAlgorithmName() { return cipher.getAlgorithmName() + "/OpenPGPCFB"; }
/** * reset the chaining vector back to the IV and reset the underlying * cipher. */ public void reset() { System.arraycopy(IV, 0, cfbV, 0, IV.length); cipher.reset(); }
/** * return the blocksize for the underlying cipher. * * @return the blocksize for the underlying cipher. */ public int getBlockSize() { return cipher.getBlockSize(); }
/** Encripta un bloque usando AES. * @param key Clave AES. * @param z Bloque a crifrar. * @return Bloque cifrado. */ public static byte[] encryptBlock(final byte[] key, final byte[] z) { final byte[] s = new byte[BLOCK_SIZE]; final KeyParameter encKey = new KeyParameter(key); final BlockCipher cipher = new AESEngine(); cipher.init(true, encKey); cipher.processBlock(z, 0, s, 0); return s; }
private void ProcessBlock(byte[] input, int inOff, int len, byte[] output, int outOff) { for (int byteIndex = 0; byteIndex < counter.length; byteIndex++) { s[byteIndex] += counter[byteIndex]; } engine.processBlock(s, 0, buffer, 0); for (int byteIndex = 0; byteIndex < engine.getBlockSize(); byteIndex++) { output[outOff + byteIndex] = (byte)(buffer[byteIndex] ^ input[inOff + byteIndex]); } }
public void init( CipherParameters params) { reset(); cipher.init(true, params); }