public ECB() { super(new CAST5Engine()); } }
/** * Encrypt the given input starting at the given offset and place * the result in the provided buffer starting at the given offset. * * @param src The plaintext buffer * @param srcIndex An offset into src * @param dst The ciphertext buffer * @param dstIndex An offset into dst */ protected int encryptBlock( byte[] src, int srcIndex, byte[] dst, int dstIndex) { int result[] = new int[2]; // process the input block // batch the units up into a 32 bit chunk and go for it // the array is in bytes, the increment is 8x8 bits = 64 int L0 = BytesTo32bits(src, srcIndex); int R0 = BytesTo32bits(src, srcIndex + 4); CAST_Encipher(L0, R0, result); // now stuff them into the destination block Bits32ToBytes(result[0], dst, dstIndex); Bits32ToBytes(result[1], dst, dstIndex + 4); return BLOCK_SIZE; }
/** * Decrypt the given input starting at the given offset and place * the result in the provided buffer starting at the given offset. * * @param src The plaintext buffer * @param srcIndex An offset into src * @param dst The ciphertext buffer * @param dstIndex An offset into dst */ protected int decryptBlock( byte[] src, int srcIndex, byte[] dst, int dstIndex) { int result[] = new int[2]; // process the input block // batch the units up into a 32 bit chunk and go for it // the array is in bytes, the increment is 8x8 bits = 64 int L16 = BytesTo32bits(src, srcIndex); int R16 = BytesTo32bits(src, srcIndex+4); CAST_Decipher(L16, R16, result); // now stuff them into the destination block Bits32ToBytes(result[0], dst, dstIndex); Bits32ToBytes(result[1], dst, dstIndex+4); return BLOCK_SIZE; }
x03 = IntsTo32bits(x, 0x0); x47 = IntsTo32bits(x, 0x4); x8B = IntsTo32bits(x, 0x8); xCF = IntsTo32bits(x, 0xC); Bits32ToInts(z03, z, 0x0); z47 = x8B ^S5[z[0x0]] ^S6[z[0x2]] ^S7[z[0x1]] ^S8[z[0x3]] ^S8[x[0xA]]; Bits32ToInts(z47, z, 0x4); z8B = xCF ^S5[z[0x7]] ^S6[z[0x6]] ^S7[z[0x5]] ^S8[z[0x4]] ^S5[x[0x9]]; Bits32ToInts(z8B, z, 0x8); zCF = x47 ^S5[z[0xA]] ^S6[z[0x9]] ^S7[z[0xB]] ^S8[z[0x8]] ^S6[x[0xB]]; Bits32ToInts(zCF, z, 0xC); _Km[ 1]= S5[z[0x8]] ^ S6[z[0x9]] ^ S7[z[0x7]] ^ S8[z[0x6]] ^ S5[z[0x2]]; _Km[ 2]= S5[z[0xA]] ^ S6[z[0xB]] ^ S7[z[0x5]] ^ S8[z[0x4]] ^ S6[z[0x6]]; z03 = IntsTo32bits(z, 0x0); z47 = IntsTo32bits(z, 0x4); z8B = IntsTo32bits(z, 0x8); zCF = IntsTo32bits(z, 0xC); x03 = z8B ^S5[z[0x5]] ^S6[z[0x7]] ^S7[z[0x4]] ^S8[z[0x6]] ^S7[z[0x0]]; Bits32ToInts(x03, x, 0x0); x47 = z03 ^S5[x[0x0]] ^S6[x[0x2]] ^S7[x[0x1]] ^S8[x[0x3]] ^S8[z[0x2]]; Bits32ToInts(x47, x, 0x4); x8B = z47 ^S5[x[0x7]] ^S6[x[0x6]] ^S7[x[0x5]] ^S8[x[0x4]] ^S5[z[0x1]]; Bits32ToInts(x8B, x, 0x8); xCF = zCF ^S5[x[0xA]] ^S6[x[0x9]] ^S7[x[0xB]] ^S8[x[0x8]] ^S6[z[0x3]]; Bits32ToInts(xCF, x, 0xC); _Km[ 5]= S5[x[0x3]] ^ S6[x[0x2]] ^ S7[x[0xC]] ^ S8[x[0xD]] ^ S5[x[0x8]]; _Km[ 6]= S5[x[0x1]] ^ S6[x[0x0]] ^ S7[x[0xE]] ^ S8[x[0xF]] ^ S6[x[0xD]];
x03 = IntsTo32bits(x, 0x0); x47 = IntsTo32bits(x, 0x4); x8B = IntsTo32bits(x, 0x8); xCF = IntsTo32bits(x, 0xC); Bits32ToInts(z03, z, 0x0); z47 = x8B ^S5[z[0x0]] ^S6[z[0x2]] ^S7[z[0x1]] ^S8[z[0x3]] ^S8[x[0xA]]; Bits32ToInts(z47, z, 0x4); z8B = xCF ^S5[z[0x7]] ^S6[z[0x6]] ^S7[z[0x5]] ^S8[z[0x4]] ^S5[x[0x9]]; Bits32ToInts(z8B, z, 0x8); zCF = x47 ^S5[z[0xA]] ^S6[z[0x9]] ^S7[z[0xB]] ^S8[z[0x8]] ^S6[x[0xB]]; Bits32ToInts(zCF, z, 0xC); _Km[ 1]= S5[z[0x8]] ^ S6[z[0x9]] ^ S7[z[0x7]] ^ S8[z[0x6]] ^ S5[z[0x2]]; _Km[ 2]= S5[z[0xA]] ^ S6[z[0xB]] ^ S7[z[0x5]] ^ S8[z[0x4]] ^ S6[z[0x6]]; z03 = IntsTo32bits(z, 0x0); z47 = IntsTo32bits(z, 0x4); z8B = IntsTo32bits(z, 0x8); zCF = IntsTo32bits(z, 0xC); x03 = z8B ^S5[z[0x5]] ^S6[z[0x7]] ^S7[z[0x4]] ^S8[z[0x6]] ^S7[z[0x0]]; Bits32ToInts(x03, x, 0x0); x47 = z03 ^S5[x[0x0]] ^S6[x[0x2]] ^S7[x[0x1]] ^S8[x[0x3]] ^S8[z[0x2]]; Bits32ToInts(x47, x, 0x4); x8B = z47 ^S5[x[0x7]] ^S6[x[0x6]] ^S7[x[0x5]] ^S8[x[0x4]] ^S5[z[0x1]]; Bits32ToInts(x8B, x, 0x8); xCF = zCF ^S5[x[0xA]] ^S6[x[0x9]] ^S7[x[0xB]] ^S8[x[0x8]] ^S6[z[0x3]]; Bits32ToInts(xCF, x, 0xC); _Km[ 5]= S5[x[0x3]] ^ S6[x[0x2]] ^ S7[x[0xC]] ^ S8[x[0xD]] ^ S5[x[0x8]]; _Km[ 6]= S5[x[0x1]] ^ S6[x[0x0]] ^ S7[x[0xE]] ^ S8[x[0xF]] ^ S6[x[0xD]];
/** * Encrypt the given input starting at the given offset and place * the result in the provided buffer starting at the given offset. * * @param src The plaintext buffer * @param srcIndex An offset into src * @param dst The ciphertext buffer * @param dstIndex An offset into dst */ protected int encryptBlock( byte[] src, int srcIndex, byte[] dst, int dstIndex) { int result[] = new int[2]; // process the input block // batch the units up into a 32 bit chunk and go for it // the array is in bytes, the increment is 8x8 bits = 64 int L0 = BytesTo32bits(src, srcIndex); int R0 = BytesTo32bits(src, srcIndex + 4); CAST_Encipher(L0, R0, result); // now stuff them into the destination block Bits32ToBytes(result[0], dst, dstIndex); Bits32ToBytes(result[1], dst, dstIndex + 4); return BLOCK_SIZE; }
/** * Decrypt the given input starting at the given offset and place * the result in the provided buffer starting at the given offset. * * @param src The plaintext buffer * @param srcIndex An offset into src * @param dst The ciphertext buffer * @param dstIndex An offset into dst */ protected int decryptBlock( byte[] src, int srcIndex, byte[] dst, int dstIndex) { int result[] = new int[2]; // process the input block // batch the units up into a 32 bit chunk and go for it // the array is in bytes, the increment is 8x8 bits = 64 int L16 = BytesTo32bits(src, srcIndex); int R16 = BytesTo32bits(src, srcIndex+4); CAST_Decipher(L16, R16, result); // now stuff them into the destination block Bits32ToBytes(result[0], dst, dstIndex); Bits32ToBytes(result[1], dst, dstIndex+4); return BLOCK_SIZE; }
public CBC() { super(new CBCBlockCipher(new CAST5Engine()), 64); } }
cipher = new CamelliaEngine(); } else if ("CAST5".equalsIgnoreCase(algorithm)) { cipher = new CAST5Engine(); } else if ("CAST6".equalsIgnoreCase(algorithm)) { cipher = new CAST6Engine();
cipher = new CBCBlockCipher(new CAST5Engine());