viff

changeset 1576:d2e456c89f9f

aes: Online masked exponentiation.
author Marcel Keller <m.keller@bristol.ac.uk>
date Thu, 29 Mar 2012 10:56:14 +0100
parents cfb8e1485006
children 49ddac9bf0fa
files viff/aes.py
diffstat 1 files changed, 19 insertions(+), 1 deletions(-) [+]
line diff
     1.1 --- a/viff/aes.py	Wed Dec 15 13:00:00 2010 +0100
     1.2 +++ b/viff/aes.py	Thu Mar 29 10:56:14 2012 +0100
     1.3 @@ -115,6 +115,8 @@
     1.4                  self.invert = self.invert_by_exponentiation_with_least_rounds
     1.5              elif use_exponentiation == "masked":
     1.6                  self.invert = self.invert_by_masked_exponentiation
     1.7 +            elif use_exponentiation == "masked_online":
     1.8 +                self.invert = self.invert_by_masked_exponentiation_online
     1.9              else:
    1.10                  self.invert = self.invert_by_exponentiation
    1.11          else:
    1.12 @@ -127,7 +129,8 @@
    1.13                                 "shortest_sequential_chain",
    1.14                                 "shortest_chain_with_least_rounds",
    1.15                                 "chain_with_least_rounds",
    1.16 -                               "masked"]
    1.17 +                               "masked",
    1.18 +                               "masked_online"]
    1.19  
    1.20      def invert_by_masking(self, byte):
    1.21          bits = bit_decompose(byte)
    1.22 @@ -179,6 +182,21 @@
    1.23          return self.runtime.schedule_callback(
    1.24              masked_byte, add_and_multiply, random_powers, prep)
    1.25  
    1.26 +    # constants for efficient computation of x^2, x^4, x^8 etc.
    1.27 +    powers_of_two = [[GF256(2**j)**(2**i) for j in range(8)] for i in range(8)]
    1.28 +
    1.29 +    def invert_by_masked_exponentiation_online(self, byte):
    1.30 +        bits = bit_decompose(byte)
    1.31 +        byte_powers = []
    1.32 +
    1.33 +        for i in range(1,8):
    1.34 +            byte_powers.append(self.runtime.lin_comb(AES.powers_of_two[i], bits))
    1.35 +
    1.36 +        while len(byte_powers) > 1:
    1.37 +            byte_powers.append(byte_powers.pop(0) * byte_powers.pop(0))
    1.38 +
    1.39 +        return byte_powers[0]
    1.40 +
    1.41      def invert_by_exponentiation(self, byte):
    1.42          byte_2 = byte * byte
    1.43          byte_3 = byte_2 * byte