Пример #1
0
        public void ComputeInverseSboxTable_returns_correct_result()
        {
            var dt    = SjclAes.ComputeDoubleTable();
            var tt    = SjclAes.ComputeTrippleTable(dt);
            var sbox  = SjclAes.ComputeSboxTable(dt, tt);
            var table = SjclAes.ComputeInverseSboxTable(sbox);

            // Test data is generated with SJCL sources
            Assert.AreEqual(256, table.Length);

            Assert.AreEqual(0x52, table[0x00]);
            Assert.AreEqual(0x09, table[0x01]);
            Assert.AreEqual(0x6a, table[0x02]);
            Assert.AreEqual(0x6b, table[0x7f]);
            Assert.AreEqual(0x3a, table[0x80]);
            Assert.AreEqual(0x0c, table[0xfe]);
            Assert.AreEqual(0x7d, table[0xff]);

            // Every value should be exactly once
            Array.Sort(table);
            for (var i = 0; i < 256; ++i)
            {
                Assert.AreEqual(i, table[i]);
            }
        }
Пример #2
0
        public void ComputeInverseSboxTable_returns_correct_result()
        {
            var dt    = SjclAes.ComputeDoubleTable();
            var tt    = SjclAes.ComputeTrippleTable(dt);
            var sbox  = SjclAes.ComputeSboxTable(dt, tt);
            var table = SjclAes.ComputeInverseSboxTable(sbox);

            // Test data is generated with SJCL sources
            Assert.That(table.Length, Is.EqualTo(256));

            Assert.That(table[0x00], Is.EqualTo(0x52));
            Assert.That(table[0x01], Is.EqualTo(0x09));
            Assert.That(table[0x02], Is.EqualTo(0x6a));
            Assert.That(table[0x7f], Is.EqualTo(0x6b));
            Assert.That(table[0x80], Is.EqualTo(0x3a));
            Assert.That(table[0xfe], Is.EqualTo(0x0c));
            Assert.That(table[0xff], Is.EqualTo(0x7d));

            // Every value should be exactly once
            Array.Sort(table);
            for (var i = 0; i < 256; ++i)
            {
                Assert.That(table[i], Is.EqualTo(i));
            }
        }