def test_add_round_key():
    ''' XOR state array sa with roundkey rk to return new state array.
        param sa is a 4x4 state array, param rk is a 4-word round key '''
    stateArr = [[newBV(0x04), newBV(0x66), newBV(0x81), newBV(0xe5)], \
                [newBV(0xe0), newBV(0xcb), newBV(0x19), newBV(0x9a)], \
                [newBV(0x48), newBV(0xf8), newBV(0xd3), newBV(0x7a)], \
                [newBV(0x28), newBV(0x06), newBV(0x26), newBV(0x4c)]]
    roundKey = [
        AES.key_to_bv("a0fafe17"),
        AES.key_to_bv("88542cb1"),
        AES.key_to_bv("23a33939"),
        AES.key_to_bv("2a6c7605")
    ]
    expected = [[newBV(0xa4), newBV(0x9c), newBV(0x7f), newBV(0xf2)],\
                [newBV(0x68), newBV(0x9f), newBV(0x35), newBV(0x2b)],\
                [newBV(0x6b), newBV(0x5b), newBV(0xea), newBV(0x43)],\
                [newBV(0x02), newBV(0x6a), newBV(0x50), newBV(0x49)]]
    actual = AES.add_round_key(stateArr, roundKey)
    assert actual == expected

    stateArr = [[newBV(0x58), newBV(0x4d), newBV(0xca), newBV(0xf1)], \
                [newBV(0x1b), newBV(0x4b), newBV(0x5a), newBV(0xac)], \
                [newBV(0xdb), newBV(0xe7), newBV(0xca), newBV(0xa8)], \
                [newBV(0x1b), newBV(0x6b), newBV(0xb0), newBV(0xe5)]]
    roundKey = [
        AES.key_to_bv("f2c295f2"),
        AES.key_to_bv("7a96b943"),
        AES.key_to_bv("5935807a"),
        AES.key_to_bv("7359f67f")
    ]
    expected = [[newBV(0xaa), newBV(0x8f), newBV(0x5f), newBV(0x03)], \
                [newBV(0x61), newBV(0xdd), newBV(0xe3), newBV(0xef)], \
                [newBV(0x82), newBV(0xd2), newBV(0x4a), newBV(0xd2)], \
                [newBV(0x68), newBV(0x32), newBV(0x46), newBV(0x9a)]]
    actual = AES.add_round_key(stateArr, roundKey)
    assert actual == expected

    stateArr = [[newBV(0x75), newBV(0xec), newBV(0x09), newBV(0x93)], \
                [newBV(0x20), newBV(0x0b), newBV(0x63), newBV(0x33)], \
                [newBV(0x53), newBV(0xc0), newBV(0xcf), newBV(0x7c)], \
                [newBV(0xbb), newBV(0x25), newBV(0xd0), newBV(0xdc)]]
    roundKey = [
        AES.key_to_bv("3d80477d"),
        AES.key_to_bv("4716fe3e"),
        AES.key_to_bv("1e237e44"),
        AES.key_to_bv("6d7a883b")
    ]
    expected = [[newBV(0x48), newBV(0x6c), newBV(0x4e), newBV(0xee)], \
                [newBV(0x67), newBV(0x1d), newBV(0x9d), newBV(0x0d)], \
                [newBV(0x4d), newBV(0xe3), newBV(0xb1), newBV(0x38)], \
                [newBV(0xd6), newBV(0x5f), newBV(0x58), newBV(0xe7)]]
    actual = AES.add_round_key(stateArr, roundKey)
    AES.print_state(expected)
    AES.print_state(actual)
    assert actual == expected
示例#2
0
    def test_add_round_key_0(self):
        rk=[aes.key_bv('00010203'),aes.key_bv('04050607'),aes.key_bv('08090a0b'),\
            aes.key_bv('0c0d0e0f')]

        sa=aes.init_state_array(aes.key_bv('00112233445566778899aabbccddeeff'))
        self.assertEqual(aes.state_str(aes.add_round_key(sa,rk)),\
                         '00102030405060708090a0b0c0d0e0f0',\
            "Test add round key from FIPS-197 C.1 round[0]")
示例#3
0
    def test_add_round_key_3(self):
        rk=[aes.key_bv('47f7f7bc'),aes.key_bv('95353e03'),aes.key_bv('f96c32bc'),\
            aes.key_bv('fd058dfd')]

        sa = aes.init_state_array(
            aes.key_bv('6385b79ffc538df997be478e7547d691'))
        self.assertEqual(aes.state_str(aes.add_round_key(sa,rk)),\
                         '247240236966b3fa6ed2753288425b6c',\
            "Test add round key from FIPS-197 C.1 round[3]")
示例#4
0
    def test_add_round_key_2(self):
        rk=[aes.key_bv('b692cf0b'),aes.key_bv('643dbdf1'),aes.key_bv('be9bc500'),\
            aes.key_bv('6830b3fe')]

        sa = aes.init_state_array(
            aes.key_bv('ff87968431d86a51645151fa773ad009'))
        self.assertEqual(aes.state_str(aes.add_round_key(sa,rk)),\
                         '4915598f55e5d7a0daca94fa1f0a63f7',\
            "Test add round key from FIPS-197 C.1 round[2]")
示例#5
0
    def test_add_round_key_1(self):
        rk=[aes.key_bv('d6aa74fd'),aes.key_bv('d2af72fa'),aes.key_bv('daa678f1'),\
            aes.key_bv('d6ab76fe')]

        sa = aes.init_state_array(
            aes.key_bv('5f72641557f5bc92f7be3b291db9f91a'))
        self.assertEqual(aes.state_str(aes.add_round_key(sa,rk)),\
                         '89d810e8855ace682d1843d8cb128fe4',\
            "Test add round key from FIPS-197 C.1 round[1]")
示例#6
0
    def test_add_round_key_0(self):
        rk=[aes.key_bv('00010203'),aes.key_bv('04050607'),aes.key_bv('08090a0b'),\
            aes.key_bv('0c0d0e0f')]

        sa = aes.init_state_array(
            aes.key_bv('00112233445566778899aabbccddeeff'))
        self.assertEqual(aes.state_str(aes.add_round_key(sa,rk)),\
                         '00102030405060708090a0b0c0d0e0f0',\
            "Test add round key from FIPS-197 C.1 round[0]")
示例#7
0
    def test_add_round_key_3(self):
        rk=[aes.key_bv('47f7f7bc'),aes.key_bv('95353e03'),aes.key_bv('f96c32bc'),\
            aes.key_bv('fd058dfd')]
        

        sa=aes.init_state_array(aes.key_bv('6385b79ffc538df997be478e7547d691'))
        self.assertEqual(aes.state_str(aes.add_round_key(sa,rk)),\
                         '247240236966b3fa6ed2753288425b6c',\
            "Test add round key from FIPS-197 C.1 round[3]")     
示例#8
0
    def test_add_round_key_2(self):
        rk=[aes.key_bv('b692cf0b'),aes.key_bv('643dbdf1'),aes.key_bv('be9bc500'),\
            aes.key_bv('6830b3fe')]
    

        sa=aes.init_state_array(aes.key_bv('ff87968431d86a51645151fa773ad009'))
        self.assertEqual(aes.state_str(aes.add_round_key(sa,rk)),\
                         '4915598f55e5d7a0daca94fa1f0a63f7',\
            "Test add round key from FIPS-197 C.1 round[2]")     
示例#9
0
    def test_add_round_key_1(self):
        rk=[aes.key_bv('d6aa74fd'),aes.key_bv('d2af72fa'),aes.key_bv('daa678f1'),\
            aes.key_bv('d6ab76fe')]
        

        sa=aes.init_state_array(aes.key_bv('5f72641557f5bc92f7be3b291db9f91a'))
        self.assertEqual(aes.state_str(aes.add_round_key(sa,rk)),\
                         '89d810e8855ace682d1843d8cb128fe4',\
            "Test add round key from FIPS-197 C.1 round[1]")
示例#10
0
def test_add_round_key():
    """
    Test AddRoundKey.
    """
    nk = 1
    state = [0] * 4
    state_ref = [0, 0, 0, 0]
    key_exp = [0, 1, 2, 3]
    enc_round = 0
    offset = len(state)
    aes.add_round_key(state, key_exp, enc_round, offset, nk)
    assert (state == state_ref)

    nk = 4
    state = [x + 1 for x in range(-1, 15)]
    state_ref = [0, 5, 10, 15, 5, 0, 15, 10, 10, 15, 0, 5, 15, 10, 5, 0]
    key_exp = [x + 1 for x in range(-1, 15)]
    enc_round = 0
    offset = len(state)
    aes.add_round_key(state, key_exp, enc_round, offset, nk)
    assert (state == state_ref)
示例#11
0
def test_add_round_key():
    ''' XOR state array sa with roundkey rk to return new state array.
        param sa is a 4x4 state array, param rk is a 4-word round key '''
    stateArr = [[newBV(0x04), newBV(0x66), newBV(0x81), newBV(0xe5)], \
                [newBV(0xe0), newBV(0xcb), newBV(0x19), newBV(0x9a)], \
                [newBV(0x48), newBV(0xf8), newBV(0xd3), newBV(0x7a)], \
                [newBV(0x28), newBV(0x06), newBV(0x26), newBV(0x4c)]]
    roundKey = [AES.key_to_bv("a0fafe17"), AES.key_to_bv("88542cb1"), AES.key_to_bv("23a33939"), AES.key_to_bv("2a6c7605")]
    expected = [[newBV(0xa4), newBV(0x9c), newBV(0x7f), newBV(0xf2)],\
                [newBV(0x68), newBV(0x9f), newBV(0x35), newBV(0x2b)],\
                [newBV(0x6b), newBV(0x5b), newBV(0xea), newBV(0x43)],\
                [newBV(0x02), newBV(0x6a), newBV(0x50), newBV(0x49)]]
    actual = AES.add_round_key(stateArr, roundKey)
    assert actual == expected

    stateArr = [[newBV(0x58), newBV(0x4d), newBV(0xca), newBV(0xf1)], \
                [newBV(0x1b), newBV(0x4b), newBV(0x5a), newBV(0xac)], \
                [newBV(0xdb), newBV(0xe7), newBV(0xca), newBV(0xa8)], \
                [newBV(0x1b), newBV(0x6b), newBV(0xb0), newBV(0xe5)]]
    roundKey = [AES.key_to_bv("f2c295f2"), AES.key_to_bv("7a96b943"), AES.key_to_bv("5935807a"), AES.key_to_bv("7359f67f")]
    expected = [[newBV(0xaa), newBV(0x8f), newBV(0x5f), newBV(0x03)], \
                [newBV(0x61), newBV(0xdd), newBV(0xe3), newBV(0xef)], \
                [newBV(0x82), newBV(0xd2), newBV(0x4a), newBV(0xd2)], \
                [newBV(0x68), newBV(0x32), newBV(0x46), newBV(0x9a)]]
    actual = AES.add_round_key(stateArr, roundKey)
    assert actual == expected

    stateArr = [[newBV(0x75), newBV(0xec), newBV(0x09), newBV(0x93)], \
                [newBV(0x20), newBV(0x0b), newBV(0x63), newBV(0x33)], \
                [newBV(0x53), newBV(0xc0), newBV(0xcf), newBV(0x7c)], \
                [newBV(0xbb), newBV(0x25), newBV(0xd0), newBV(0xdc)]]
    roundKey = [AES.key_to_bv("3d80477d"), AES.key_to_bv("4716fe3e"), AES.key_to_bv("1e237e44"), AES.key_to_bv("6d7a883b")]
    expected = [[newBV(0x48), newBV(0x6c), newBV(0x4e), newBV(0xee)], \
                [newBV(0x67), newBV(0x1d), newBV(0x9d), newBV(0x0d)], \
                [newBV(0x4d), newBV(0xe3), newBV(0xb1), newBV(0x38)], \
                [newBV(0xd6), newBV(0x5f), newBV(0x58), newBV(0xe7)]]
    actual = AES.add_round_key(stateArr, roundKey)
    AES.print_state(expected)
    AES.print_state(actual)
    assert actual == expected