예제 #1
0
 /// <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;
 }
예제 #2
0
 /// <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;
 }
예제 #3
0
        private int GetIvSize(string KeyPath)
        {
            IVSizes ivSize = KeyHeader.GetIvSize(KeyPath);

            if (ivSize == IVSizes.V128)
            {
                return(16);
            }
            else if (ivSize == IVSizes.V256)
            {
                return(32);
            }
            else
            {
                return(8);
            }
        }
예제 #4
0
 /// <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;
 }
예제 #5
0
        /// <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);
        }
예제 #6
0
        /// <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);
        }
예제 #7
0
 /// <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;
 }
예제 #8
0
        /// <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));
        }
예제 #9
0
 /// <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;
 }