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 wrap: on
line diff
--- a/viff/aes.py	Tue Oct 06 14:18:55 2009 +0200
+++ b/viff/aes.py	Tue Oct 06 17:52:14 2009 +0200
@@ -129,7 +129,7 @@
         bits = bit_decompose(byte)
 
         for j in range(len(bits)):
-            bits[j].addCallback(lambda x: GF256(1) - x)
+            bits[j].addCallback(lambda x: 1 - x)
 #            bits[j] = 1 - bits[j]
 
         while(len(bits) > 1):
@@ -278,10 +278,6 @@
          [1, 1, 2, 3],
          [3, 1, 1, 2]]
 
-    for row in C:
-        for i in xrange(len(row)):
-            row[i] = GF256(row[i])
-
     C = Matrix(C)
 
     def mix_column(self, state, use_lin_comb=True):
--- a/viff/passive.py	Tue Oct 06 14:18:55 2009 +0200
+++ b/viff/passive.py	Tue Oct 06 17:52:14 2009 +0200
@@ -127,7 +127,7 @@
             # operator overloading in Share. Clone share_a to avoid
             # changing it.
             result = share_a.clone()
-            result.addCallback(lambda a, b: a + b, share_b)
+            result.addCallback(lambda a, b: b + a, share_b)
             return result
         
         result = gather_shares([share_a, share_b])
@@ -168,7 +168,7 @@
             "Number of coefficients and shares should be equal."
 
         def computation(shares, coefficients):
-            return sum(map(operator.mul, shares, coefficients))
+            return sum(map(operator.mul, coefficients, shares))
 
         result = gather_shares(shares)
         result.addCallback(computation, coefficients)
@@ -189,7 +189,7 @@
             # operator overloading in Share. We clone share_a first
             # to avoid changing it.
             result = share_a.clone()
-            result.addCallback(lambda a: a * share_b)
+            result.addCallback(lambda a: share_b * a)
             return result
 
         # At this point both share_a and share_b must be Share