예제 #1
0
        public void ScheduleDecryptionKey_returns_correct_result()
        {
            var dt     = SjclAes.ComputeDoubleTable();
            var sbox   = SjclAes.ComputeSboxTable(dt, SjclAes.ComputeTrippleTable(dt));
            var decode = SjclAes.ComputeDecodeTable(dt, sbox);

            foreach (var i in KeyTestCases)
            {
                var encKey = SjclAes.ScheduleEncryptionKey(i.Key, sbox);
                var key    = SjclAes.ScheduleDecryptionKey(encKey, sbox, decode);
                Assert.AreEqual(i.DecryptionKey, key);
            }
        }
예제 #2
0
        public void ComputeDecodeTable_returns_correct_result()
        {
            var dt    = SjclAes.ComputeDoubleTable();
            var sbox  = SjclAes.ComputeSboxTable(dt, SjclAes.ComputeTrippleTable(dt));
            var table = SjclAes.ComputeDecodeTable(dt, sbox);

            // Test data is generated with SJCL sources
            Assert.AreEqual(4, table.GetLength(0));
            Assert.AreEqual(256, table.GetLength(1));

            // 0
            Assert.AreEqual(0x51f4a750, table[0, 0x00]);
            Assert.AreEqual(0x7e416553, table[0, 0x01]);
            Assert.AreEqual(0x1a17a4c3, table[0, 0x02]);
            Assert.AreEqual(0x141ea9c8, table[0, 0x7f]);
            Assert.AreEqual(0x57f11985, table[0, 0x80]);
            Assert.AreEqual(0x486c5c74, table[0, 0xfe]);
            Assert.AreEqual(0xd0b85742, table[0, 0xff]);

            // 1
            Assert.AreEqual(0x5051f4a7, table[1, 0x00]);
            Assert.AreEqual(0x537e4165, table[1, 0x01]);
            Assert.AreEqual(0xc31a17a4, table[1, 0x02]);
            Assert.AreEqual(0xc8141ea9, table[1, 0x7f]);
            Assert.AreEqual(0x8557f119, table[1, 0x80]);
            Assert.AreEqual(0x74486c5c, table[1, 0xfe]);
            Assert.AreEqual(0x42d0b857, table[1, 0xff]);

            // 2
            Assert.AreEqual(0xa75051f4, table[2, 0x00]);
            Assert.AreEqual(0x65537e41, table[2, 0x01]);
            Assert.AreEqual(0xa4c31a17, table[2, 0x02]);
            Assert.AreEqual(0xa9c8141e, table[2, 0x7f]);
            Assert.AreEqual(0x198557f1, table[2, 0x80]);
            Assert.AreEqual(0x5c74486c, table[2, 0xfe]);
            Assert.AreEqual(0x5742d0b8, table[2, 0xff]);

            // 3
            Assert.AreEqual(0xf4a75051, table[3, 0x00]);
            Assert.AreEqual(0x4165537e, table[3, 0x01]);
            Assert.AreEqual(0x17a4c31a, table[3, 0x02]);
            Assert.AreEqual(0x1ea9c814, table[3, 0x7f]);
            Assert.AreEqual(0xf1198557, table[3, 0x80]);
            Assert.AreEqual(0x6c5c7448, table[3, 0xfe]);
            Assert.AreEqual(0xb85742d0, table[3, 0xff]);
        }
예제 #3
0
        public void ComputeDecodeTable_returns_correct_result()
        {
            var dt    = SjclAes.ComputeDoubleTable();
            var sbox  = SjclAes.ComputeSboxTable(dt, SjclAes.ComputeTrippleTable(dt));
            var table = SjclAes.ComputeDecodeTable(dt, sbox);

            // Test data is generated with SJCL sources
            Assert.That(table.GetLength(0), Is.EqualTo(4));
            Assert.That(table.GetLength(1), Is.EqualTo(256));

            // 0
            Assert.That(table[0, 0x00], Is.EqualTo(0x51f4a750));
            Assert.That(table[0, 0x01], Is.EqualTo(0x7e416553));
            Assert.That(table[0, 0x02], Is.EqualTo(0x1a17a4c3));
            Assert.That(table[0, 0x7f], Is.EqualTo(0x141ea9c8));
            Assert.That(table[0, 0x80], Is.EqualTo(0x57f11985));
            Assert.That(table[0, 0xfe], Is.EqualTo(0x486c5c74));
            Assert.That(table[0, 0xff], Is.EqualTo(0xd0b85742));

            // 1
            Assert.That(table[1, 0x00], Is.EqualTo(0x5051f4a7));
            Assert.That(table[1, 0x01], Is.EqualTo(0x537e4165));
            Assert.That(table[1, 0x02], Is.EqualTo(0xc31a17a4));
            Assert.That(table[1, 0x7f], Is.EqualTo(0xc8141ea9));
            Assert.That(table[1, 0x80], Is.EqualTo(0x8557f119));
            Assert.That(table[1, 0xfe], Is.EqualTo(0x74486c5c));
            Assert.That(table[1, 0xff], Is.EqualTo(0x42d0b857));

            // 2
            Assert.That(table[2, 0x00], Is.EqualTo(0xa75051f4));
            Assert.That(table[2, 0x01], Is.EqualTo(0x65537e41));
            Assert.That(table[2, 0x02], Is.EqualTo(0xa4c31a17));
            Assert.That(table[2, 0x7f], Is.EqualTo(0xa9c8141e));
            Assert.That(table[2, 0x80], Is.EqualTo(0x198557f1));
            Assert.That(table[2, 0xfe], Is.EqualTo(0x5c74486c));
            Assert.That(table[2, 0xff], Is.EqualTo(0x5742d0b8));

            // 3
            Assert.That(table[3, 0x00], Is.EqualTo(0xf4a75051));
            Assert.That(table[3, 0x01], Is.EqualTo(0x4165537e));
            Assert.That(table[3, 0x02], Is.EqualTo(0x17a4c31a));
            Assert.That(table[3, 0x7f], Is.EqualTo(0x1ea9c814));
            Assert.That(table[3, 0x80], Is.EqualTo(0xf1198557));
            Assert.That(table[3, 0xfe], Is.EqualTo(0x6c5c7448));
            Assert.That(table[3, 0xff], Is.EqualTo(0xb85742d0));
        }