예제 #1
0
        static void Main(string[] args)
        {
            string keyString = "80000000000000000000000000000000";
            string ivString  = "0000000000000000";

            byte[]        key       = RabbitUtils.StringToByteArray(keyString);
            byte[]        iv        = RabbitUtils.StringToByteArray(ivString);
            StringBuilder plaintext = new StringBuilder();

            // Building a 128bit block of plain text
            for (int i = 0; i < 2 * 16; i++)
            {
                plaintext.Append("0");
            }

            byte[] plainBytes = RabbitUtils.StringToByteArray(plaintext.ToString());
            Rabbit rabbit     = new Rabbit(key, iv);

            // Repeating 32 times in order to simulate 512 zero bytes
            // As requested in the test file https://github.com/cantora/avr-crypto-lib/blob/master/testvectors/rabbit-verified.test-vectors
            for (int i = 0; i < 32; i++)
            {
                byte[] ciphertextBytes = rabbit.EncryptBlock(plainBytes);
                string cyphertext      = RabbitUtils.ByteArrayToHexString(ciphertextBytes);
                Console.WriteLine(cyphertext);
            }
        }
예제 #2
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;
        }