Exemplo n.º 1
0
        public SymmetricTransform(SymmetricAlgorithmPlus algo, bool encryptMode, byte[] iv)
        {
            _algo          = algo;
            _blockBytes    = algo.BlockSize >> 3;
            _encryptMode   = encryptMode;
            _mt_threshold  = _blockBytes * 2;
            _iv            = (byte[])iv.Clone();
            _mode          = algo.ModePlus;
            _decryptBuffer = new byte[OutputBlockSize];

            if (_algo.NumberOfThreads > 1 && (algo.ModePlus == CipherModePlus.ECB || algo.ModePlus == CipherModePlus.CTR || (algo.ModePlus == CipherModePlus.CBC && !encryptMode)))
            {
                _useThread  = true;
                _waitHandle = new ConfluentWaitHandle();
                _threads    = _algo.NumberOfThreads;
                if (_mode != CipherModePlus.ECB)
                {
                    _mt_temp = new byte[_threads][];
                    for (int i = 0; i < _mt_temp.Length; i++)
                    {
                        _mt_temp[i] = new byte[iv.Length];
                    }
                    _temp = _mt_temp[0];
                }
            }
            else if (_mode != CipherModePlus.ECB)
            {
                _temp = new byte[iv.Length];
            }
        }
Exemplo n.º 2
0
        public SymmetricKey(SymmetricAlgorithmType type, byte[] iv, byte[] key, CipherModePlus cipherMode, PaddingMode paddingMode, bool enableIVShuffle)
        {
            _type = type;
            switch (type) {
                case SymmetricAlgorithmType.None:
                    _algo = null;
                    return;
                case SymmetricAlgorithmType.Camellia:
                    _algo = new openCrypto.CamelliaManaged ();
                    break;
                case SymmetricAlgorithmType.Rijndael:
                    _algo = new openCrypto.RijndaelManaged ();
                    break;
                default:
                    throw new ArgumentOutOfRangeException ();
            }

            _algo.ModePlus = cipherMode;
            _algo.Padding = paddingMode;
            _algo.KeySize = key.Length << 3;
            _algo.BlockSize = iv.Length << 3;
            _algo.FeedbackSize = iv.Length << 3;
            _iv = iv;
            _key = key;
            _ivShuffle = enableIVShuffle;
        }
Exemplo n.º 3
0
		public unsafe CamelliaTransformLE (SymmetricAlgorithmPlus algo, byte[] rgbKey, byte[] rgbIV, bool encrypt)
			: base (algo, encrypt, rgbKey.Length == 16 ? 2 : 3, rgbIV, SBOX1_1110, SBOX2_0222, SBOX3_3033, SBOX4_4404)
		{
			fixed (byte* pKey = rgbKey) {
				GenerateKeyTable ((uint*)pKey, rgbKey.Length, _keyTable);
			}
		}
Exemplo n.º 4
0
 public unsafe CamelliaTransformBE(SymmetricAlgorithmPlus algo, byte[] rgbKey, byte[] rgbIV, bool encrypt)
     : base(algo, encrypt, rgbKey.Length == 16 ? 2 : 3, rgbIV, SBOX1_1110, SBOX2_0222, SBOX3_3033, SBOX4_4404)
 {
     fixed(byte *pKey = rgbKey)
     {
         GenerateKeyTable((uint *)pKey, rgbKey.Length, _keyTable);
     }
 }
Exemplo n.º 5
0
		protected CamelliaTransform (SymmetricAlgorithmPlus algo, bool encryptMode, int flayerLimit, byte[] iv, uint[] sbox1, uint[] sbox2, uint[] sbox3, uint[] sbox4)
			: base (algo, encryptMode, iv)
		{
			_flayerLimit = flayerLimit;

			_sbox1 = sbox1;
			_sbox2 = sbox2;
			_sbox3 = sbox3;
			_sbox4 = sbox4;
		}
Exemplo n.º 6
0
        protected CamelliaTransform(SymmetricAlgorithmPlus algo, bool encryptMode, int flayerLimit, byte[] iv, uint[] sbox1, uint[] sbox2, uint[] sbox3, uint[] sbox4)
            : base(algo, encryptMode, iv)
        {
            _flayerLimit = flayerLimit;

            _sbox1 = sbox1;
            _sbox2 = sbox2;
            _sbox3 = sbox3;
            _sbox4 = sbox4;
        }
Exemplo n.º 7
0
 public SymmetricKey(SymmetricAlgorithmPlus algo, byte[] iv, byte[] key, bool enableIVShuffle)
 {
     if (algo == null)
         _type = SymmetricAlgorithmType.None;
     else if (algo is openCrypto.CamelliaManaged)
         _type = SymmetricAlgorithmType.Camellia;
     else if (algo is openCrypto.RijndaelManaged)
         _type = SymmetricAlgorithmType.Rijndael;
     else
         throw new NotSupportedException ();
     _algo = algo;
     _iv = iv;
     _key = key;
     _ivShuffle = enableIVShuffle;
 }
Exemplo n.º 8
0
			public DummyTransform (SymmetricAlgorithmPlus algo, bool encryptMode, byte[] iv)
				: base (algo, encryptMode, iv)
			{
			}