viff

changeset 1131:cf4920b3ae72

Added the possibility to use square-and-multiply for the inversion in AES.
author Marcel Keller <mkeller@cs.au.dk>
date Thu, 05 Feb 2009 17:03:30 +0100
parents 006bdec768e6
children f24861244622
files viff/aes.py
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line diff
     1.1 --- a/viff/aes.py	Thu Feb 05 16:14:01 2009 +0100
     1.2 +++ b/viff/aes.py	Thu Feb 05 17:03:30 2009 +0100
     1.3 @@ -71,7 +71,7 @@
     1.4      """
     1.5  
     1.6      def __init__(self, runtime, key_size, block_size=128, 
     1.7 -                 use_exponentiation=False):
     1.8 +                 use_exponentiation=False, use_square_and_multiply=False):
     1.9          """Initialize Rijndael.
    1.10  
    1.11          AES(runtime, key_size, block_size), whereas key size and block
    1.12 @@ -87,6 +87,7 @@
    1.13          self.rounds = max(self.n_k, self.n_b) + 6
    1.14          self.runtime = runtime
    1.15          self.use_exponentiation = use_exponentiation
    1.16 +        self.use_square_and_multiply = use_square_and_multiply
    1.17  
    1.18      # matrix for byte_sub, the last column is the translation vector
    1.19      A = Matrix([[1,0,0,0,1,1,1,1, 1],
    1.20 @@ -148,7 +149,10 @@
    1.21              return byte_254
    1.22  
    1.23          if (self.use_exponentiation):
    1.24 -            invert = invert_by_exponentiation
    1.25 +            if (self.use_square_and_multiply):
    1.26 +                invert = lambda byte: byte ** 254
    1.27 +            else:
    1.28 +                invert = invert_by_exponentiation
    1.29          else:
    1.30              invert = invert_by_masking
    1.31