Mercurial > 510Connectbot
diff src/ch/ethz/ssh2/crypto/cipher/CTRMode.java @ 308:42b15aaa7ac7 ganymed
merge
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Wed, 30 Jul 2014 14:21:50 -0700 |
parents | 071eccdff8ea |
children |
line wrap: on
line diff
--- a/src/ch/ethz/ssh2/crypto/cipher/CTRMode.java Wed Jul 30 13:38:04 2014 -0700 +++ b/src/ch/ethz/ssh2/crypto/cipher/CTRMode.java Wed Jul 30 14:21:50 2014 -0700 @@ -6,60 +6,52 @@ /** * This is CTR mode as described in draft-ietf-secsh-newmodes-XY.txt - * + * * @author Christian Plattner * @version 2.50, 03/15/10 */ -public class CTRMode implements BlockCipher -{ - byte[] X; - byte[] Xenc; +public class CTRMode implements BlockCipher { + byte[] X; + byte[] Xenc; - BlockCipher bc; - int blockSize; - boolean doEncrypt; + BlockCipher bc; + int blockSize; + boolean doEncrypt; - int count = 0; + int count = 0; - public void init(boolean forEncryption, byte[] key) - { - } + public void init(boolean forEncryption, byte[] key) { + } - public CTRMode(BlockCipher tc, byte[] iv, boolean doEnc) throws IllegalArgumentException - { - bc = tc; - blockSize = bc.getBlockSize(); - doEncrypt = doEnc; + public CTRMode(BlockCipher tc, byte[] iv, boolean doEnc) throws IllegalArgumentException { + bc = tc; + blockSize = bc.getBlockSize(); + doEncrypt = doEnc; - if (blockSize != iv.length) - throw new IllegalArgumentException("IV must be " + blockSize + " bytes long! (currently " + iv.length + ")"); - - X = new byte[blockSize]; - Xenc = new byte[blockSize]; + if (blockSize != iv.length) + throw new IllegalArgumentException("IV must be " + blockSize + " bytes long! (currently " + iv.length + ")"); - System.arraycopy(iv, 0, X, 0, blockSize); - } + X = new byte[blockSize]; + Xenc = new byte[blockSize]; + System.arraycopy(iv, 0, X, 0, blockSize); + } - public final int getBlockSize() - { - return blockSize; - } + public final int getBlockSize() { + return blockSize; + } - public final void transformBlock(byte[] src, int srcoff, byte[] dst, int dstoff) - { - bc.transformBlock(X, 0, Xenc, 0); + public final void transformBlock(byte[] src, int srcoff, byte[] dst, int dstoff) { + bc.transformBlock(X, 0, Xenc, 0); - for (int i = 0; i < blockSize; i++) - { - dst[dstoff + i] = (byte) (src[srcoff + i] ^ Xenc[i]); - } + for (int i = 0; i < blockSize; i++) { + dst[dstoff + i] = (byte)(src[srcoff + i] ^ Xenc[i]); + } - for (int i = (blockSize - 1); i >= 0; i--) - { - X[i]++; - if (X[i] != 0) - break; + for (int i = (blockSize - 1); i >= 0; i--) { + X[i]++; - } - } + if (X[i] != 0) + break; + } + } }