// Token: 0x06000245 RID: 581 RVA: 0x000128C0 File Offset: 0x00010AC0
        public void Init(byte[] H)
        {
            this.M[0]    = new uint[16][];
            this.M[1]    = new uint[16][];
            this.M[0][0] = new uint[4];
            this.M[1][0] = new uint[4];
            this.M[1][8] = GcmUtilities.AsUints(H);
            for (int i = 4; i >= 1; i >>= 1)
            {
                uint[] array = (uint[])this.M[1][i + i].Clone();
                GcmUtilities.MultiplyP(array);
                this.M[1][i] = array;
            }
            uint[] array2 = (uint[])this.M[1][1].Clone();
            GcmUtilities.MultiplyP(array2);
            this.M[0][8] = array2;
            for (int j = 4; j >= 1; j >>= 1)
            {
                uint[] array3 = (uint[])this.M[0][j + j].Clone();
                GcmUtilities.MultiplyP(array3);
                this.M[0][j] = array3;
            }
            int num = 0;

            for (;;)
            {
                for (int k = 2; k < 16; k += k)
                {
                    for (int l = 1; l < k; l++)
                    {
                        uint[] array4 = (uint[])this.M[num][k].Clone();
                        GcmUtilities.Xor(array4, this.M[num][l]);
                        this.M[num][k + l] = array4;
                    }
                }
                if (++num == 32)
                {
                    break;
                }
                if (num > 1)
                {
                    this.M[num]    = new uint[16][];
                    this.M[num][0] = new uint[4];
                    for (int m = 8; m > 0; m >>= 1)
                    {
                        uint[] array5 = (uint[])this.M[num - 2][m].Clone();
                        GcmUtilities.MultiplyP8(array5);
                        this.M[num][m] = array5;
                    }
                }
            }
        }
Exemple #2
0
 // Token: 0x0600028C RID: 652 RVA: 0x0002699C File Offset: 0x00024B9C
 private byte[] gHASH(byte[] byte_0)
 {
     byte[] array = new byte[16];
     for (int i = 0; i < byte_0.Length; i += 16)
     {
         byte[] array2 = new byte[16];
         int    length = Math.Min(byte_0.Length - i, 16);
         Array.Copy(byte_0, i, array2, 0, length);
         GcmUtilities.Xor(array, array2);
         this.multiplier.MultiplyH(array);
     }
     return(array);
 }
Exemple #3
0
        // Token: 0x06000287 RID: 647 RVA: 0x00026658 File Offset: 0x00024858
        public int DoFinal(byte[] output, int outOff)
        {
            int num = this.bufOff;

            if (!this.forEncryption)
            {
                if (num < this.macSize)
                {
                    throw new InvalidCipherTextException(Strings.Get(107395407));
                }
                num -= this.macSize;
            }
            if (num > 0)
            {
                byte[] array = new byte[16];
                Array.Copy(this.bufBlock, 0, array, 0, num);
                this.gCTRBlock(array, num, output, outOff);
            }
            byte[] array2 = new byte[16];
            GcmBlockCipher.packLength((ulong)((long)this.A.Length * 8L), array2, 0);
            GcmBlockCipher.packLength(this.totalLength * 8UL, array2, 8);
            GcmUtilities.Xor(this.S, array2);
            this.multiplier.MultiplyH(this.S);
            byte[] array3 = new byte[16];
            this.cipher.ProcessBlock(this.J0, 0, array3, 0);
            GcmUtilities.Xor(array3, this.S);
            int num2 = num;

            this.macBlock = new byte[this.macSize];
            Array.Copy(array3, 0, this.macBlock, 0, this.macSize);
            if (this.forEncryption)
            {
                Array.Copy(this.macBlock, 0, output, outOff + this.bufOff, this.macSize);
                num2 += this.macSize;
            }
            else
            {
                byte[] array4 = new byte[this.macSize];
                Array.Copy(this.bufBlock, num, array4, 0, this.macSize);
                if (!Arrays.ConstantTimeAreEqual(this.macBlock, array4))
                {
                    throw new InvalidCipherTextException(Strings.Get(107395418));
                }
            }
            this.Reset(false);
            return(num2);
        }
Exemple #4
0
 // Token: 0x0600028B RID: 651 RVA: 0x000268D4 File Offset: 0x00024AD4
 private void gCTRBlock(byte[] byte_0, int int_0, byte[] byte_1, int int_1)
 {
     for (int i = 15; i >= 12; i--)
     {
         byte[] array = this.counter;
         int    num   = i;
         byte   b     = array[num] + 1;
         array[num] = b;
         if (b != 0)
         {
             break;
         }
     }
     byte[] array2 = new byte[16];
     this.cipher.ProcessBlock(this.counter, 0, array2, 0);
     byte[] byte_2;
     if (this.forEncryption)
     {
         Array.Copy(GcmBlockCipher.Zeroes, int_0, array2, int_0, 16 - int_0);
         byte_2 = array2;
     }
     else
     {
         byte_2 = byte_0;
     }
     for (int j = int_0 - 1; j >= 0; j--)
     {
         byte[] array3 = array2;
         int    num2   = j;
         array3[num2]     ^= byte_0[j];
         byte_1[int_1 + j] = array2[j];
     }
     GcmUtilities.Xor(this.S, byte_2);
     this.multiplier.MultiplyH(this.S);
     this.totalLength += (ulong)((long)int_0);
 }
Exemple #5
0
 // Token: 0x06000213 RID: 531 RVA: 0x00011570 File Offset: 0x0000F770
 private void gCTRBlock(byte[] A_1, int A_2, byte[] A_3, int A_4)
 {
     for (int i = 15; i >= 12; i--)
     {
         byte[] array = this.counter;
         int    num   = i;
         byte   b     = array[num] + 1;
         array[num] = b;
         if (b != 0)
         {
             break;
         }
     }
     byte[] array2 = new byte[16];
     this.cipher.ProcessBlock(this.counter, 0, array2, 0);
     byte[] array3;
     if (this.forEncryption)
     {
         Array.Copy(GcmBlockCipher.Zeroes, A_2, array2, A_2, 16 - A_2);
         array3 = array2;
     }
     else
     {
         array3 = A_1;
     }
     for (int j = A_2 - 1; j >= 0; j--)
     {
         byte[] array4 = array2;
         int    num2   = j;
         array4[num2] ^= A_1[j];
         A_3[A_4 + j]  = array2[j];
     }
     GcmUtilities.Xor(this.S, array3);
     this.multiplier.MultiplyH(this.S);
     this.totalLength += (ulong)((long)A_2);
 }
Exemple #6
0
        // Token: 0x06000281 RID: 641 RVA: 0x00026360 File Offset: 0x00024560
        public virtual void Init(bool forEncryption, ICipherParameters parameters)
        {
            this.forEncryption = forEncryption;
            this.macBlock      = null;
            if (parameters is AeadParameters)
            {
                AeadParameters aeadParameters = (AeadParameters)parameters;
                this.nonce = aeadParameters.GetNonce();
                this.A     = aeadParameters.GetAssociatedText();
                int num = aeadParameters.MacSize;
                if (num < 96 || num > 128 || num % 8 != 0)
                {
                    throw new ArgumentException(Strings.Get(107395530) + num.ToString());
                }
                this.macSize  = num / 8;
                this.keyParam = aeadParameters.Key;
            }
            else
            {
                if (!(parameters is ParametersWithIV))
                {
                    throw new ArgumentException(Strings.Get(107395489));
                }
                ParametersWithIV parametersWithIV = (ParametersWithIV)parameters;
                this.nonce    = parametersWithIV.GetIV();
                this.A        = null;
                this.macSize  = 16;
                this.keyParam = (KeyParameter)parametersWithIV.Parameters;
            }
            int num2 = forEncryption ? 16 : (16 + this.macSize);

            this.bufBlock = new byte[num2];
            if (this.nonce != null && this.nonce.Length >= 1)
            {
                if (this.A == null)
                {
                    this.A = new byte[0];
                }
                this.cipher.Init(true, this.keyParam);
                this.H = new byte[16];
                this.cipher.ProcessBlock(this.H, 0, this.H, 0);
                this.multiplier.Init(this.H);
                this.initS = this.gHASH(this.A);
                if (this.nonce.Length == 12)
                {
                    this.J0 = new byte[16];
                    Array.Copy(this.nonce, 0, this.J0, 0, this.nonce.Length);
                    this.J0[15] = 1;
                }
                else
                {
                    this.J0 = this.gHASH(this.nonce);
                    byte[] array = new byte[16];
                    GcmBlockCipher.packLength((ulong)((long)this.nonce.Length * 8L), array, 8);
                    GcmUtilities.Xor(this.J0, array);
                    this.multiplier.MultiplyH(this.J0);
                }
                this.S           = Arrays.Clone(this.initS);
                this.counter     = Arrays.Clone(this.J0);
                this.bufOff      = 0;
                this.totalLength = 0UL;
                return;
            }
            throw new ArgumentException(Strings.Get(107395476));
        }