Beispiel #1
0
        private void IterateState()
        {
            QByte[] newStates = new QByte[8];
            for (int i = 0; i < 8; i++)
            {
                uint op1 = RabbitUtils.g_function(this.states[i], this.counters[i]);
                uint op2 = RabbitUtils.g_function(this.states[(i + 7) % 8], this.counters[(i + 7) % 8]);
                uint op3 = RabbitUtils.g_function(this.states[(i + 6) % 8], this.counters[(i + 6) % 8]);
                if (i % 2 == 0)
                {
                    op2 = RabbitUtils.LeftRotate(op2, 16);
                    op3 = RabbitUtils.LeftRotate(op3, 16);
                }
                else
                {
                    op2 = RabbitUtils.LeftRotate(op2, 8);
                }

                ulong tmp    = op1 + op2 + op3;
                uint  result = (uint)(tmp % uint.MaxValue);
                newStates[i] = new QByte(result);
            }

            this.states = newStates;
        }
Beispiel #2
0
        /// <summary>
        /// Helper function defined in the original paper for iterating the state
        /// </summary>
        public static uint g_function(QByte state, QByte counter)
        {
            uint  x   = state.ToUInt();
            uint  y   = counter.ToUInt();
            ulong op1 = (x + y) % uint.MaxValue;

            op1 *= op1;
            //uint op2 = op1 >> 32;
            uint result = (uint)(op1 ^ (op1 >> 32)) % uint.MaxValue;

            return(result);
        }
Beispiel #3
0
        private void IterateCounters()
        {
            QByte[] newCounters = new QByte[8];
            for (int i = 0; i < 8; i++)
            {
                uint result;
                try
                {
                    result     = checked (this.counters[i].ToUInt() + Rabbit.aConstants[i] + this.carry);
                    this.carry = 0;
                }
                catch (OverflowException)
                {
                    result     = this.counters[i].ToUInt() + Rabbit.aConstants[i] + this.carry;
                    this.carry = 1;
                }

                newCounters[i] = new QByte(result);
            }

            this.counters = newCounters;
        }