/** * 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 void transformBlock(byte[] in, int inOff, byte[] out, int outOff) { if (workingKey == null) { throw new IllegalStateException("Blowfish not initialised"); } if (doEncrypt) { encryptBlock(in, inOff, out, outOff); } else { decryptBlock(in, inOff, out, outOff); } }
/** * initialise a Blowfish cipher. * * @param encrypting * whether or not we are for encryption. * @param key * the key required to set up the cipher. * @exception IllegalArgumentException * if the params argument is inappropriate. */ public void init(boolean encrypting, byte[] key) { this.doEncrypt = encrypting; this.workingKey = key; setKey(this.workingKey); }
/** * 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);
/** * 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);
/** * 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 void transformBlock(byte[] in, int inOff, byte[] out, int outOff) { if (workingKey == null) { throw new IllegalStateException("Blowfish not initialised"); } if (doEncrypt) { encryptBlock(in, inOff, out, outOff); } else { decryptBlock(in, inOff, out, outOff); } }
/** * initialise a Blowfish cipher. * * @param encrypting * whether or not we are for encryption. * @param key * the key required to set up the cipher. * @exception IllegalArgumentException * if the params argument is inappropriate. */ public void init(boolean encrypting, byte[] key) { this.doEncrypt = encrypting; this.workingKey = key; setKey(this.workingKey); }
/** * 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);
/** * 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 final void transformBlock(byte[] in, int inOff, byte[] out, int outOff) { if (workingKey == null) { throw new IllegalStateException("Blowfish not initialised"); } if (doEncrypt) { encryptBlock(in, inOff, out, outOff); } else { decryptBlock(in, inOff, out, outOff); } }
/** * initialise a Blowfish cipher. * * @param encrypting * whether or not we are for encryption. * @param key * the key required to set up the cipher. * @exception IllegalArgumentException * if the params argument is inappropriate. */ public void init(boolean encrypting, byte[] key) { this.doEncrypt = encrypting; this.workingKey = key; setKey(this.workingKey); }
/** * 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); }
/** * 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); }
/** * 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); }