예제 #1
0
    def test_AddRoundKey(self):
        # for input = key the result should be 0
        instance = AES(key=("test" * 3))
        input = [gf._cache.fetch_int(i) for i in xrange(16)]
        key = [gf._cache.fetch_int(i) for i in xrange(16)]
        expected_result = [gf(0)] * 16
        result = instance.AddRoundKey(input, key)
        self.assertEquals(expected_result, result)

        # for each position the result should be the xor result
        input = [gf._cache.fetch_int(i) for i in xrange(16)]
        key = [gf._cache.fetch_int(i + i) for i in xrange(16)]
        result = instance.AddRoundKey(input, key)
        self.assertEquals(len(result), len(input))
        for i in xrange(len(result)):
            self.assertEquals(input[i] + key[i], result[i])

        # inversion test: applying the same key again should invert the effect
        input = [gf._cache.fetch_int(2 * i) for i in xrange(16)]
        key = [gf._cache.fetch_int(i**2) for i in xrange(16)]
        result = instance.AddRoundKey(input, key)
        self.assertEquals(input, instance.AddRoundKey(result, key))