OCB_double() protected static method

protected static OCB_double ( byte block ) : byte[]
block byte
return byte[]
Esempio n. 1
0
 protected virtual byte[] GetLSub(int n)
 {
     while (n >= this.L.Count)
     {
         this.L.Add(OcbBlockCipher.OCB_double((byte[])this.L[this.L.Count - 1]));
     }
     return((byte[])this.L[n]);
 }
Esempio n. 2
0
        public virtual void Init(bool forEncryption, ICipherParameters parameters)
        {
            bool flag = this.forEncryption;

            this.forEncryption = forEncryption;
            this.macBlock      = null;
            byte[]       array;
            KeyParameter keyParameter;

            if (parameters is AeadParameters)
            {
                AeadParameters aeadParameters = (AeadParameters)parameters;
                array = aeadParameters.GetNonce();
                this.initialAssociatedText = aeadParameters.GetAssociatedText();
                int num = aeadParameters.MacSize;
                if (num < 64 || num > 128 || num % 8 != 0)
                {
                    throw new ArgumentException("Invalid value for MAC size: " + num);
                }
                this.macSize = num / 8;
                keyParameter = aeadParameters.Key;
            }
            else
            {
                if (!(parameters is ParametersWithIV))
                {
                    throw new ArgumentException("invalid parameters passed to OCB");
                }
                ParametersWithIV parametersWithIV = (ParametersWithIV)parameters;
                array = parametersWithIV.GetIV();
                this.initialAssociatedText = null;
                this.macSize = 16;
                keyParameter = (KeyParameter)parametersWithIV.Parameters;
            }
            this.hashBlock = new byte[16];
            this.mainBlock = new byte[forEncryption ? 16 : (16 + this.macSize)];
            if (array == null)
            {
                array = new byte[0];
            }
            if (array.Length > 15)
            {
                throw new ArgumentException("IV must be no more than 15 bytes");
            }
            if (keyParameter != null)
            {
                this.hashCipher.Init(true, keyParameter);
                this.mainCipher.Init(forEncryption, keyParameter);
                this.KtopInput = null;
            }
            else if (flag != forEncryption)
            {
                throw new ArgumentException("cannot change encrypting state without providing key.");
            }
            this.L_Asterisk = new byte[16];
            this.hashCipher.ProcessBlock(this.L_Asterisk, 0, this.L_Asterisk, 0);
            this.L_Dollar = OcbBlockCipher.OCB_double(this.L_Asterisk);
            this.L        = Platform.CreateArrayList();
            this.L.Add(OcbBlockCipher.OCB_double(this.L_Dollar));
            int num2 = this.ProcessNonce(array);
            int num3 = num2 % 8;
            int num4 = num2 / 8;

            if (num3 == 0)
            {
                Array.Copy(this.Stretch, num4, this.OffsetMAIN_0, 0, 16);
            }
            else
            {
                for (int i = 0; i < 16; i++)
                {
                    uint num5 = (uint)this.Stretch[num4];
                    uint num6 = (uint)this.Stretch[++num4];
                    this.OffsetMAIN_0[i] = (byte)(num5 << num3 | num6 >> 8 - num3);
                }
            }
            this.hashBlockPos   = 0;
            this.mainBlockPos   = 0;
            this.hashBlockCount = 0L;
            this.mainBlockCount = 0L;
            this.OffsetHASH     = new byte[16];
            this.Sum            = new byte[16];
            Array.Copy(this.OffsetMAIN_0, 0, this.OffsetMAIN, 0, 16);
            this.Checksum = new byte[16];
            if (this.initialAssociatedText != null)
            {
                this.ProcessAadBytes(this.initialAssociatedText, 0, this.initialAssociatedText.Length);
            }
        }