Exemplo n.º 1
0
        public static double[] Run(ImplementationType implType, string mode, int keySize, int blockSize, int dataSize, int threads)
        {
            double[] result;
            int      totalBlocks = dataSize / (blockSize >> 3);

            byte[] key  = new byte [keySize >> 3];
            byte[] iv   = new byte [blockSize >> 3];
            object algo = Helper.CreateInstance(implType);

            do
            {
                SymmetricAlgorithmPlus sap = algo as SymmetricAlgorithmPlus;
                if (sap != null)
                {
                    sap.NumberOfThreads = threads;
                    sap.ModePlus        = (CipherModePlus)Enum.Parse(typeof(CipherModePlus), mode);
                    result = Run(sap, key, iv, totalBlocks);
                    break;
                }
                SymmetricAlgorithm sa = algo as SymmetricAlgorithm;
                if (sa != null)
                {
                    sa.Mode = (CipherMode)Enum.Parse(typeof(CipherMode), mode);
                    result  = Run(sa, key, iv, totalBlocks);
                    break;
                }
                result = Run(algo as IBlockCipher, mode, key, iv, totalBlocks);
            } while (false);

            for (int i = 0; i < result.Length; i++)
            {
                result[i] = dataSize * 8.0 / result[i] / (1024.0 * 1024.0);
            }
            return(result);
        }
Exemplo n.º 2
0
        void EncryptionThread(object instance)
        {
            DateTime start = DateTime.Now;

            instance = Helper.CreateInstance(_implType);
            int totalBlocks = _dataSize / (_blockSize >> 3);
            int unitBlocks  = 1024 * 1024 * 2 / (_blockSize >> 3);

            byte[] key   = new byte[_keySize >> 3];
            byte[] iv    = new byte[_blockSize >> 3];
            byte[] data1 = new byte[unitBlocks * (_blockSize >> 3)];
            byte[] data2 = new byte[unitBlocks * (_blockSize >> 3)];
            Invoke(new SetProgressbarDelegate(SetProgressbarMax), totalBlocks);

            SymmetricAlgorithm     algo    = instance as SymmetricAlgorithm;
            SymmetricAlgorithmPlus algo2   = instance as SymmetricAlgorithmPlus;
            IBlockCipher           bc      = instance as IBlockCipher;
            SetProgressbarDelegate setprog = new SetProgressbarDelegate(SetProgressbarValue);
            int step = unitBlocks;

            if (algo2 != null)
            {
                algo2.NumberOfThreads = _threads;
            }
            if (algo != null)
            {
                algo.Mode = CipherMode.ECB;
            }
            if (bc != null)
            {
                bc.Init(true, new KeyParameter(key));
            }

            if (algo != null)
            {
                using (ICryptoTransform ct = algo.CreateEncryptor(key, iv)) {
                    for (int i = 0; i <= totalBlocks - step; i += step)
                    {
                        ct.TransformBlock(data1, 0, data1.Length, data2, 0);
                        Invoke(setprog, i);
                    }
                }
            }
            else if (bc != null)
            {
                for (int i = 0; i < totalBlocks; i += step)
                {
                    for (int q = 0; q < unitBlocks; q++)
                    {
                        bc.ProcessBlock(data1, q * iv.Length, data2, q * iv.Length);
                    }
                    Invoke(setprog, i);
                }
            }
            TimeSpan span = DateTime.Now.Subtract(start);

            Invoke(setprog, totalBlocks);
            Invoke(new SetTextDelegate(SetText), label1, Helper.ToName(_implType) + " - Time: " + span.ToString());
        }
Exemplo n.º 3
0
        public void Start()
        {
            DateTime start       = DateTime.Now;
            object   instance    = Helper.CreateInstance(_implType);
            int      totalBlocks = _dataSize / (_blockSize >> 3);

            byte[]                 key   = new byte[_keySize >> 3];
            byte[]                 iv    = new byte[_blockSize >> 3];
            byte[]                 data1 = new byte[_dataSize];
            byte[]                 data2 = new byte[_dataSize];
            SymmetricAlgorithm     algo  = instance as SymmetricAlgorithm;
            SymmetricAlgorithmPlus algo2 = instance as SymmetricAlgorithmPlus;
            IBlockCipher           bc    = instance as IBlockCipher;
            int step = iv.Length;

            if (algo2 != null)
            {
                algo2.NumberOfThreads = _threads;
            }
            if (algo != null)
            {
                algo.Mode = CipherMode.ECB;
            }
            if (bc != null)
            {
                bc.Init(true, new KeyParameter(key));
            }

            Stopwatch sw = new Stopwatch();

            sw.Reset();
            sw.Start();
            if (algo != null)
            {
                using (ICryptoTransform ct = algo.CreateEncryptor(key, iv)) {
                    ct.TransformBlock(data1, 0, data1.Length, data2, 0);
                }
            }
            else if (bc != null)
            {
                for (int i = 0, q = 0; i < totalBlocks; i++, q += step)
                {
                    bc.ProcessBlock(data1, q, data2, q);
                }
            }
            sw.Stop();

            _speed      = _dataSize * 8.0 / sw.Elapsed.TotalSeconds / (1024.0 * 1024.0);
            label1.Text = Helper.ToName(_implType) + " - ‘¬“x: " + _speed.ToString("f2") + " Mbps";
        }
Exemplo n.º 4
0
        public static uint[] Run(ImplementationType implType, int keySize, int blockSize)
        {
            byte[] key  = new byte [keySize >> 3];
            byte[] iv   = new byte [blockSize >> 3];
            object algo = Helper.CreateInstance(implType);
            SymmetricAlgorithmPlus sap = algo as SymmetricAlgorithmPlus;

            if (sap != null)
            {
                return(Run(sap, key, iv));
            }
            SymmetricAlgorithm sa = algo as SymmetricAlgorithm;

            if (sa != null)
            {
                return(Run(sa, key, iv));
            }
            return(Run(algo as IBlockCipher, key, iv));
        }