bytes2uint() приватный статический Метод

private static bytes2uint ( byte src, int offset ) : uint
src byte
offset int
Результат uint
Пример #1
0
 private int processBlock192or256(byte[] input, int inOff, byte[] output, int outOff)
 {
     for (int i = 0; i < 4; i++)
     {
         this.state[i]  = CamelliaLightEngine.bytes2uint(input, inOff + i * 4);
         this.state[i] ^= this.kw[i];
     }
     this.camelliaF2(this.state, this.subkey, 0);
     this.camelliaF2(this.state, this.subkey, 4);
     this.camelliaF2(this.state, this.subkey, 8);
     this.camelliaFLs(this.state, this.ke, 0);
     this.camelliaF2(this.state, this.subkey, 12);
     this.camelliaF2(this.state, this.subkey, 16);
     this.camelliaF2(this.state, this.subkey, 20);
     this.camelliaFLs(this.state, this.ke, 4);
     this.camelliaF2(this.state, this.subkey, 24);
     this.camelliaF2(this.state, this.subkey, 28);
     this.camelliaF2(this.state, this.subkey, 32);
     this.camelliaFLs(this.state, this.ke, 8);
     this.camelliaF2(this.state, this.subkey, 36);
     this.camelliaF2(this.state, this.subkey, 40);
     this.camelliaF2(this.state, this.subkey, 44);
     this.state[2] ^= this.kw[4];
     this.state[3] ^= this.kw[5];
     this.state[0] ^= this.kw[6];
     this.state[1] ^= this.kw[7];
     CamelliaLightEngine.uint2bytes(this.state[2], output, outOff);
     CamelliaLightEngine.uint2bytes(this.state[3], output, outOff + 4);
     CamelliaLightEngine.uint2bytes(this.state[0], output, outOff + 8);
     CamelliaLightEngine.uint2bytes(this.state[1], output, outOff + 12);
     return(16);
 }
Пример #2
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;
            }
        }