コード例 #1
0
        public void TestKeyExpansion()
        {
            byte[] inputKey = { 0x11, 0x22, 0x33, 0x44,
                                0x55, 0x66, 0x77, 0x88,
                                0x99, 0x00, 0xaa, 0xbb,
                                0xcc, 0xdd, 0xee, 0xff };
            string expectedKeyString = "11 55 99 CC D1 84 1D D1 1B 9F 82 53 AF 30 B2 E1 35 05 B7 56 53 56 E1 B7 E3 B5 54 E3 1B AE FA 19 07 A9 53 4A EE 47 14 5E 78 3F 2B 75 \n" +
                                       "22 66 00 DD 0A 6C 6C B1 4D 21 4D FC E4 C5 88 74 36 F3 7B 0F 11 E2 99 96 77 95 0C 9A 1F 8A 86 1C 14 9E 18 04 C5 5B 43 47 10 4B 08 4F \n" +
                                       "33 77 AA EE 25 52 F8 16 0B 59 A1 B7 30 69 C8 7F E3 8A 42 3D 26 AC EE D3 66 CA 24 F7 87 4D 69 9E EB A6 CF 51 8D 2B E4 B5 C4 EF 0B BE \n" +
                                       "44 88 BB FF 0F 87 3C C3 31 B6 8A 49 DC 6A E0 A9 24 4E AE 07 95 DB 75 72 3C E7 92 E0 2D CA 58 B8 F9 33 6B D3 2F 1C 77 A4 77 6B 1C B8 \n";

            Key key = new Key(inputKey);

            Console.Out.WriteLine("key:\n" + key);
            Assert.AreEqual(key.ToString(), expectedKeyString);
        }
コード例 #2
0
        public void TestAddRoundKey0()
        {
            string s = "12345689abcdefgh";
            byte[] inputKey = { 0x11, 0x22, 0x33, 0x44,
                                0x55, 0x66, 0x77, 0x88,
                                0x99, 0x00, 0xaa, 0xbb,
                                0xcc, 0xdd, 0xee, 0xff };
            byte[] expectedStateData = { 32, 16, 0, 112, 96, 80, 79, 177, 248, 98, 201, 223, 169, 187, 137, 151 };
            State expectedState = new State(expectedStateData);
            Encoding encoding = Encoding.UTF8;
            byte[] inputPlain = encoding.GetBytes(s);

            Key key = new Key(inputKey);
            State start = new State(inputPlain);

            start = start.addRoundKey(key, 0);

            Console.Out.WriteLine("add0:\n" + start);
            Assert.AreEqual(start.ToString(), expectedState.ToString());
        }
コード例 #3
0
        public void TestInvalidKeyLength144Bit()
        {
            string invalidKey = "11223344556677889900aabbccddeeff2323";
            int size = invalidKey.Length / 2;
            byte[] b = new byte[size];

            if ((size != 16) && (size != 24) && (size != 32))
            {
                throw new ArgumentException();
            }
            Encoding encoding = Encoding.UTF8;
            byte[] inputPlain = encoding.GetBytes(invalidKey);
            Key key = new Key(inputPlain);
        }
コード例 #4
0
        public void TestInvalidKeyLength32Bit()
        {
            string invalidKey = "12345678";//32 bit key

            int size = invalidKey.Length / 2;
            byte[] b = new byte[size];

            if ((size != 16) && (size != 24) && (size != 32))
            {
                throw new ArgumentException();
            }
            Encoding encoding = Encoding.UTF8;
            byte[] inputPlain = encoding.GetBytes(invalidKey);
            Key key = new Key(inputPlain);
        }
コード例 #5
0
        public void TestAddRoundKey7()
        {
            string s = "12345689abcdefgh";
            byte[] inputKey = { 0x11, 0x22, 0x33, 0x44,
                                0x55, 0x66, 0x77, 0x88,
                                0x99, 0x00, 0xaa, 0xbb,
                                0xcc, 0xdd, 0xee, 0xff };
            byte[] expectedStateData = { 42, 45, 180, 25, 155, 188, 117, 243, 155, 228, 10, 60, 124, 122, 249, 208 };
            State expectedState = new State(expectedStateData);
            Encoding encoding = Encoding.UTF8;
            byte[] inputPlain = encoding.GetBytes(s);

            Key key = new Key(inputKey);
            State start = new State(inputPlain);
            start = start.addRoundKey(key, 7);
            Console.Out.WriteLine("add7:\n" + start);
            Assert.AreEqual(start.ToString(), expectedState.ToString());
        }
コード例 #6
0
 public State addRoundKey(Key key, int round)
 {
     State s = new State();
     for (int c = 0; c < nrofCol; c++)
     {
         for (int r = 0; r < nrofRow; r++)
         {
             s.buf[r, c] = (byte)(buf[r, c] ^ key.w[r, c + 4 * round]);
         }
     }
     return (s);
 }