public ECB64() { super(new RC564Engine()); } }
private int decryptBlock( byte[] in, int inOff, byte[] out, int outOff) { long A = bytesToWord(in, inOff); long B = bytesToWord(in, inOff + bytesPerWord); for (int i = _noRounds; i >= 1; i--) { B = rotateRight(B - _S[2*i+1], A) ^ A; A = rotateRight(A - _S[2*i], B) ^ B; } wordToBytes(A - _S[0], out, outOff); wordToBytes(B - _S[1], out, outOff + bytesPerWord); return 2 * bytesPerWord; }
public int processBlock( byte[] in, int inOff, byte[] out, int outOff) { return (forEncryption) ? encryptBlock(in, inOff, out, outOff) : decryptBlock(in, inOff, out, outOff); }
/** * Encrypt the given block starting at the given offset and place * the result in the provided buffer starting at the given offset. * <p> * @param in in byte buffer containing data to encrypt * @param inOff offset into src buffer * @param out out buffer where encrypted data is written * @param outOff offset into out buffer */ private int encryptBlock( byte[] in, int inOff, byte[] out, int outOff) { long A = bytesToWord(in, inOff) + _S[0]; long B = bytesToWord(in, inOff + bytesPerWord) + _S[1]; for (int i = 1; i <= _noRounds; i++) { A = rotateLeft(A ^ B, B) + _S[2*i]; B = rotateLeft(B ^ A, A) + _S[2*i+1]; } wordToBytes(A, out, outOff); wordToBytes(B, out, outOff + bytesPerWord); return 2 * bytesPerWord; }
/** * initialise a RC5-64 cipher. * * @param forEncryption whether or not we are for encryption. * @param params the parameters required to set up the cipher. * @exception IllegalArgumentException if the params argument is * inappropriate. */ public void init( boolean forEncryption, CipherParameters params) { if (!(params instanceof RC5Parameters)) { throw new IllegalArgumentException("invalid parameter passed to RC564 init - " + params.getClass().getName()); } RC5Parameters p = (RC5Parameters)params; this.forEncryption = forEncryption; _noRounds = p.getRounds(); setKey(p.getKey()); }
A = _S[i] = rotateLeft(_S[i] + A + B, 3); B = L[j] = rotateLeft(L[j] + A + B, A+B); i = (i+1) % _S.length; j = (j+1) % L.length;
/** * Encrypt the given block starting at the given offset and place * the result in the provided buffer starting at the given offset. * <p> * @param in in byte buffer containing data to encrypt * @param inOff offset into src buffer * @param out out buffer where encrypted data is written * @param outOff offset into out buffer */ private int encryptBlock( byte[] in, int inOff, byte[] out, int outOff) { long A = bytesToWord(in, inOff) + _S[0]; long B = bytesToWord(in, inOff + bytesPerWord) + _S[1]; for (int i = 1; i <= _noRounds; i++) { A = rotateLeft(A ^ B, B) + _S[2*i]; B = rotateLeft(B ^ A, A) + _S[2*i+1]; } wordToBytes(A, out, outOff); wordToBytes(B, out, outOff + bytesPerWord); return 2 * bytesPerWord; }
/** * initialise a RC5-64 cipher. * * @param forEncryption whether or not we are for encryption. * @param params the parameters required to set up the cipher. * @exception IllegalArgumentException if the params argument is * inappropriate. */ public void init( boolean forEncryption, CipherParameters params) { if (!(params instanceof RC5Parameters)) { throw new IllegalArgumentException("invalid parameter passed to RC564 init - " + params.getClass().getName()); } RC5Parameters p = (RC5Parameters)params; this.forEncryption = forEncryption; _noRounds = p.getRounds(); setKey(p.getKey()); }
A = _S[i] = rotateLeft(_S[i] + A + B, 3); B = L[j] = rotateLeft(L[j] + A + B, A+B); i = (i+1) % _S.length; j = (j+1) % L.length;
private int decryptBlock( byte[] in, int inOff, byte[] out, int outOff) { long A = bytesToWord(in, inOff); long B = bytesToWord(in, inOff + bytesPerWord); for (int i = _noRounds; i >= 1; i--) { B = rotateRight(B - _S[2*i+1], A) ^ A; A = rotateRight(A - _S[2*i], B) ^ B; } wordToBytes(A - _S[0], out, outOff); wordToBytes(B - _S[1], out, outOff + bytesPerWord); return 2 * bytesPerWord; }
public int processBlock( byte[] in, int inOff, byte[] out, int outOff) { return (forEncryption) ? encryptBlock(in, inOff, out, outOff) : decryptBlock(in, inOff, out, outOff); }
cipher = new RC2Engine(); } else if ("RC5".equalsIgnoreCase(algorithm)) { cipher = new RC564Engine(); } else if ("RC6".equalsIgnoreCase(algorithm)) { cipher = new RC6Engine();