viff

changeset 1322:5a2e6564c40a

Optimize by using reflected argument version of overloaded operators.
author Marcel Keller <mkeller@cs.au.dk>
date Tue, 06 Oct 2009 17:52:14 +0200
parents 71f205befbbb
children 2fb6e3f39e69
files viff/aes.py viff/passive.py
diffstat 2 files changed, 4 insertions(+), 8 deletions(-) [+]
line diff
     1.1 --- a/viff/aes.py	Tue Oct 06 14:18:55 2009 +0200
     1.2 +++ b/viff/aes.py	Tue Oct 06 17:52:14 2009 +0200
     1.3 @@ -129,7 +129,7 @@
     1.4          bits = bit_decompose(byte)
     1.5  
     1.6          for j in range(len(bits)):
     1.7 -            bits[j].addCallback(lambda x: GF256(1) - x)
     1.8 +            bits[j].addCallback(lambda x: 1 - x)
     1.9  #            bits[j] = 1 - bits[j]
    1.10  
    1.11          while(len(bits) > 1):
    1.12 @@ -278,10 +278,6 @@
    1.13           [1, 1, 2, 3],
    1.14           [3, 1, 1, 2]]
    1.15  
    1.16 -    for row in C:
    1.17 -        for i in xrange(len(row)):
    1.18 -            row[i] = GF256(row[i])
    1.19 -
    1.20      C = Matrix(C)
    1.21  
    1.22      def mix_column(self, state, use_lin_comb=True):
     2.1 --- a/viff/passive.py	Tue Oct 06 14:18:55 2009 +0200
     2.2 +++ b/viff/passive.py	Tue Oct 06 17:52:14 2009 +0200
     2.3 @@ -127,7 +127,7 @@
     2.4              # operator overloading in Share. Clone share_a to avoid
     2.5              # changing it.
     2.6              result = share_a.clone()
     2.7 -            result.addCallback(lambda a, b: a + b, share_b)
     2.8 +            result.addCallback(lambda a, b: b + a, share_b)
     2.9              return result
    2.10          
    2.11          result = gather_shares([share_a, share_b])
    2.12 @@ -168,7 +168,7 @@
    2.13              "Number of coefficients and shares should be equal."
    2.14  
    2.15          def computation(shares, coefficients):
    2.16 -            return sum(map(operator.mul, shares, coefficients))
    2.17 +            return sum(map(operator.mul, coefficients, shares))
    2.18  
    2.19          result = gather_shares(shares)
    2.20          result.addCallback(computation, coefficients)
    2.21 @@ -189,7 +189,7 @@
    2.22              # operator overloading in Share. We clone share_a first
    2.23              # to avoid changing it.
    2.24              result = share_a.clone()
    2.25 -            result.addCallback(lambda a: a * share_b)
    2.26 +            result.addCallback(lambda a: share_b * a)
    2.27              return result
    2.28  
    2.29          # At this point both share_a and share_b must be Share