コード例 #1
0
        static uint[] Run(IBlockCipher algo, byte[] key, byte[] iv)
        {
            IBlockCipher     cipher = new Org.BouncyCastle.Crypto.Modes.CbcBlockCipher(algo);
            ParametersWithIV param  = new ParametersWithIV(new KeyParameter(key), iv);
            Stopwatch        sw     = new Stopwatch();

            uint[] result = new uint[2];
            sw.Reset(); sw.Start();
            for (int i = 0; i < LOOP; i++)
            {
                cipher.Init(true, param);
                cipher.Reset();
            }
            sw.Stop();
            result[0] = (uint)(LOOP / sw.Elapsed.TotalSeconds);

            sw.Reset(); sw.Start();
            for (int i = 0; i < LOOP; i++)
            {
                cipher.Init(false, param);
                cipher.Reset();
            }
            sw.Stop();
            result[1] = (uint)(LOOP / sw.Elapsed.TotalSeconds);

            return(result);
        }
コード例 #2
0
ファイル: SpeedTest.cs プロジェクト: kazuki/opencrypto.net
        static IBlockCipher Setup(IBlockCipher algo, string mode, bool encryption, byte[] key, byte[] iv)
        {
            if (mode == "ECB")
            {
                algo.Init(encryption, new KeyParameter(key));
                return(algo);
            }
            IBlockCipher cipher = null;

            if (mode == "CBC")
            {
                cipher = new Org.BouncyCastle.Crypto.Modes.CbcBlockCipher(algo);
            }
            if (mode == "CFB")
            {
                cipher = new Org.BouncyCastle.Crypto.Modes.CfbBlockCipher(algo, iv.Length << 3);
            }
            if (mode == "OFB")
            {
                cipher = new Org.BouncyCastle.Crypto.Modes.OfbBlockCipher(algo, iv.Length);
            }
            if (cipher != null)
            {
                cipher.Init(encryption, new ParametersWithIV(new KeyParameter(key), iv));
                return(cipher);
            }
            throw new ArgumentException();
        }
コード例 #3
0
		static uint[] Run (IBlockCipher algo, byte[] key, byte[] iv)
		{
			IBlockCipher cipher = new Org.BouncyCastle.Crypto.Modes.CbcBlockCipher (algo);
			ParametersWithIV param = new ParametersWithIV (new KeyParameter (key), iv);
			Stopwatch sw = new Stopwatch ();
			uint[] result = new uint[2];
			sw.Reset (); sw.Start ();
			for (int i = 0; i < LOOP; i++) {
				cipher.Init (true, param);
				cipher.Reset ();
			}
			sw.Stop ();
			result[0] = (uint)(LOOP / sw.Elapsed.TotalSeconds);

			sw.Reset (); sw.Start ();
			for (int i = 0; i < LOOP; i++) {
				cipher.Init (false, param);
				cipher.Reset ();
			}
			sw.Stop ();
			result[1] = (uint)(LOOP / sw.Elapsed.TotalSeconds);

			return result;
		}
コード例 #4
0
ファイル: SpeedTest.cs プロジェクト: kazuki/opencrypto.net
		static IBlockCipher Setup (IBlockCipher algo, string mode, bool encryption, byte[] key, byte[] iv)
		{
			if (mode == "ECB") {
				algo.Init (encryption, new KeyParameter (key));
				return algo;
			}
			IBlockCipher cipher = null;
			if (mode == "CBC") cipher = new Org.BouncyCastle.Crypto.Modes.CbcBlockCipher (algo);
			if (mode == "CFB") cipher = new Org.BouncyCastle.Crypto.Modes.CfbBlockCipher (algo, iv.Length << 3);
			if (mode == "OFB") cipher = new Org.BouncyCastle.Crypto.Modes.OfbBlockCipher (algo, iv.Length);
			if (cipher != null) {
				cipher.Init (encryption, new ParametersWithIV (new KeyParameter (key), iv));
				return cipher;
			}
			throw new ArgumentException ();
		}