private void OnRoundsCountChanged(object sender, EventArgs e) { RoundCounts rcount = RoundCounts.R10; Enum.TryParse <RoundCounts>(((ComboBox)sender).Text, out rcount); _roundCount = rcount; }
/// <summary> /// Initialize the structure with parameters for any supported type of Mac generator /// </summary> /// /// <param name="MacType">The type of Mac generator; Cmac, Hmac, or Vmac</param> /// <param name="KeySize">The mac/cipher key size in bytes</param> /// <param name="IvSize">Size of the Mac Initialization Vector</param> /// <param name="HmacEngine">The <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.Digests">Digest</see> engine used in the Hmac</param> /// <param name="EngineType">The symmetric block cipher <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.SymmetricEngines">Engine</see> type</param> /// <param name="RoundCount">The number of diffusion <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.RoundCounts">Rounds</see></param> /// <param name="BlockSize">The cipher <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.BlockSizes">Block Size</see></param> /// <param name="KdfEngine">The <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.Digests">Digest</see> engine used to power the key schedule Key Derivation Function in HX and M series ciphers</param> public MacDescription(Macs MacType, int KeySize, int IvSize, Digests HmacEngine = Digests.SHA512, BlockCiphers EngineType = BlockCiphers.Rijndael, RoundCounts RoundCount = RoundCounts.R14, BlockSizes BlockSize = BlockSizes.B128, Digests KdfEngine = Digests.SHA512) { this.MacType = (int)MacType; this.KeySize = KeySize; this.IvSize = IvSize; this.HmacEngine = (int)HmacEngine; this.EngineType = (int)EngineType; this.RoundCount = (int)RoundCount; this.BlockSize = (int)BlockSize; this.KdfEngine = (int)KdfEngine; }
/// <summary> /// CipherDescription constructor /// </summary> /// /// <param name="EngineType">The Cryptographic <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.SymmetricEngines">Engine</see> type</param> /// <param name="KeySize">The cipher Key Size in bytes</param> /// <param name="IvSize">Size of the cipher <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.IVSizes">Initialization Vector</see></param> /// <param name="CipherType">The type of <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.CipherModes">Cipher Mode</see></param> /// <param name="PaddingType">The type of cipher <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.PaddingModes">Padding Mode</see></param> /// <param name="BlockSize">The cipher <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.BlockSizes">Block Size</see></param> /// <param name="RoundCount">The number of diffusion <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.RoundCounts">Rounds</see></param> /// <param name="KdfEngine">The <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.Digests">Digest</see> digest engine used to power the key schedule Key Derivation Function</param> /// <param name="MacKeySize">The size of the HMAC key in bytes; a zeroed parameter means authentication is not enabled with this key</param> /// <param name="MacEngine">The HMAC <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.Digests">Digest</see> engine used to authenticate a message file encrypted with this key</param> /// /// <exception cref="System.ArgumentOutOfRangeException">Thrown if an invalid KeyId, MessageKey, or ExtensionKey is used</exception> public CipherDescription(SymmetricEngines EngineType, int KeySize, IVSizes IvSize, CipherModes CipherType, PaddingModes PaddingType, BlockSizes BlockSize, RoundCounts RoundCount, Digests KdfEngine = Digests.None, int MacKeySize = 0, Digests MacEngine = Digests.None) { this.EngineType = (int)EngineType; this.KeySize = KeySize; this.IvSize = (int)IvSize; this.CipherType = (int)CipherType; this.PaddingType = (int)PaddingType; this.BlockSize = (int)BlockSize; this.RoundCount = (int)RoundCount; this.KdfEngine = (int)KdfEngine; this.MacKeySize = MacKeySize; this.MacEngine = (int)MacEngine; }
private IBlockCipher GetCipher(BlockCiphers EngineType, Digests DigestType, RoundCounts Rounds, int BlockSize = 16) { switch (EngineType) { case BlockCiphers.Rijndael: return(new RHX(BlockSize, (int)Rounds, DigestType)); case BlockCiphers.Serpent: return(new SHX((int)Rounds, DigestType)); case BlockCiphers.Twofish: return(new THX((int)Rounds, DigestType)); } throw new Exception(); }
/// <summary> /// Create a single use Key file using a manual description of the cipher parameters. /// </summary> /// /// <param name="KeyParam">An initialized and populated key material container</param> /// <param name="EngineType">The Cryptographic <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.SymmetricEngines">Engine</see> type</param> /// <param name="KeySize">The cipher Key Size in bytes</param> /// <param name="IvSize">Size of the cipher <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.IVSizes">Initialization Vector</see></param> /// <param name="CipherType">The type of <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.CipherModes">Cipher Mode</see></param> /// <param name="PaddingType">The type of cipher <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.PaddingModes">Padding Mode</see></param> /// <param name="BlockSize">The cipher <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.BlockSizes">Block Size</see></param> /// <param name="Rounds">The number of diffusion <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.RoundCounts">Rounds</see></param> /// <param name="KdfEngine">The <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.Digests">Digest</see> engine used to power the key schedule Key Derivation Function in HX and M series ciphers</param> /// <param name="MacSize">The size of the HMAC message authentication code; a zeroed parameter means authentication is not enabled with this key</param> /// <param name="MacEngine">The HMAC <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.Digests">Digest</see> engine used to authenticate a message file encrypted with this key</param> /// /// <exception cref="System.ArgumentNullException">Thrown if a KeyParams member is null, but specified in the Header</exception> /// <exception cref="System.ArgumentOutOfRangeException">Thrown if a Header parameter does not match a KeyParams value</exception> public void Create(KeyParams KeyParam, SymmetricEngines EngineType, int KeySize, IVSizes IvSize, CipherModes CipherType, PaddingModes PaddingType, BlockSizes BlockSize, RoundCounts Rounds, Digests KdfEngine, int MacSize, Digests MacEngine) { CipherDescription dsc = new CipherDescription() { EngineType = (int)EngineType, KeySize = KeySize, IvSize = (int)IvSize, CipherType = (int)CipherType, PaddingType = (int)PaddingType, BlockSize = (int)BlockSize, RoundCount = (int)Rounds, KdfEngine = (int)KdfEngine, MacEngine = (int)MacEngine, MacKeySize = MacSize }; Create(dsc, KeyParam); }
/// <summary> /// Create a volume key file using a manual description of the cipher parameters. /// </summary> /// /// <param name="KeyCount">The number of key sets associated with this volume key</param> /// <param name="EngineType">The Cryptographic <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.SymmetricEngines">Engine</see> type</param> /// <param name="KeySize">The cipher Key Size in bytes</param> /// <param name="IvSize">Size of the cipher <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.IVSizes">Initialization Vector</see></param> /// <param name="CipherType">The type of <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.CipherModes">Cipher Mode</see></param> /// <param name="PaddingType">The type of cipher <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.PaddingModes">Padding Mode</see></param> /// <param name="BlockSize">The cipher <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.BlockSizes">Block Size</see></param> /// <param name="Rounds">The number of diffusion <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.RoundCounts">Rounds</see></param> /// <param name="KdfEngine">The <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.Digests">Digest</see> engine used to power the key schedule Key Derivation Function in HX and M series ciphers</param> /// <param name="MacSize">The size of the HMAC message authentication code; a zeroed parameter means authentication is not enabled with this key</param> /// <param name="MacEngine">The HMAC <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.Digests">Digest</see> engine used to authenticate a message file encrypted with this key</param> /// /// <returns>A populated VolumeKey</returns> public MemoryStream Create(int KeyCount, SymmetricEngines EngineType, int KeySize, IVSizes IvSize, CipherModes CipherType, PaddingModes PaddingType, BlockSizes BlockSize, RoundCounts Rounds, Digests KdfEngine, int MacSize, Digests MacEngine) { CipherDescription dsc = new CipherDescription() { EngineType = (int)EngineType, KeySize = KeySize, IvSize = (int)IvSize, CipherType = (int)CipherType, PaddingType = (int)PaddingType, BlockSize = (int)BlockSize, RoundCount = (int)Rounds, KdfEngine = (int)KdfEngine, MacEngine = (int)MacEngine, MacKeySize = MacSize }; return(Create(dsc, KeyCount)); }
/// <summary> /// Outputs expected values for 512 bit keys /// </summary> /// /// <returns>State</returns> public string Get512Vector(BlockCiphers EngineType, RoundCounts Rounds, int BlockSize = 16) { IBlockCipher engine = GetCipher(EngineType, Digests.None, Rounds, BlockSize); // rounds calc automatic int keyLen = 64; byte[] key = new byte[keyLen]; byte[] iv = new byte[engine.BlockSize]; ICipherMode cipher = new CTR(engine); for (int i = 0; i < keyLen; i++) { key[i] = (byte)i; } for (int i = 0; i < iv.Length; i++) { iv[i] = (byte)i; } cipher.Initialize(true, new KeyParams(key, iv)); return(MonteCarloTest(cipher)); }
/// <summary> /// Outputs expected values for the HX Ciphers /// </summary> /// /// <returns>State</returns> public string GetHXVector(BlockCiphers EngineType, Digests DigestType, RoundCounts Rounds) { IBlockCipher engine = GetCipher(EngineType, DigestType, Rounds); int keyLen = GetKeySize(engine); byte[] key = new byte[keyLen]; byte[] iv = new byte[engine.BlockSize]; ICipherMode cipher = new CTR(engine); for (int i = 0; i < keyLen; i++) { key[i] = (byte)i; } for (int i = 0; i < iv.Length; i++) { iv[i] = (byte)i; } cipher.Initialize(true, new KeyParams(key, iv)); return(MonteCarloTest(cipher)); }
/// <summary> /// SessionParams constructor /// </summary> /// /// <param name="EngineType">The Cryptographic <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.BlockCiphers">Engine</see> type</param> /// <param name="KeySize">The cipher Key Size in bytes</param> /// <param name="IvSize">Size of the cipher <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.IVSizes">Initialization Vector</see></param> /// <param name="RoundCount">The number of diffusion <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.RoundCounts">Rounds</see></param> /// <param name="KdfEngine">The <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.Digests">Digest</see> engine used to power the key schedule Key Derivation Function in HX and M series ciphers</param> /// /// <exception cref="System.ArgumentOutOfRangeException">Thrown if an invalid KeyId, MessageKey, or ExtensionKey is used</exception> public DtmSession(BlockCiphers EngineType = BlockCiphers.RDX, int KeySize = 32, IVSizes IvSize = IVSizes.V128, RoundCounts RoundCount = RoundCounts.R14, Digests KdfEngine = Digests.SHA512) { this.EngineType = (byte)EngineType; this.KeySize = (short)KeySize; this.IvSize = (byte)IvSize; this.RoundCount = (byte)RoundCount; this.KdfEngine = (byte)KdfEngine; }
/// <summary> /// Create a volume key file using a manual description of the cipher parameters. /// </summary> /// /// <param name="KeyCount">The number of key sets associated with this volume key</param> /// <param name="EngineType">The Cryptographic <see cref="SymmetricEngines">Engine</see> type</param> /// <param name="KeySize">The cipher Key Size in bytes</param> /// <param name="IvSize">Size of the cipher <see cref="IVSizes">Initialization Vector</see></param> /// <param name="CipherType">The type of <see cref="CipherModes">Cipher Mode</see></param> /// <param name="PaddingType">The type of cipher <see cref="PaddingModes">Padding Mode</see></param> /// <param name="BlockSize">The cipher <see cref="BlockSizes">Block Size</see></param> /// <param name="Rounds">The number of diffusion <see cref="RoundCounts">Rounds</see></param> /// <param name="KdfEngine">The <see cref="Digests">Digest</see> engine used to power the key schedule Key Derivation Function in HX and M series ciphers</param> /// <param name="MacSize">The size of the HMAC message authentication code; a zeroed parameter means authentication is not enabled with this key</param> /// <param name="MacEngine">The HMAC <see cref="Digests">Digest</see> engine used to authenticate a message file encrypted with this key</param> /// /// <exception cref="System.IO.FileLoadException">A key file exists at the path specified</exception> /// <exception cref="System.UnauthorizedAccessException">The key file path is read only</exception> public void Create(int KeyCount, SymmetricEngines EngineType, int KeySize, IVSizes IvSize, CipherModes CipherType, PaddingModes PaddingType, BlockSizes BlockSize, RoundCounts Rounds, Digests KdfEngine, int MacSize, Digests MacEngine) { CipherDescription dsc = new CipherDescription() { EngineType = (int)EngineType, KeySize = KeySize, IvSize = (int)IvSize, CipherType = (int)CipherType, PaddingType = (int)PaddingType, BlockSize = (int)BlockSize, RoundCount = (int)Rounds, KdfEngine = (int)KdfEngine, MacEngine = (int)MacEngine, MacSize = MacSize }; Create(dsc, KeyCount); }
/// <summary> /// DtmSessionStruct constructor /// </summary> /// /// <param name="EngineType">The Cryptographic <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.BlockCiphers">Engine</see> type</param> /// <param name="KeySize">The cipher Key Size in bytes</param> /// <param name="IvSize">Size of the cipher <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.IVSizes">Initialization Vector</see></param> /// <param name="RoundCount">The number of diffusion <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.RoundCounts">Rounds</see></param> /// <param name="KdfEngine">The <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.Digests">Digest</see> engine used to power the key schedule Key Derivation Function in HX and M series ciphers</param> /// /// <exception cref="System.ArgumentOutOfRangeException">Thrown if an invalid KeyId, MessageKey, or ExtensionKey is used</exception> public DtmSessionStruct(BlockCiphers EngineType = BlockCiphers.Rijndael, int KeySize = 32, IVSizes IvSize = IVSizes.V128, RoundCounts RoundCount = RoundCounts.R14, Digests KdfEngine = Digests.None) { this.EngineType = (byte)EngineType; this.KeySize = (short)KeySize; this.IvSize = (byte)IvSize; this.RoundCount = (byte)RoundCount; this.KdfEngine = (byte)KdfEngine; }
private int GetRoundsSize(string KeyPath) { this.RoundCount = KeyHeader.GetRoundCount(KeyPath); if (this.RoundCount == RoundCounts.R8) { return(8); } else if (this.RoundCount == RoundCounts.R10) { return(10); } else if (this.RoundCount == RoundCounts.R12) { return(12); } else if (this.RoundCount == RoundCounts.R14) { return(14); } else if (this.RoundCount == RoundCounts.R16) { return(16); } else if (this.RoundCount == RoundCounts.R18) { return(18); } else if (this.RoundCount == RoundCounts.R20) { return(20); } else if (this.RoundCount == RoundCounts.R22) { return(22); } else if (this.RoundCount == RoundCounts.R24) { return(24); } else if (this.RoundCount == RoundCounts.R26) { return(26); } else if (this.RoundCount == RoundCounts.R28) { return(28); } else if (this.RoundCount == RoundCounts.R30) { return(30); } else if (this.RoundCount == RoundCounts.R32) { return(32); } else if (this.RoundCount == RoundCounts.R34) { return(34); } else if (this.RoundCount == RoundCounts.R38) { return(38); } else if (this.RoundCount == RoundCounts.R40) { return(40); } else if (this.RoundCount == RoundCounts.R42) { return(42); } else if (this.RoundCount == RoundCounts.R48) { return(48); } else if (this.RoundCount == RoundCounts.R56) { return(56); } else if (this.RoundCount == RoundCounts.R64) { return(64); } else if (this.RoundCount == RoundCounts.R80) { return(80); } else if (this.RoundCount == RoundCounts.R96) { return(96); } else if (this.RoundCount == RoundCounts.R128) { return(128); } else { return(20); } }
private int GetRoundsSize(string KeyPath) { this.RoundCount = KeyHeader.GetRoundCount(KeyPath); if (this.RoundCount == RoundCounts.R8) return 8; else if (this.RoundCount == RoundCounts.R10) return 10; else if (this.RoundCount == RoundCounts.R12) return 12; else if (this.RoundCount == RoundCounts.R14) return 14; else if (this.RoundCount == RoundCounts.R16) return 16; else if (this.RoundCount == RoundCounts.R18) return 18; else if (this.RoundCount == RoundCounts.R20) return 20; else if (this.RoundCount == RoundCounts.R22) return 22; else if (this.RoundCount == RoundCounts.R24) return 24; else if (this.RoundCount == RoundCounts.R26) return 26; else if (this.RoundCount == RoundCounts.R28) return 28; else if (this.RoundCount == RoundCounts.R30) return 30; else if (this.RoundCount == RoundCounts.R32) return 32; else if (this.RoundCount == RoundCounts.R34) return 34; else if (this.RoundCount == RoundCounts.R38) return 38; else if (this.RoundCount == RoundCounts.R40) return 40; else if (this.RoundCount == RoundCounts.R42) return 42; else if (this.RoundCount == RoundCounts.R48) return 48; else if (this.RoundCount == RoundCounts.R56) return 56; else if (this.RoundCount == RoundCounts.R64) return 64; else if (this.RoundCount == RoundCounts.R80) return 80; else if (this.RoundCount == RoundCounts.R96) return 96; else if (this.RoundCount == RoundCounts.R128) return 128; else return 20; }
private void OnRoundsCountChanged(object sender, EventArgs e) { RoundCounts rcount = RoundCounts.R10; Enum.TryParse<RoundCounts>(((ComboBox)sender).Text, out rcount); _roundCount = rcount; }
/// <summary> /// Initialize the structure with parameters for an CMAC generator /// </summary> /// /// <param name="KeySize">The Mac key size in bytes</param> /// <param name="EngineType">The symmetric block cipher <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.SymmetricEngines">Engine</see> type</param> /// <param name="IvSize">Size of the cipher <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.IVSizes">Initialization Vector</see></param> /// <param name="BlockSize">The cipher <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.BlockSizes">Block Size</see></param> /// <param name="RoundCount">The number of diffusion <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.RoundCounts">Rounds</see></param> /// <param name="KdfEngine">The <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.Digests">Digest</see> engine used to power the key schedule Key Derivation Function in HX and M series ciphers</param> public MacDescription(int KeySize, BlockCiphers EngineType, IVSizes IvSize, BlockSizes BlockSize = BlockSizes.B128, RoundCounts RoundCount = RoundCounts.R14, Digests KdfEngine = Digests.SHA512) { MacType = (int)Macs.CMAC; this.KeySize = KeySize; this.IvSize = (int)IvSize; HmacEngine = 0; this.EngineType = (int)EngineType; this.BlockSize = (int)BlockSize; this.RoundCount = (int)RoundCount; this.KdfEngine = (int)KdfEngine; }
/// <summary> /// CipherDescription constructor /// </summary> /// /// <param name="EngineType">The Cryptographic <see cref="SymmetricEngines">Engine</see> type</param> /// <param name="KeySize">The cipher Key Size in bytes</param> /// <param name="IvSize">Size of the cipher <see cref="IVSizes">Initialization Vector</see></param> /// <param name="CipherType">The type of <see cref="CipherModes">Cipher Mode</see></param> /// <param name="PaddingType">The type of cipher <see cref="PaddingModes">Padding Mode</see></param> /// <param name="BlockSize">The cipher <see cref="BlockSizes">Block Size</see></param> /// <param name="RoundCount">The number of diffusion <see cref="RoundCounts">Rounds</see></param> /// <param name="KdfEngine">The <see cref="Digests">Digest</see> engine used to power the key schedule Key Derivation Function in HX and M series ciphers</param> /// <param name="MacSize">The size of the HMAC message authentication code; a zeroed parameter means authentication is not enabled with this key</param> /// <param name="MacEngine">The HMAC <see cref="Digests">Digest</see> engine used to authenticate a message file encrypted with this key</param> /// /// <exception cref="System.ArgumentOutOfRangeException">Thrown if an invalid KeyId, MessageKey, or ExtensionKey is used</exception> public CipherDescription(SymmetricEngines EngineType, int KeySize, IVSizes IvSize, CipherModes CipherType, PaddingModes PaddingType, BlockSizes BlockSize, RoundCounts RoundCount, Digests KdfEngine = Digests.SHA512, int MacSize = 64, Digests MacEngine = Digests.SHA512) { this.EngineType = (Int32)EngineType; this.KeySize = KeySize; this.IvSize = (Int32)IvSize; this.CipherType = (Int32)CipherType; this.PaddingType = (Int32)PaddingType; this.BlockSize = (Int32)BlockSize; this.RoundCount = (Int32)RoundCount; this.KdfEngine = (Int32)KdfEngine; this.MacSize = MacSize; this.MacEngine = (Int32)MacEngine; }