viff

changeset 1093:af545b802fd8

Small optimization: Use lin_comb() in byte_sub().
author Marcel Keller <mkeller@cs.au.dk>
date Tue, 27 Jan 2009 14:26:49 +0100
parents d20cb1435966
children bdab6f30511a
files viff/aes.py
diffstat 1 files changed, 7 insertions(+), 3 deletions(-) [+]
line diff
     1.1 --- a/viff/aes.py	Mon Jan 26 10:58:27 2009 +0100
     1.2 +++ b/viff/aes.py	Tue Jan 27 14:26:49 2009 +0100
     1.3 @@ -86,7 +86,7 @@
     1.4                  [0,0,1,1,1,1,1,0],
     1.5                  [0,0,0,1,1,1,1,1]])
     1.6  
     1.7 -    def byte_sub(self, state):
     1.8 +    def byte_sub(self, state, use_lin_comb=True):
     1.9          """ByteSub operation of Rijndael.
    1.10  
    1.11          The first argument should be a matrix consisting of elements
    1.12 @@ -150,8 +150,12 @@
    1.13                  vector = AES.A * Matrix(zip(bits)) + Matrix(zip([1,1,0,0,0,1,1,0]))
    1.14                  bits = zip(*vector.rows)[0]
    1.15  
    1.16 -                row[i] = reduce(lambda x,y: x + y, 
    1.17 -                                [bits[j] * 2**j for j in range(len(bits))])
    1.18 +                if (use_lin_comb):
    1.19 +                    row[i] = self.runtime.lin_comb(
    1.20 +                        [2**j for j in range(len(bits))], bits)
    1.21 +                else:
    1.22 +                    row[i] = reduce(lambda x,y: x + y, 
    1.23 +                                    [bits[j] * 2**j for j in range(len(bits))])
    1.24  
    1.25      def shift_row(self, state):
    1.26          """AES ShiftRow.