public ECB() { super(new BlowfishEngine()); } }
/** * Encrypt the given input starting at the given offset and place * the result in the provided buffer starting at the given offset. * The input will be an exact multiple of our blocksize. */ private void encryptBlock( byte[] src, int srcIndex, byte[] dst, int dstIndex) { int xl = BytesTo32bits(src, srcIndex); int xr = BytesTo32bits(src, srcIndex+4); xl ^= P[0]; for (int i = 1; i < ROUNDS; i += 2) { xr ^= F(xl) ^ P[i]; xl ^= F(xr) ^ P[i + 1]; } xr ^= P[ROUNDS + 1]; Bits32ToBytes(xr, dst, dstIndex); Bits32ToBytes(xl, dst, dstIndex + 4); }
public final int processBlock( byte[] in, int inOff, byte[] out, int outOff) { if (workingKey == null) { throw new IllegalStateException("Blowfish not initialised"); } if ((inOff + BLOCK_SIZE) > in.length) { throw new DataLengthException("input buffer too short"); } if ((outOff + BLOCK_SIZE) > out.length) { throw new OutputLengthException("output buffer too short"); } if (encrypting) { encryptBlock(in, inOff, out, outOff); } else { decryptBlock(in, inOff, out, outOff); } return BLOCK_SIZE; }
/** * initialise a Blowfish cipher. * * @param encrypting 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 encrypting, CipherParameters params) { if (params instanceof KeyParameter) { this.encrypting = encrypting; this.workingKey = ((KeyParameter)params).getKey(); setKey(this.workingKey); return; } throw new IllegalArgumentException("invalid parameter passed to Blowfish init - " + params.getClass().getName()); }
/** * apply the encryption cycle to each value pair in the table. */ private void processTable( int xl, int xr, int[] table) { int size = table.length; for (int s = 0; s < size; s += 2) { xl ^= P[0]; for (int i = 1; i < ROUNDS; i += 2) { xr ^= F(xl) ^ P[i]; xl ^= F(xr) ^ P[i + 1]; } xr ^= P[ROUNDS + 1]; table[s] = xr; table[s + 1] = xl; xr = xl; // end of cycle swap xl = table[s]; } }
processTable(0, 0, P); processTable(P[P_SZ - 2], P[P_SZ - 1], S0); processTable(S0[SBOX_SK - 2], S0[SBOX_SK - 1], S1); processTable(S1[SBOX_SK - 2], S1[SBOX_SK - 1], S2); processTable(S2[SBOX_SK - 2], S2[SBOX_SK - 1], S3);
public final int processBlock( byte[] in, int inOff, byte[] out, int outOff) { if (workingKey == null) { throw new IllegalStateException("Blowfish not initialised"); } if ((inOff + BLOCK_SIZE) > in.length) { throw new DataLengthException("input buffer too short"); } if ((outOff + BLOCK_SIZE) > out.length) { throw new DataLengthException("output buffer too short"); } if (encrypting) { encryptBlock(in, inOff, out, outOff); } else { decryptBlock(in, inOff, out, outOff); } return BLOCK_SIZE; }
/** * initialise a Blowfish cipher. * * @param encrypting 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 encrypting, CipherParameters params) { if (params instanceof KeyParameter) { this.encrypting = encrypting; this.workingKey = ((KeyParameter)params).getKey(); setKey(this.workingKey); return; } throw new IllegalArgumentException("invalid parameter passed to Blowfish init - " + params.getClass().getName()); }
/** * apply the encryption cycle to each value pair in the table. */ private void processTable( int xl, int xr, int[] table) { int size = table.length; for (int s = 0; s < size; s += 2) { xl ^= P[0]; for (int i = 1; i < ROUNDS; i += 2) { xr ^= F(xl) ^ P[i]; xl ^= F(xr) ^ P[i + 1]; } xr ^= P[ROUNDS + 1]; table[s] = xr; table[s + 1] = xl; xr = xl; // end of cycle swap xl = table[s]; } }
processTable(0, 0, P); processTable(P[P_SZ - 2], P[P_SZ - 1], S0); processTable(S0[SBOX_SK - 2], S0[SBOX_SK - 1], S1); processTable(S1[SBOX_SK - 2], S1[SBOX_SK - 1], S2); processTable(S2[SBOX_SK - 2], S2[SBOX_SK - 1], S3);
public ECB() { super(new BlowfishEngine()); } }
/** * Decrypt the given input starting at the given offset and place * the result in the provided buffer starting at the given offset. * The input will be an exact multiple of our blocksize. */ private void decryptBlock( byte[] src, int srcIndex, byte[] dst, int dstIndex) { int xl = BytesTo32bits(src, srcIndex); int xr = BytesTo32bits(src, srcIndex + 4); xl ^= P[ROUNDS + 1]; for (int i = ROUNDS; i > 0 ; i -= 2) { xr ^= F(xl) ^ P[i]; xl ^= F(xr) ^ P[i - 1]; } xr ^= P[0]; Bits32ToBytes(xr, dst, dstIndex); Bits32ToBytes(xl, dst, dstIndex+4); }
public Blowfish_CFB8() { super(new CFBBlockCipher(new BlowfishEngine(), 8), 64); } }
/** * Encrypt the given input starting at the given offset and place * the result in the provided buffer starting at the given offset. * The input will be an exact multiple of our blocksize. */ private void encryptBlock( byte[] src, int srcIndex, byte[] dst, int dstIndex) { int xl = BytesTo32bits(src, srcIndex); int xr = BytesTo32bits(src, srcIndex+4); xl ^= P[0]; for (int i = 1; i < ROUNDS; i += 2) { xr ^= F(xl) ^ P[i]; xl ^= F(xr) ^ P[i + 1]; } xr ^= P[ROUNDS + 1]; Bits32ToBytes(xr, dst, dstIndex); Bits32ToBytes(xl, dst, dstIndex + 4); }
public CBC() { super(new CBCBlockCipher(new BlowfishEngine()), 64); } }
/** * Decrypt the given input starting at the given offset and place * the result in the provided buffer starting at the given offset. * The input will be an exact multiple of our blocksize. */ private void decryptBlock( byte[] src, int srcIndex, byte[] dst, int dstIndex) { int xl = BytesTo32bits(src, srcIndex); int xr = BytesTo32bits(src, srcIndex + 4); xl ^= P[ROUNDS + 1]; for (int i = ROUNDS; i > 0 ; i -= 2) { xr ^= F(xl) ^ P[i]; xl ^= F(xr) ^ P[i - 1]; } xr ^= P[0]; Bits32ToBytes(xr, dst, dstIndex); Bits32ToBytes(xl, dst, dstIndex+4); }
public CBC() { super(new CBCBlockCipher(new BlowfishEngine()), 64); } }
public CMAC() { super(new CMac(new BlowfishEngine())); } }
public Blowfish_OFB8() { super(new OFBBlockCipher(new BlowfishEngine(), 8), 64); } }
byte[] keyByte = key.getBytes("UTF8"); PaddedBufferedBlockCipher _cipher = new PaddedBufferedBlockCipher(new BlowfishEngine());