changeset 1205:86d0c1d49af8

Added an inversion by exponentiation variant with least rounds.
author Marcel Keller <mkeller@cs.au.dk>
date Mon, 27 Jul 2009 15:24:11 +0200
parents d43f766c4cac
children 104d89587c94
files viff/aes.py
diffstat 1 files changed, 20 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/viff/aes.py	Mon Jul 27 12:16:25 2009 +0200
+++ b/viff/aes.py	Mon Jul 27 15:24:11 2009 +0200
@@ -107,6 +107,8 @@
                 self.invert = lambda byte: byte ** 254
             elif (use_exponentiation == "shortest_chain_with_least_rounds"):
                 self.invert = self.invert_by_exponentiation_with_less_rounds
+            elif (use_exponentiation == "chain_with_least_rounds"):
+                self.invert = self.invert_by_exponentiation_with_least_rounds
             else:
                 self.invert = self.invert_by_exponentiation
         else:
@@ -117,7 +119,8 @@
 
     exponentiation_variants = ["standard_square_and_multiply",
                                "shortest_sequential_chain",
-                               "shortest_chain_with_least_rounds"]
+                               "shortest_chain_with_least_rounds",
+                               "chain_with_least_rounds"]
 
     def invert_by_masking(self, byte):
         bits = bit_decompose(byte)
@@ -181,6 +184,22 @@
         byte_254 = byte_200 * byte_54
         return byte_254
 
+    def invert_by_exponentiation_with_least_rounds(self, byte):
+        byte_2 = byte * byte
+        byte_3 = byte_2 * byte
+        byte_4 = byte_2 * byte_2
+        byte_7 = byte_4 * byte_3
+        byte_8 = byte_4 * byte_4
+        byte_15 = byte_8 * byte_7
+        byte_16 = byte_8 * byte_8
+        byte_31 = byte_16 * byte_15
+        byte_32 = byte_16 * byte_16
+        byte_63 = byte_32 * byte_31
+        byte_64 = byte_32 * byte_32
+        byte_127 = byte_64 * byte_63
+        byte_254 = byte_127 * byte_127
+        return byte_254
+
     # matrix for byte_sub, the last column is the translation vector
     A = Matrix([[1,0,0,0,1,1,1,1, 1],
                 [1,1,0,0,0,1,1,1, 1],