roldqo32() private static method

private static roldqo32 ( int rot, uint ki, int ioff, uint ko, int ooff ) : void
rot int
ki uint
ioff int
ko uint
ooff int
return void
Example #1
0
        private void setKey(bool forEncryption, byte[] key)
        {
            uint[] array  = new uint[8];
            uint[] array2 = new uint[4];
            uint[] array3 = new uint[4];
            uint[] array4 = new uint[4];
            int    num    = key.Length;

            if (num != 16)
            {
                if (num != 24)
                {
                    if (num != 32)
                    {
                        throw new ArgumentException("key sizes are only 16/24/32 bytes.");
                    }
                    array[0]       = CamelliaLightEngine.bytes2uint(key, 0);
                    array[1]       = CamelliaLightEngine.bytes2uint(key, 4);
                    array[2]       = CamelliaLightEngine.bytes2uint(key, 8);
                    array[3]       = CamelliaLightEngine.bytes2uint(key, 12);
                    array[4]       = CamelliaLightEngine.bytes2uint(key, 16);
                    array[5]       = CamelliaLightEngine.bytes2uint(key, 20);
                    array[6]       = CamelliaLightEngine.bytes2uint(key, 24);
                    array[7]       = CamelliaLightEngine.bytes2uint(key, 28);
                    this._keyis128 = false;
                }
                else
                {
                    array[0]       = CamelliaLightEngine.bytes2uint(key, 0);
                    array[1]       = CamelliaLightEngine.bytes2uint(key, 4);
                    array[2]       = CamelliaLightEngine.bytes2uint(key, 8);
                    array[3]       = CamelliaLightEngine.bytes2uint(key, 12);
                    array[4]       = CamelliaLightEngine.bytes2uint(key, 16);
                    array[5]       = CamelliaLightEngine.bytes2uint(key, 20);
                    array[6]       = ~array[4];
                    array[7]       = ~array[5];
                    this._keyis128 = false;
                }
            }
            else
            {
                this._keyis128 = true;
                array[0]       = CamelliaLightEngine.bytes2uint(key, 0);
                array[1]       = CamelliaLightEngine.bytes2uint(key, 4);
                array[2]       = CamelliaLightEngine.bytes2uint(key, 8);
                array[3]       = CamelliaLightEngine.bytes2uint(key, 12);
                array[4]       = (array[5] = (array[6] = (array[7] = 0u)));
            }
            for (int i = 0; i < 4; i++)
            {
                array2[i] = (array[i] ^ array[i + 4]);
            }
            this.camelliaF2(array2, CamelliaLightEngine.SIGMA, 0);
            for (int j = 0; j < 4; j++)
            {
                array2[j] ^= array[j];
            }
            this.camelliaF2(array2, CamelliaLightEngine.SIGMA, 4);
            if (this._keyis128)
            {
                if (forEncryption)
                {
                    this.kw[0] = array[0];
                    this.kw[1] = array[1];
                    this.kw[2] = array[2];
                    this.kw[3] = array[3];
                    CamelliaLightEngine.roldq(15, array, 0, this.subkey, 4);
                    CamelliaLightEngine.roldq(30, array, 0, this.subkey, 12);
                    CamelliaLightEngine.roldq(15, array, 0, array4, 0);
                    this.subkey[18] = array4[2];
                    this.subkey[19] = array4[3];
                    CamelliaLightEngine.roldq(17, array, 0, this.ke, 4);
                    CamelliaLightEngine.roldq(17, array, 0, this.subkey, 24);
                    CamelliaLightEngine.roldq(17, array, 0, this.subkey, 32);
                    this.subkey[0] = array2[0];
                    this.subkey[1] = array2[1];
                    this.subkey[2] = array2[2];
                    this.subkey[3] = array2[3];
                    CamelliaLightEngine.roldq(15, array2, 0, this.subkey, 8);
                    CamelliaLightEngine.roldq(15, array2, 0, this.ke, 0);
                    CamelliaLightEngine.roldq(15, array2, 0, array4, 0);
                    this.subkey[16] = array4[0];
                    this.subkey[17] = array4[1];
                    CamelliaLightEngine.roldq(15, array2, 0, this.subkey, 20);
                    CamelliaLightEngine.roldqo32(34, array2, 0, this.subkey, 28);
                    CamelliaLightEngine.roldq(17, array2, 0, this.kw, 4);
                    return;
                }
                this.kw[4] = array[0];
                this.kw[5] = array[1];
                this.kw[6] = array[2];
                this.kw[7] = array[3];
                CamelliaLightEngine.decroldq(15, array, 0, this.subkey, 28);
                CamelliaLightEngine.decroldq(30, array, 0, this.subkey, 20);
                CamelliaLightEngine.decroldq(15, array, 0, array4, 0);
                this.subkey[16] = array4[0];
                this.subkey[17] = array4[1];
                CamelliaLightEngine.decroldq(17, array, 0, this.ke, 0);
                CamelliaLightEngine.decroldq(17, array, 0, this.subkey, 8);
                CamelliaLightEngine.decroldq(17, array, 0, this.subkey, 0);
                this.subkey[34] = array2[0];
                this.subkey[35] = array2[1];
                this.subkey[32] = array2[2];
                this.subkey[33] = array2[3];
                CamelliaLightEngine.decroldq(15, array2, 0, this.subkey, 24);
                CamelliaLightEngine.decroldq(15, array2, 0, this.ke, 4);
                CamelliaLightEngine.decroldq(15, array2, 0, array4, 0);
                this.subkey[18] = array4[2];
                this.subkey[19] = array4[3];
                CamelliaLightEngine.decroldq(15, array2, 0, this.subkey, 12);
                CamelliaLightEngine.decroldqo32(34, array2, 0, this.subkey, 4);
                CamelliaLightEngine.roldq(17, array2, 0, this.kw, 0);
                return;
            }
            else
            {
                for (int k = 0; k < 4; k++)
                {
                    array3[k] = (array2[k] ^ array[k + 4]);
                }
                this.camelliaF2(array3, CamelliaLightEngine.SIGMA, 8);
                if (forEncryption)
                {
                    this.kw[0] = array[0];
                    this.kw[1] = array[1];
                    this.kw[2] = array[2];
                    this.kw[3] = array[3];
                    CamelliaLightEngine.roldqo32(45, array, 0, this.subkey, 16);
                    CamelliaLightEngine.roldq(15, array, 0, this.ke, 4);
                    CamelliaLightEngine.roldq(17, array, 0, this.subkey, 32);
                    CamelliaLightEngine.roldqo32(34, array, 0, this.subkey, 44);
                    CamelliaLightEngine.roldq(15, array, 4, this.subkey, 4);
                    CamelliaLightEngine.roldq(15, array, 4, this.ke, 0);
                    CamelliaLightEngine.roldq(30, array, 4, this.subkey, 24);
                    CamelliaLightEngine.roldqo32(34, array, 4, this.subkey, 36);
                    CamelliaLightEngine.roldq(15, array2, 0, this.subkey, 8);
                    CamelliaLightEngine.roldq(30, array2, 0, this.subkey, 20);
                    this.ke[8]  = array2[1];
                    this.ke[9]  = array2[2];
                    this.ke[10] = array2[3];
                    this.ke[11] = array2[0];
                    CamelliaLightEngine.roldqo32(49, array2, 0, this.subkey, 40);
                    this.subkey[0] = array3[0];
                    this.subkey[1] = array3[1];
                    this.subkey[2] = array3[2];
                    this.subkey[3] = array3[3];
                    CamelliaLightEngine.roldq(30, array3, 0, this.subkey, 12);
                    CamelliaLightEngine.roldq(30, array3, 0, this.subkey, 28);
                    CamelliaLightEngine.roldqo32(51, array3, 0, this.kw, 4);
                    return;
                }
                this.kw[4] = array[0];
                this.kw[5] = array[1];
                this.kw[6] = array[2];
                this.kw[7] = array[3];
                CamelliaLightEngine.decroldqo32(45, array, 0, this.subkey, 28);
                CamelliaLightEngine.decroldq(15, array, 0, this.ke, 4);
                CamelliaLightEngine.decroldq(17, array, 0, this.subkey, 12);
                CamelliaLightEngine.decroldqo32(34, array, 0, this.subkey, 0);
                CamelliaLightEngine.decroldq(15, array, 4, this.subkey, 40);
                CamelliaLightEngine.decroldq(15, array, 4, this.ke, 8);
                CamelliaLightEngine.decroldq(30, array, 4, this.subkey, 20);
                CamelliaLightEngine.decroldqo32(34, array, 4, this.subkey, 8);
                CamelliaLightEngine.decroldq(15, array2, 0, this.subkey, 36);
                CamelliaLightEngine.decroldq(30, array2, 0, this.subkey, 24);
                this.ke[2] = array2[1];
                this.ke[3] = array2[2];
                this.ke[0] = array2[3];
                this.ke[1] = array2[0];
                CamelliaLightEngine.decroldqo32(49, array2, 0, this.subkey, 4);
                this.subkey[46] = array3[0];
                this.subkey[47] = array3[1];
                this.subkey[44] = array3[2];
                this.subkey[45] = array3[3];
                CamelliaLightEngine.decroldq(30, array3, 0, this.subkey, 32);
                CamelliaLightEngine.decroldq(30, array3, 0, this.subkey, 16);
                CamelliaLightEngine.roldqo32(51, array3, 0, this.kw, 0);
                return;
            }
        }