Пример #1
0
        private void OnEngineChanged(object sender, EventArgs e)
        {
            SymmetricEngines engine = _engineDescriptions[((ComboBox)sender).Text];

            SetComboParams(engine);
            this._engineType = engine;
        }
Пример #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
        /// <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>
        ///
        /// <returns>A populated VolumeKey</returns>
        public MemoryStream CreateKey(int KeyCount, SymmetricEngines EngineType, int KeySize, IVSizes IvSize,
                                      CipherModes CipherType, PaddingModes PaddingType, BlockSizes BlockSize, RoundCounts Rounds, Digests KdfEngine)
        {
            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,
            };

            return(CreateKey(dsc, KeyCount));
        }
Пример #4
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);
        }
Пример #5
0
 private bool IsStreamCipher(SymmetricEngines EngineType)
 {
     return EngineType == SymmetricEngines.ChaCha ||
         EngineType == SymmetricEngines.Salsa ||
         EngineType == SymmetricEngines.Fusion;
 }
Пример #6
0
 private IStreamCipher GetStreamEngine(SymmetricEngines EngineType, int RoundCount, Digests KdfEngine)
 {
     if (EngineType == SymmetricEngines.ChaCha)
         return new ChaCha(RoundCount);
     else if (EngineType == SymmetricEngines.Fusion)
         return new Fusion(RoundCount, KdfEngine);
     else if (EngineType == SymmetricEngines.Salsa)
         return new Salsa20(RoundCount);
     else
         return null;
 }
Пример #7
0
 private ICipherMode GetCipher(CipherModes CipherType, SymmetricEngines EngineType, int RoundCount, int BlockSize, Digests KdfEngine)
 {
     if (CipherType == CipherModes.CBC)
         return new CBC(GetBlockEngine(EngineType, RoundCount, BlockSize, KdfEngine));
     else if (CipherType == CipherModes.CFB)
         return new CFB(GetBlockEngine(EngineType, RoundCount, BlockSize, KdfEngine), BlockSize * 8);
     else if (CipherType == CipherModes.OFB)
         return new OFB(GetBlockEngine(EngineType, RoundCount, BlockSize, KdfEngine));
     else
         return new CTR(GetBlockEngine(EngineType, RoundCount, BlockSize, KdfEngine));
 }
Пример #8
0
 private IBlockCipher GetBlockEngine(SymmetricEngines EngineType, int RoundCount, int BlockSize, Digests KdfEngine)
 {
     if (EngineType == SymmetricEngines.RDX)
         return new RDX(BlockSize);
     else if (EngineType == SymmetricEngines.RHX)
         return new RHX(RoundCount, BlockSize, KdfEngine);
     else if (EngineType == SymmetricEngines.RSM)
         return new RSM(RoundCount, BlockSize, KdfEngine);
     else if (EngineType == SymmetricEngines.SHX)
         return new SHX(RoundCount, KdfEngine);
     else if (EngineType == SymmetricEngines.SPX)
         return new SPX(RoundCount);
     else if (EngineType == SymmetricEngines.TFX)
         return new TFX(RoundCount);
     else if (EngineType == SymmetricEngines.THX)
         return new THX(RoundCount, KdfEngine);
     else if (EngineType == SymmetricEngines.TSM)
         return new TSM(RoundCount, KdfEngine);
     else
         return new RHX(RoundCount, BlockSize, KdfEngine);
 }
Пример #9
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);
        }
Пример #10
0
        private void SetComboParams(SymmetricEngines Engine)
        {
            cbCipherMode.Enabled = true;
            cbKeySize.Enabled    = true;
            cbKeySize.Items.Clear();
            cbRounds.Enabled = true;
            cbRounds.Items.Clear();

            switch (Engine)
            {
            case SymmetricEngines.ChaCha:
            case SymmetricEngines.Salsa:
                cbCipherMode.Enabled = false;
                cbKeySize.Items.Add(KeySizes.K128);
                cbKeySize.Items.Add(KeySizes.K256);
                ComboHelper.SetSelectedIndex(cbKeySize, 1);
                ComboHelper.AddEnumRange(cbRounds, typeof(RoundCounts), 8, 30);
                ComboHelper.SetSelectedIndex(cbRounds, 6);
                break;

            case SymmetricEngines.RHX:
                ComboHelper.SetSelectedIndex(cbEngines, 0);
                cbKeySize.Items.Clear();
                cbKeySize.Items.Add(KeySizes.K128);
                cbKeySize.Items.Add(KeySizes.K192);
                cbKeySize.Items.Add(KeySizes.K256);
                cbKeySize.Items.Add(KeySizes.K512);
                ComboHelper.SetSelectedIndex(cbKeySize, 2);
                ComboHelper.AddEnumRange(cbRounds, typeof(RoundCounts), 10, 38);
                ComboHelper.SetSelectedIndex(cbRounds, 2);
                break;

            case SymmetricEngines.SHX:
                cbKeySize.Items.Add(KeySizes.K128);
                cbKeySize.Items.Add(KeySizes.K192);
                cbKeySize.Items.Add(KeySizes.K256);
                cbKeySize.Items.Add(KeySizes.K512);
                ComboHelper.SetSelectedIndex(cbKeySize, 2);
                cbRounds.Items.Add(RoundCounts.R32);
                cbRounds.Items.Add(RoundCounts.R40);
                cbRounds.Items.Add(RoundCounts.R48);
                cbRounds.Items.Add(RoundCounts.R56);
                cbRounds.Items.Add(RoundCounts.R64);
                ComboHelper.SetSelectedIndex(cbRounds, 0);
                break;

            case SymmetricEngines.THX:
                cbKeySize.Items.Add(KeySizes.K128);
                cbKeySize.Items.Add(KeySizes.K192);
                cbKeySize.Items.Add(KeySizes.K256);
                cbKeySize.Items.Add(KeySizes.K512);
                ComboHelper.SetSelectedIndex(cbKeySize, 2);
                ComboHelper.AddEnumRange(cbRounds, typeof(RoundCounts), 16, 32);
                ComboHelper.SetSelectedIndex(cbRounds, 0);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            SetRounds();
        }
Пример #11
0
        private void SetKeySizes(SymmetricEngines CipherEngine, Digests KdfEngine)
        {
            cbKeySize.Items.Clear();

            if (CipherEngine == SymmetricEngines.Fusion ||
                CipherEngine == SymmetricEngines.RHX ||
                CipherEngine == SymmetricEngines.RSM ||
                CipherEngine == SymmetricEngines.SHX ||
                CipherEngine == SymmetricEngines.TSM ||
                CipherEngine == SymmetricEngines.THX)
            {
                cbHkdf.Enabled = true;

                switch (KdfEngine)
                {
                    case Digests.Blake256:
                    case Digests.Skein256:
                        cbKeySize.Items.Add(KeySizes.K512);
                        cbKeySize.Items.Add(KeySizes.K768);
                        cbKeySize.Items.Add(KeySizes.K1024);
                        cbKeySize.Items.Add(KeySizes.K1280);
                        break;
                    case Digests.SHA256:
                        cbKeySize.Items.Add(KeySizes.K768);
                        cbKeySize.Items.Add(KeySizes.K1280);
                        cbKeySize.Items.Add(KeySizes.K1792);
                        cbKeySize.Items.Add(KeySizes.K2304);
                        break;
                    case Digests.Blake512:
                    case Digests.Skein512:
                        cbKeySize.Items.Add(KeySizes.K1024);
                        cbKeySize.Items.Add(KeySizes.K1536);
                        cbKeySize.Items.Add(KeySizes.K2048);
                        cbKeySize.Items.Add(KeySizes.K2560);
                        break;
                    case Digests.Keccak512:
                        cbKeySize.Items.Add(KeySizes.K1088);
                        cbKeySize.Items.Add(KeySizes.K1664);
                        cbKeySize.Items.Add(KeySizes.K2240);
                        cbKeySize.Items.Add(KeySizes.K2816);
                        break;
                    case Digests.SHA512:
                        cbKeySize.Items.Add(KeySizes.K1536);
                        cbKeySize.Items.Add(KeySizes.K2560);
                        cbKeySize.Items.Add(KeySizes.K3584);
                        cbKeySize.Items.Add(KeySizes.K4608);
                        break;
                    case Digests.Skein1024:
                        cbKeySize.Items.Add(KeySizes.K2048);
                        cbKeySize.Items.Add(KeySizes.K3072);
                        cbKeySize.Items.Add(KeySizes.K4096);
                        cbKeySize.Items.Add(KeySizes.K5120);
                        break;
                }
            }
            else if (CipherEngine == SymmetricEngines.RDX ||
                CipherEngine == SymmetricEngines.SPX ||
                CipherEngine == SymmetricEngines.TFX)
            {
                cbHkdf.Enabled = false;
                cbKeySize.Items.Add(KeySizes.K128);
                cbKeySize.Items.Add(KeySizes.K256);
                cbKeySize.Items.Add(KeySizes.K512);
            }
            else if (CipherEngine == SymmetricEngines.ChaCha ||
                CipherEngine == SymmetricEngines.Salsa)
            {
                cbHkdf.Enabled = false;
                cbKeySize.Items.Add(KeySizes.K128);
                cbKeySize.Items.Add(KeySizes.K256);
                cbKeySize.Items.Add(KeySizes.K384);
                cbKeySize.Items.Add(KeySizes.K448);
            }

            ComboHelper.SetSelectedIndex(cbKeySize, 1);
        }
Пример #12
0
 private bool IsStreamCipher(SymmetricEngines EngineType)
 {
     return(EngineType == SymmetricEngines.ChaCha ||
            EngineType == SymmetricEngines.Salsa);
 }
Пример #13
0
        private void SetComboParams(SymmetricEngines Engine)
        {
            cbCipherMode.Enabled = true;
            cbKeySize.Enabled = true;
            cbKeySize.Items.Clear();
            cbRounds.Enabled = true;
            cbRounds.Items.Clear();

            switch (Engine)
            {
                case SymmetricEngines.ChaCha:
                case SymmetricEngines.Salsa:
                    cbCipherMode.Enabled = false;
                    cbKeySize.Items.Add(KeySizes.K128);
                    cbKeySize.Items.Add(KeySizes.K256);
                    cbKeySize.Items.Add(KeySizes.K384);
                    cbKeySize.Items.Add(KeySizes.K448);
                    ComboHelper.SetSelectedIndex(cbKeySize, 1);
                    ComboHelper.AddEnumRange(cbRounds, typeof(RoundCounts), 8, 30);
                    ComboHelper.SetSelectedIndex(cbRounds, 6);
                    break;
                case SymmetricEngines.RDX:
                    cbRounds.Enabled = false;
                    cbKeySize.Items.Add(KeySizes.K128);
                    cbKeySize.Items.Add(KeySizes.K256);
                    cbKeySize.Items.Add(KeySizes.K512);
                    ComboHelper.SetSelectedIndex(cbKeySize, 1);
                    break;
                case SymmetricEngines.RHX:
                    ComboHelper.SetSelectedIndex(cbEngines, 3);
                    ComboHelper.AddEnumRange(cbKeySize, typeof(KeySizes), 192, 576);
                    ComboHelper.SetSelectedIndex(cbKeySize, 0);
                    ComboHelper.AddEnumRange(cbRounds, typeof(RoundCounts), 10, 38);
                    ComboHelper.SetSelectedIndex(cbRounds, 2);
                    break;
                case SymmetricEngines.RSM:
                    ComboHelper.AddEnumRange(cbKeySize, typeof(KeySizes), 192, 576);
                    ComboHelper.SetSelectedIndex(cbKeySize, 0);
                    cbRounds.Items.Add(RoundCounts.R10);
                    cbRounds.Items.Add(RoundCounts.R18);
                    cbRounds.Items.Add(RoundCounts.R26);
                    cbRounds.Items.Add(RoundCounts.R34);
                    cbRounds.Items.Add(RoundCounts.R42);
                    ComboHelper.SetSelectedIndex(cbRounds, 1);
                    break;
                case SymmetricEngines.SHX:
                    ComboHelper.AddEnumRange(cbKeySize, typeof(KeySizes), 192, 576);
                    ComboHelper.SetSelectedIndex(cbKeySize, 0);
                    cbRounds.Items.Add(RoundCounts.R32);
                    cbRounds.Items.Add(RoundCounts.R40);
                    cbRounds.Items.Add(RoundCounts.R48);
                    cbRounds.Items.Add(RoundCounts.R56);
                    cbRounds.Items.Add(RoundCounts.R64);
                    ComboHelper.SetSelectedIndex(cbRounds, 0);
                    break;
                case SymmetricEngines.SPX:
                    ComboHelper.AddEnumRange(cbKeySize, typeof(KeySizes), 16, 64);
                    ComboHelper.SetSelectedIndex(cbKeySize, 2);
                    cbRounds.Items.Add(RoundCounts.R32);
                    cbRounds.Items.Add(RoundCounts.R40);
                    cbRounds.Items.Add(RoundCounts.R48);
                    cbRounds.Items.Add(RoundCounts.R56);
                    cbRounds.Items.Add(RoundCounts.R64);
                    ComboHelper.SetSelectedIndex(cbRounds, 0);
                    break;
                case SymmetricEngines.TFX:
                    cbKeySize.Items.Add(KeySizes.K128);
                    cbKeySize.Items.Add(KeySizes.K256);
                    cbKeySize.Items.Add(KeySizes.K512);
                    ComboHelper.SetSelectedIndex(cbKeySize, 1);
                    ComboHelper.AddEnumRange(cbRounds, typeof(RoundCounts), 16, 32);
                    ComboHelper.SetSelectedIndex(cbRounds, 0);
                    break;
                default:
                    ComboHelper.AddEnumRange(cbKeySize, typeof(KeySizes), 192, 576);
                    ComboHelper.SetSelectedIndex(cbKeySize, 0);
                    ComboHelper.AddEnumRange(cbRounds, typeof(RoundCounts), 16, 32);
                    ComboHelper.SetSelectedIndex(cbRounds, 0);
                    break;
            }
        }
Пример #14
0
 private void OnEngineChanged(object sender, EventArgs e)
 {
     SymmetricEngines engine = _engineDescriptions[((ComboBox)sender).Text];
     SetComboParams(engine);
     this._engineType = engine;
 }
Пример #15
0
        public EngineSpeedTest(SymmetricEngines Engine, CipherModes Mode, int DataSize, int KeySize, int Rounds, bool Encryption, bool Parallel, TestTypes TestType = TestTypes.FileIO)
        {
            _cipherType   = Mode;
            _dataSize     = DataSize;
            _roundCount   = Rounds;
            _engineType   = Engine;
            _isEncryption = Encryption;
            _isParallel   = Parallel;
            _keySize      = KeySize;
            _keyParam     = GetKeyParams();
            _testType     = TestType;

            if (IsStreamCipher())
            {
                _streamCipher = GetStreamEngine();
                _streamCipher.Initialize(_keyParam);

                if (_isParallel && _engineType == SymmetricEngines.ChaCha || _engineType == SymmetricEngines.Salsa)
                {
                    if (_dataSize > MB100)
                    {
                        _blockSize = MB100;
                    }
                    else if (DataSize > MB10)
                    {
                        _blockSize = MB10;
                    }
                    else if (DataSize > MB1)
                    {
                        _blockSize = MB1;
                    }
                    else
                    {
                        _blockSize = 1024;
                    }

                    // align block
                    if (_isParallel)
                    {
                        _blockSize -= (_blockSize % (64 * Environment.ProcessorCount));
                    }
                }
                else
                {
                    _blockSize = 64000;
                }
            }
            else
            {
                _cipherEngine = GetCipher();
                _cipherEngine.Initialize(_isEncryption, _keyParam);

                // set parallel
                if (_cipherEngine.GetType().Equals(typeof(CTR)))
                {
                    ((CTR)_cipherEngine).IsParallel = _isParallel;
                }
                else if (_cipherEngine.GetType().Equals(typeof(CBC)))
                {
                    ((CBC)_cipherEngine).IsParallel = _isParallel;
                }
                else if (_cipherEngine.GetType().Equals(typeof(CFB)))
                {
                    ((CFB)_cipherEngine).IsParallel = _isParallel;
                }

                // set block
                if (_isParallel && (_cipherType.Equals(CipherModes.CTR) ||
                                    _cipherType.Equals(CipherModes.CBC) && !_isEncryption ||
                                    _cipherType.Equals(CipherModes.CFB) && !_isEncryption))
                {
                    if (_dataSize > MB100)
                    {
                        _blockSize = MB100;
                    }
                    else if (DataSize > MB10)
                    {
                        _blockSize = MB10;
                    }
                    else if (DataSize > MB1)
                    {
                        _blockSize = MB1;
                    }
                    else
                    {
                        _blockSize = 1024;
                    }

                    // align block
                    if (_isParallel)
                    {
                        _blockSize -= (_blockSize % (16 * Environment.ProcessorCount));
                    }

                    if (_cipherEngine.GetType().Equals(typeof(CTR)))
                    {
                        ((CTR)_cipherEngine).ParallelBlockSize = _blockSize;
                    }
                    else if (_cipherEngine.GetType().Equals(typeof(CBC)))
                    {
                        ((CBC)_cipherEngine).ParallelBlockSize = _blockSize;
                    }
                    else if (_cipherEngine.GetType().Equals(typeof(CFB)))
                    {
                        ((CFB)_cipherEngine).ParallelBlockSize = _blockSize;
                    }
                }
                else
                {
                    _blockSize = _cipherEngine.BlockSize;
                }
            }

            _inputBuffer  = new byte[_blockSize];
            _outputBuffer = new byte[_blockSize];
        }
Пример #16
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;
 }
Пример #17
0
        public EngineSpeedTest(SymmetricEngines Engine, CipherModes Mode, int DataSize, int KeySize, int Rounds, bool Encryption, bool Parallel, TestTypes TestType = TestTypes.FileIO)
        {
            _cipherType = Mode;
            _dataSize = DataSize;
            _roundCount = Rounds;
            _engineType = Engine;
            _isEncryption = Encryption;
            _isParallel = Parallel;
            _keySize = KeySize;
            _keyParam = GetKeyParams();
            _testType = TestType;

            if (IsStreamCipher())
            {
                _streamCipher = GetStreamEngine();
                _streamCipher.Initialize(_keyParam);

                if (_isParallel && _engineType == SymmetricEngines.Fusion || _engineType == SymmetricEngines.Salsa)
                {
                    if (_dataSize > MB100)
                        _blockSize = MB100;
                    else if (DataSize > MB10)
                        _blockSize = MB10;
                    else if (DataSize > MB1)
                        _blockSize = MB1;
                    else
                        _blockSize = 1024;
                }
                else
                {
                    _blockSize = 64000;
                }
            }
            else
            {
                _cipherEngine = GetCipher();
                _cipherEngine.Initialize(_isEncryption, _keyParam);

                // set parallel
                if (_cipherEngine.GetType().Equals(typeof(CTR)))
                    ((CTR)_cipherEngine).IsParallel = _isParallel;
                else if (_cipherEngine.GetType().Equals(typeof(CBC)))
                    ((CBC)_cipherEngine).IsParallel = _isParallel;
                else if (_cipherEngine.GetType().Equals(typeof(CFB)))
                    ((CFB)_cipherEngine).IsParallel = _isParallel;

                // set block
                if (_isParallel && (_cipherType.Equals(CipherModes.CTR) ||
                    _cipherType.Equals(CipherModes.CBC) && !_isEncryption ||
                    _cipherType.Equals(CipherModes.CFB) && !_isEncryption))
                {
                    if (_dataSize > MB100)
                        _blockSize = MB100;
                    else if (DataSize > MB10)
                        _blockSize = MB10;
                    else if (DataSize > MB1)
                        _blockSize = MB1;
                    else
                        _blockSize = 1024;

                    if (_cipherEngine.GetType().Equals(typeof(CTR)))
                        ((CTR)_cipherEngine).ParallelBlockSize = _blockSize;
                    else if (_cipherEngine.GetType().Equals(typeof(CBC)))
                        ((CBC)_cipherEngine).ParallelBlockSize = _blockSize;
                    else if (_cipherEngine.GetType().Equals(typeof(CFB)))
                        ((CFB)_cipherEngine).ParallelBlockSize = _blockSize;
                }
                else
                {
                    _blockSize = _cipherEngine.BlockSize;
                }
            }

            _inputBuffer = new byte[_blockSize];
            _outputBuffer = new byte[_blockSize];
        }
Пример #18
0
        private void SetComboParams(SymmetricEngines Engine)
        {
            cbCipherMode.Enabled = true;
            cbPaddingMode.Enabled = true;
            cbRounds.Enabled = true;
            cbVectorSize.Enabled = true;
            cbRounds.Items.Clear();
            cbVectorSize.Items.Clear();
            cbVectorSize.Items.Add(IVSizes.V128);
            cbVectorSize.SelectedIndex = 0;

            switch (Engine)
            {
                case SymmetricEngines.ChaCha:
                case SymmetricEngines.Salsa:
                    cbCipherMode.Enabled = false;
                    cbPaddingMode.Enabled = false;
                    ComboHelper.AddEnumRange(cbRounds, typeof(RoundCounts), 8, 30);
                    ComboHelper.SetSelectedIndex(cbRounds, 6);
                    cbVectorSize.Items.Clear();
                    cbVectorSize.Items.Add(IVSizes.V64);
                    cbVectorSize.SelectedIndex = 0;
                    break;
                case SymmetricEngines.Fusion:
                    cbCipherMode.Enabled = false;
                    cbPaddingMode.Enabled = false;
                    ComboHelper.AddEnumRange(cbRounds, typeof(RoundCounts), 16, 32);
                    ComboHelper.SetSelectedIndex(cbRounds, 0);
                    break;
                case SymmetricEngines.RDX:
                    cbRounds.Enabled = false;
                    cbVectorSize.Items.Add(IVSizes.V256);
                    cbVectorSize.SelectedIndex = 0;
                    break;
                case SymmetricEngines.RHX:
                    ComboHelper.AddEnumRange(cbRounds, typeof(RoundCounts), 10, 38);
                    ComboHelper.SetSelectedIndex(cbRounds, 2);
                    cbVectorSize.Items.Add(IVSizes.V256);
                    cbVectorSize.SelectedIndex = 0;
                    break;
                case SymmetricEngines.RSM:
                    cbRounds.Items.Add(RoundCounts.R10);
                    cbRounds.Items.Add(RoundCounts.R18);
                    cbRounds.Items.Add(RoundCounts.R26);
                    cbRounds.Items.Add(RoundCounts.R34);
                    cbRounds.Items.Add(RoundCounts.R42);
                    ComboHelper.SetSelectedIndex(cbRounds, 1);
                    cbVectorSize.Items.Add(IVSizes.V256);
                    cbVectorSize.SelectedIndex = 0;
                    break;
                case SymmetricEngines.SHX:
                    cbRounds.Items.Add(RoundCounts.R32);
                    cbRounds.Items.Add(RoundCounts.R40);
                    cbRounds.Items.Add(RoundCounts.R48);
                    cbRounds.Items.Add(RoundCounts.R56);
                    cbRounds.Items.Add(RoundCounts.R64);
                    ComboHelper.SetSelectedIndex(cbRounds, 0);
                    break;
                case SymmetricEngines.SPX:
                    cbRounds.Items.Add(RoundCounts.R32);
                    cbRounds.Items.Add(RoundCounts.R40);
                    cbRounds.Items.Add(RoundCounts.R48);
                    cbRounds.Items.Add(RoundCounts.R56);
                    cbRounds.Items.Add(RoundCounts.R64);
                    ComboHelper.SetSelectedIndex(cbRounds, 0);
                    break;
                case SymmetricEngines.TFX:
                    ComboHelper.AddEnumRange(cbRounds, typeof(RoundCounts), 16, 32);
                    ComboHelper.SetSelectedIndex(cbRounds, 0);
                    break;
                case SymmetricEngines.TSM:
                    cbRounds.Items.Add(RoundCounts.R16);
                    cbRounds.Items.Add(RoundCounts.R24);
                    cbRounds.Items.Add(RoundCounts.R32);
                    ComboHelper.SetSelectedIndex(cbRounds, 0);
                    break;
                default:
                    ComboHelper.AddEnumRange(cbRounds, typeof(RoundCounts), 16, 32);
                    ComboHelper.SetSelectedIndex(cbRounds, 0);
                    break;
            }
        }