public static void RC5_32_ecb_encrypt(byte[] inBytes, byte[] outBytes, RC5_32_KEY ks, int encrypt, CryptContext cryptContext) { ulong l = 0; ulong[] d = new ulong[2]; int c2l_inBytes_startIdx = 0; int l2c_outBytes_startIdx = 0; CryptUtil.c2l(inBytes, ref l, ref c2l_inBytes_startIdx); d[0] = l; CryptUtil.c2l(inBytes, ref l, ref c2l_inBytes_startIdx); d[1] = l; if (encrypt > 0) { RC5_32_encrypt(ref d, ks); } else { RC5_32_decrypt(ref d, ks); } l = d[0]; CryptUtil.l2c(l, outBytes, ref l2c_outBytes_startIdx); l = d[1]; CryptUtil.l2c(l, outBytes, ref l2c_outBytes_startIdx); l = d[0] = d[1] = 0; }
public static void DES_ecb_encrypt(byte[] input, byte[] output, DES_key_schedule ks, int enc) { ulong l = 0; ulong[] ll = new ulong[2]; byte[] in_input = input; byte[] out_output = output; int c2l_in_input_startIdx = 0; int l2c_out_output_startIdx = 0; CryptUtil.c2l(in_input, ref l, ref c2l_in_input_startIdx); ll[0] = l; CryptUtil.c2l(in_input, ref l, ref c2l_in_input_startIdx); ll[1] = l; DES_encrypt1(ll, ks, enc); l = ll[0]; CryptUtil.l2c(l, out_output, ref l2c_out_output_startIdx); l = ll[1]; CryptUtil.l2c(l, out_output, ref l2c_out_output_startIdx); l = ll[0] = ll[1] = 0; }
public static void RC5_32_cbc_encrypt(byte[] inBytes, byte[] outBytes, long length, RC5_32_KEY ks, byte[] iv, int encrypt) { ulong tin0 = 0, tin1 = 0; ulong tout0 = 0, tout1 = 0, xor0 = 0, xor1 = 0; long l = length; ulong[] tin = new ulong[2]; int c2l_iv_startIdx = 0; int c2l_inBytes_startIdx = 0; int l2c_outBytes_startIdx = 0; int l2c_iv_startIdx = 0; if (encrypt > 0) { CryptUtil.c2l(iv, ref tout0, ref c2l_iv_startIdx); CryptUtil.c2l(iv, ref tout1, ref c2l_iv_startIdx); c2l_iv_startIdx -= 8; for (l -= 8; l >= 0; l -= 8) { CryptUtil.c2l(inBytes, ref tin0, ref c2l_inBytes_startIdx); CryptUtil.c2l(inBytes, ref tin1, ref c2l_inBytes_startIdx); tin0 ^= tout0; tin1 ^= tout1; tin[0] = tin0; tin[1] = tin1; RC5_32_encrypt(ref tin, ks); tout0 = tin[0]; CryptUtil.l2c(tout0, outBytes, ref l2c_outBytes_startIdx); tout1 = tin[1]; CryptUtil.l2c(tout1, outBytes, ref l2c_outBytes_startIdx); } if (l != -8) { CryptUtil.c2ln(inBytes, ref tin0, ref tin1, l + 8, ref c2l_inBytes_startIdx); tin0 ^= tout0; tin1 ^= tout1; tin[0] = tin0; tin[1] = tin1; RC5_32_encrypt(ref tin, ks); tout0 = tin[0]; CryptUtil.l2c(tout0, outBytes, ref l2c_outBytes_startIdx); tout1 = tin[1]; CryptUtil.l2c(tout1, outBytes, ref l2c_outBytes_startIdx); } CryptUtil.l2c(tout0, iv, ref l2c_iv_startIdx); CryptUtil.l2c(tout1, iv, ref l2c_iv_startIdx); } else { CryptUtil.c2l(iv, ref xor0, ref c2l_iv_startIdx); CryptUtil.c2l(iv, ref xor1, ref c2l_iv_startIdx); c2l_iv_startIdx -= 8; for (l -= 8; l >= 0; l -= 8) { CryptUtil.c2l(inBytes, ref tin0, ref c2l_inBytes_startIdx); tin[0] = tin0; CryptUtil.c2l(inBytes, ref tin1, ref c2l_inBytes_startIdx); tin[1] = tin1; RC5_32_decrypt(ref tin, ks); tout0 = tin[0] ^ xor0; tout1 = tin[1] ^ xor1; CryptUtil.l2c(tout0, outBytes, ref l2c_outBytes_startIdx); CryptUtil.l2c(tout1, outBytes, ref l2c_outBytes_startIdx); xor0 = tin0; xor1 = tin1; } if (l != -8) { CryptUtil.c2l(inBytes, ref tin0, ref c2l_inBytes_startIdx); tin[0] = tin0; CryptUtil.c2l(inBytes, ref tin1, ref c2l_inBytes_startIdx); tin[1] = tin1; RC5_32_decrypt(ref tin, ks); tout0 = tin[0] ^ xor0; tout1 = tin[1] ^ xor1; CryptUtil.l2cn(tout0, tout1, outBytes, l + 8, ref l2c_outBytes_startIdx); xor0 = tin0; xor1 = tin1; } CryptUtil.l2c(xor0, iv, ref l2c_iv_startIdx); CryptUtil.l2c(xor1, iv, ref l2c_iv_startIdx); } tin0 = tin1 = tout0 = tout1 = xor0 = xor1 = 0; tin[0] = tin[1] = 0; }