/** * encrypt 16 bytes (AES standard block size) or less * starting at "pos" within "in" byte[] */ protected void encryptBlock( byte[] in, int pos, int length ) { byte[] encryptedIn = new byte[blockSize]; byte[] ivBytes = ByteArrayHelper.toByteArray( nonce++, 16 ); ParametersWithIV ivParams = new ParametersWithIV(cipherParameters, ivBytes); aesCipher.init( true, ivParams ); int remainingCount = length-pos; if( remainingCount>=blockSize ) { aesCipher.processBlock( in, pos, encryptedIn, 0 ); System.arraycopy( encryptedIn, 0, in, pos, blockSize ); mac.update( encryptedIn, 0, blockSize ); } else { byte[] extendedIn = new byte[blockSize]; System.arraycopy( in, pos, extendedIn, 0, remainingCount ); aesCipher.processBlock( extendedIn, 0, encryptedIn, 0 ); System.arraycopy( encryptedIn, 0, in, pos, remainingCount ); mac.update( encryptedIn, 0, remainingCount ); } }
public int getBlockSize() { return cipher.getBlockSize(); }
public int processBlock(byte[] in, int inOff, byte[] out, int outOff) throws DataLengthException, IllegalStateException { processBytes(in, inOff, blockSize, out, outOff); return blockSize; }
public long skip(long numberOfBytes) { adjustCounter(numberOfBytes); checkCounter(); cipher.processBlock(counter, 0, counterOut, 0); return numberOfBytes; }
mac.init( new KeyParameter(authenticationCodeBytes) ); this.aesCipher = new SICBlockCipher(new AESEngine()); this.blockSize = aesCipher.getBlockSize();
private BufferedBlockCipher ase256CtrCipher(boolean forEncryption, byte[] key, byte[] iv) { BlockCipher engine = new AESEngine(); BufferedBlockCipher cipher = new BufferedBlockCipher(new SICBlockCipher(engine)); CipherParameters params = new ParametersWithIV(new KeyParameter(key), iv); cipher.init(forEncryption, params); return cipher; }
Arrays.fill(IV, (byte) 0); SICBlockCipher decryptionCipher = new SICBlockCipher(new AESEngine()); decryptionCipher.init(false, new ParametersWithIV(aesKey, IV)); decryptionCipher.processBytes(headerBytes.toArrayUnsafe(), 0, 16, decryptedHeader.toArrayUnsafe(), 0); int frameSize = decryptedHeader.get(0) & 0xff; frameSize = (frameSize << 8) + (decryptedHeader.get(1) & 0xff); .processBytes(frameData.toArrayUnsafe(), 0, frameData.size(), decryptedFrameData.toArrayUnsafe(), 0);
SICBlockCipher ctrEngine = new SICBlockCipher(engine); ctrEngine.init(false, params); ctrEngine.processBlock(cipher, i, out, i); i += engine.getBlockSize(); if (cipher.length - i < engine.getBlockSize()) byte[] tmpBlock = new byte[16]; System.arraycopy(cipher, i, tmpBlock, 0, cipher.length - i); ctrEngine.processBlock(tmpBlock, 0, tmpBlock, 0); System.arraycopy(tmpBlock, 0, out, i, cipher.length - i);
rng.nextBytes(iv); AESFastEngine e = new AESFastEngine(); SICBlockCipher ctr = new SICBlockCipher(e); ctr.init(true, new ParametersWithIV(new KeyParameter(key),iv)); cis = new CipherInputStream(zis, new BufferedBlockCipher(ctr)); cisCounter = 0;
size = cipher.processBlock(bufBlock, 0, out, outOff); size = cipher.processBlock(bufBlock, 0, out, outOff);
public BlockCipher getUnderlyingCipher() { return cipher.getUnderlyingCipher(); }
cipher.init(true, new ParametersWithIV(null, nonceMac));
public long skip(long numberOfBytes) { adjustCounter(numberOfBytes); cipher.processBlock(counter, 0, counterOut, 0); return numberOfBytes; }
mac.init( new KeyParameter(authenticationCodeBytes) ); this.aesCipher = new SICBlockCipher(new AESEngine()); this.blockSize = aesCipher.getBlockSize();
/** * Constructor that accepts an instance of a block cipher engine. * * @param cipher the engine to use */ public EAXBlockCipher(BlockCipher cipher) { blockSize = cipher.getBlockSize(); mac = new CMac(cipher); macBlock = new byte[blockSize]; associatedTextMac = new byte[mac.getMacSize()]; nonceMac = new byte[mac.getMacSize()]; this.cipher = new SICBlockCipher(cipher); }
Arrays.fill(IV, (byte) 0); SICBlockCipher encryptionCipher = new SICBlockCipher(new AESEngine()); encryptionCipher.init(true, new ParametersWithIV(aesKey, IV)); Bytes headerBytes = Bytes.concatenate(frameSizeBytes, protocolHeader, Bytes.wrap(zeros)); Bytes encryptedHeaderBytes = Bytes.wrap(new byte[16]); encryptionCipher.processBytes(headerBytes.toArrayUnsafe(), 0, 16, encryptedHeaderBytes.toArrayUnsafe(), 0); Bytes headerMac = calculateMac(encryptedHeaderBytes, false); encryptionCipher.processBytes( Bytes.concatenate(idBytes, messageData, Bytes.wrap(new byte[pad])).toArrayUnsafe(), 0,
size = cipher.processBlock(bufBlock, 0, out, outOff); size = cipher.processBlock(bufBlock, 0, out, outOff);
public BlockCipher getUnderlyingCipher() { return cipher.getUnderlyingCipher(); }
cipher.init(true, new ParametersWithIV(null, nonceMac));
public void init( String pwStr, int keySize, byte[] salt, byte[] pwVerification ) throws ZipException { byte[] pwBytes = pwStr.getBytes(); super.saltBytes = salt; PBEParametersGenerator generator = new PKCS5S2ParametersGenerator(); generator.init( pwBytes, salt, ITERATION_COUNT ); cipherParameters = generator.generateDerivedParameters(KEY_SIZE_BIT*2 + 16); byte[] keyBytes = ((KeyParameter)cipherParameters).getKey(); this.cryptoKeyBytes = new byte[ KEY_SIZE_BYTE ]; System.arraycopy( keyBytes, 0, cryptoKeyBytes, 0, KEY_SIZE_BYTE ); this.authenticationCodeBytes = new byte[ KEY_SIZE_BYTE ]; System.arraycopy( keyBytes, KEY_SIZE_BYTE, authenticationCodeBytes, 0, KEY_SIZE_BYTE ); // based on SALT + PASSWORD (password is probably correct) this.pwVerificationBytes = new byte[ 2 ]; System.arraycopy( keyBytes, KEY_SIZE_BYTE*2, this.pwVerificationBytes, 0, 2 ); if( !ByteArrayHelper.isEqual( this.pwVerificationBytes, pwVerification ) ) { throw new ZipException("wrong password - " + ByteArrayHelper.toString(this.pwVerificationBytes) + "/ " + ByteArrayHelper.toString(pwVerification)); } // create the first 16 bytes of the key sequence again (using pw+salt) generator.init( pwBytes, salt, ITERATION_COUNT ); cipherParameters = generator.generateDerivedParameters(KEY_SIZE_BIT); // checksum added to the end of the encrypted data, update on each encryption call this.mac = new HMac( new SHA1Digest() ); mac.init( new KeyParameter(authenticationCodeBytes) ); this.aesCipher = new SICBlockCipher(new AESEngine()); this.blockSize = aesCipher.getBlockSize(); // incremented on each 16 byte block and used as encryption NONCE (ivBytes) nonce = 1; }