public static CTR @new(IBlockCipher cipher, _counter counter) { CTR ctr = new CTR(); ctr.ucipher = cipher; ctr.counter = counter; ctr.counterOut = new byte[counter.Length]; ctr.count = 0; return ctr; }
private static CAST @new(string key, int mode, string IV, int segment_size, _counter counter) { if (key.Length == 0) { throw PythonOps.ValueError("Key cannot be the null string"); } if (IV.Length > 0 && IV.Length != block_size) { throw PythonOps.ValueError("IV must be {0} bytes long", block_size); } if (counter != null && mode != MODE_CTR) { throw PythonOps.ValueError("'counter' parameter only useful with CTR mode"); } CAST cast = new CAST(); IBlockCipher cipher = CAST_ECB.@new(key); if (mode == MODE_CBC) { cast.mcipher = CBC.@new(cipher, IV); } else if (mode == MODE_CFB) { cast.mcipher = CFB.@new(cipher, IV, segment_size); } else if (mode == MODE_OFB) { cast.mcipher = OFB.@new(cipher, IV); } else if (mode == MODE_CTR) { if (counter == null) { throw PythonOps.TypeError("'counter' keyword parameter is required with CTR mode"); } cast.mcipher = CTR.@new(cipher, counter); } else if (mode == MODE_ECB) { cast.mcipher = cipher; } else { throw PythonOps.ValueError("Unknown cipher feedback mode {0}", mode); } cast.bitcount = cast.blocksize * 8; cast.key = StringBytes.StringToBytes(key); if (IV != null) { cast.IV = StringBytes.StringToBytes(IV); } cast.mode = mode; return (CAST)cast; }
public static CAST @new(string key, int mode, string IV, _counter counter) { CAST cast = CAST.@new(key, mode, IV, 8, counter); return (CAST)cast; }
public static DES @new(string key, int mode, string IV, _counter counter) { DES des = DES.@new(key, mode, IV, 8, counter); return (DES) des; }
private static ARC2 @new(string key, int mode, string IV, int segment_size, _counter counter, int effective_keylen) { if (key.Length == 0) { throw PythonOps.ValueError("Key cannot be the null string"); } if (IV.Length > 0 && IV.Length != block_size) { throw PythonOps.ValueError("IV must be {0} bytes long", block_size); } if (counter != null && mode != MODE_CTR) { throw PythonOps.ValueError("'counter' parameter only useful with CTR mode"); } if (effective_keylen < 0 || effective_keylen > 1024) { throw PythonOps.ValueError("RC2: effective_keylen must be between 0 and 1024, not {0}", effective_keylen); } ARC2 arc2 = new ARC2(); arc2.effective_keylen = effective_keylen; IBlockCipher cipher = ARC2_ECB.@new(key, effective_keylen); if (mode == MODE_CBC) { arc2.mcipher = CBC.@new(cipher, IV); } else if (mode == MODE_CFB) { arc2.mcipher = CFB.@new(cipher, IV, segment_size); } else if (mode == MODE_OFB) { arc2.mcipher = OFB.@new(cipher, IV); } else if (mode == MODE_CTR) { if (counter == null) { throw PythonOps.TypeError("'counter' keyword parameter is required with CTR mode"); } arc2.mcipher = CTR.@new(cipher, counter); } else if (mode == MODE_ECB) { arc2.mcipher = cipher; } else { throw PythonOps.ValueError("Unknown cipher feedback mode {0}", mode); } arc2.bitcount = arc2.blocksize * 8; arc2.key = StringBytes.StringToBytes(key); if (arc2.key.Length > 128) { throw PythonOps.ValueError("ARC2 key length must be less than 128 bytes"); } if (IV != null) { arc2.IV = StringBytes.StringToBytes(IV); } arc2.mode = mode; return (ARC2)arc2; }
public static ARC2 @new(string key, int mode, string IV, _counter counter) { ARC2 arc2 = ARC2.@new(key, mode, IV, 8, counter, 1024); return (ARC2)arc2; }
public static Blowfish @new(string key, int mode, string IV, _counter counter) { Blowfish blf = Blowfish.@new(key, mode, IV, 8, counter); return (Blowfish) blf; }
public static DES3 @new(string key, int mode, string IV, _counter counter) { DES3 des3 = DES3.@new(key, mode, IV, 8, counter); return (DES3) des3; }
public static _counter _newBE(string prefix, string suffix, string initval, bool allow_wraparound, bool disable_shortcut) { _counter c = new _counter(); CheckArgs(prefix, suffix, initval); c.nbytes = initval.Length + prefix.Length + suffix.Length; c.prefix = StringBytes.StringToBytes(prefix); c.suffix = StringBytes.StringToBytes(suffix); c.val = new byte[initval.Length]; byte[] binitval = StringBytes.StringToBytes(initval); Buffer.BlockCopy(binitval, 0, c.val, 0, c.val.Length); c.allow_wraparound = allow_wraparound; c.disable_shortcut = disable_shortcut; c.little_endian = false; c.carry = 0; return c; }
private static AES @new(string key, int mode, string IV, int segment_size, _counter counter) { if (key.Length == 0) { throw PythonOps.ValueError("Key cannot be the null string"); } if (IV.Length > 0 && IV.Length != block_size) { throw PythonOps.ValueError("IV must be {0} bytes long", block_size); } if (counter != null && mode != MODE_CTR) { throw PythonOps.ValueError("'counter' parameter only useful with CTR mode"); } AES aes = new AES(); IBlockCipher cipher = AES_ECB.@new(key); if (mode == MODE_CBC) { aes.mcipher = CBC.@new(cipher, IV); } else if (mode == MODE_CFB) { aes.mcipher = CFB.@new(cipher, IV, segment_size); } else if (mode == MODE_OFB) { aes.mcipher = OFB.@new(cipher, IV); } else if (mode == MODE_CTR) { if (counter == null) { throw PythonOps.TypeError("'counter' keyword parameter is required with CTR mode"); } // don't know how to check if counter is callable aes.mcipher = CTR.@new(cipher, counter); } else if (mode == MODE_ECB) { aes.mcipher = cipher; } else { throw PythonOps.ValueError("Unknown cipher feedback mode {0}", mode); } aes.bitcount = aes.blocksize * 8; aes.key = StringBytes.StringToBytes(key); if (IV != null) { aes.IV = StringBytes.StringToBytes(IV); } aes.mode = mode; return (AES) aes; }
public static AES @new(string key, int mode, string IV, _counter counter) { AES aes = AES.@new(key, mode, IV, 8, counter); return (AES) aes; }