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 wrap: on
line diff
--- a/viff/aes.py	Thu Feb 05 16:14:01 2009 +0100
+++ b/viff/aes.py	Thu Feb 05 17:03:30 2009 +0100
@@ -71,7 +71,7 @@
     """
 
     def __init__(self, runtime, key_size, block_size=128, 
-                 use_exponentiation=False):
+                 use_exponentiation=False, use_square_and_multiply=False):
         """Initialize Rijndael.
 
         AES(runtime, key_size, block_size), whereas key size and block
@@ -87,6 +87,7 @@
         self.rounds = max(self.n_k, self.n_b) + 6
         self.runtime = runtime
         self.use_exponentiation = use_exponentiation
+        self.use_square_and_multiply = use_square_and_multiply
 
     # matrix for byte_sub, the last column is the translation vector
     A = Matrix([[1,0,0,0,1,1,1,1, 1],
@@ -148,7 +149,10 @@
             return byte_254
 
         if (self.use_exponentiation):
-            invert = invert_by_exponentiation
+            if (self.use_square_and_multiply):
+                invert = lambda byte: byte ** 254
+            else:
+                invert = invert_by_exponentiation
         else:
             invert = invert_by_masking