viff

changeset 1097:50056a810951

Optimization: Use lin_comb() instead of Matrix class in mix_column().
author Marcel Keller <mkeller@cs.au.dk>
date Fri, 30 Jan 2009 14:50:47 +0100
parents 072920ec7f69
children 54a68af0a945 006bdec768e6 87f37eb25159 56d259ed2a3d
files viff/aes.py
diffstat 1 files changed, 9 insertions(+), 2 deletions(-) [+]
line diff
     1.1 --- a/viff/aes.py	Fri Jan 30 14:19:54 2009 +0100
     1.2 +++ b/viff/aes.py	Fri Jan 30 14:50:47 2009 +0100
     1.3 @@ -202,14 +202,21 @@
     1.4  
     1.5      C = Matrix(C)
     1.6  
     1.7 -    def mix_column(self, state):
     1.8 +    def mix_column(self, state, use_lin_comb=True):
     1.9          """Rijndael MixColumn.
    1.10  
    1.11          Input should be a list of 4 rows."""
    1.12  
    1.13          assert len(state) == 4, "Wrong state size."
    1.14  
    1.15 -        state[:] = (AES.C * Matrix(state)).rows
    1.16 +        if (use_lin_comb):
    1.17 +            columns = zip(*state)
    1.18 +
    1.19 +            for i, row in enumerate(state):
    1.20 +                row[:] = [self.runtime.lin_comb(AES.C.rows[i], column)
    1.21 +                          for column in columns]
    1.22 +        else:
    1.23 +            state[:] = (AES.C * Matrix(state)).rows
    1.24  
    1.25      def add_round_key(self, state, round_key):
    1.26          """Rijndael AddRoundKey.