viff

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 diff
     1.1 --- a/viff/aes.py	Mon Jul 27 12:16:25 2009 +0200
     1.2 +++ b/viff/aes.py	Mon Jul 27 15:24:11 2009 +0200
     1.3 @@ -107,6 +107,8 @@
     1.4                  self.invert = lambda byte: byte ** 254
     1.5              elif (use_exponentiation == "shortest_chain_with_least_rounds"):
     1.6                  self.invert = self.invert_by_exponentiation_with_less_rounds
     1.7 +            elif (use_exponentiation == "chain_with_least_rounds"):
     1.8 +                self.invert = self.invert_by_exponentiation_with_least_rounds
     1.9              else:
    1.10                  self.invert = self.invert_by_exponentiation
    1.11          else:
    1.12 @@ -117,7 +119,8 @@
    1.13  
    1.14      exponentiation_variants = ["standard_square_and_multiply",
    1.15                                 "shortest_sequential_chain",
    1.16 -                               "shortest_chain_with_least_rounds"]
    1.17 +                               "shortest_chain_with_least_rounds",
    1.18 +                               "chain_with_least_rounds"]
    1.19  
    1.20      def invert_by_masking(self, byte):
    1.21          bits = bit_decompose(byte)
    1.22 @@ -181,6 +184,22 @@
    1.23          byte_254 = byte_200 * byte_54
    1.24          return byte_254
    1.25  
    1.26 +    def invert_by_exponentiation_with_least_rounds(self, byte):
    1.27 +        byte_2 = byte * byte
    1.28 +        byte_3 = byte_2 * byte
    1.29 +        byte_4 = byte_2 * byte_2
    1.30 +        byte_7 = byte_4 * byte_3
    1.31 +        byte_8 = byte_4 * byte_4
    1.32 +        byte_15 = byte_8 * byte_7
    1.33 +        byte_16 = byte_8 * byte_8
    1.34 +        byte_31 = byte_16 * byte_15
    1.35 +        byte_32 = byte_16 * byte_16
    1.36 +        byte_63 = byte_32 * byte_31
    1.37 +        byte_64 = byte_32 * byte_32
    1.38 +        byte_127 = byte_64 * byte_63
    1.39 +        byte_254 = byte_127 * byte_127
    1.40 +        return byte_254
    1.41 +
    1.42      # matrix for byte_sub, the last column is the translation vector
    1.43      A = Matrix([[1,0,0,0,1,1,1,1, 1],
    1.44                  [1,1,0,0,0,1,1,1, 1],