changeset 1324:382f0eb42dca

field: Optimized standard path in GF256 operations.
author Marcel Keller <mkeller@cs.au.dk>
date Thu, 22 Oct 2009 19:38:16 +0200
parents 2fb6e3f39e69
children 613aa672ba5e
files viff/field.py
diffstat 1 files changed, 10 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/viff/field.py	Tue Oct 06 18:37:52 2009 +0200
+++ b/viff/field.py	Thu Oct 22 19:38:16 2009 +0200
@@ -162,15 +162,16 @@
         >>> GF256(0x01) + 1
         [0]
         """
-        if not isinstance(other, (GF256, int, long)):
+        if isinstance(other, GF256):
+            return _add_table[self.value][other.value]
+        elif isinstance(other, (int, long)):
+            return _add_table[self.value][other]
+        else:
             # This occurs with code like 'a + b' where b is a Share.
             # In that case we must return NotImplemented to signal
             # that b.__radd__(a) should be run instead. The Share will
             # then schedule things correctly.
             return NotImplemented
-        if isinstance(other, GF256):
-            other = other.value
-        return _add_table[self.value][other]
 
     def __radd__(self, other):
         """Add this and another number (reflected argument version).
@@ -206,12 +207,12 @@
         >>> GF256(16) * GF256(32)
         [54]
         """
-        if not isinstance(other, (GF256, int, long)):
+        if isinstance(other, GF256):
+            return _mul_table[self.value][other.value]
+        elif isinstance(other, (int, long)):
+            return _mul_table[self.value][other]
+        else:
             return NotImplemented
-        if isinstance(other, GF256):
-            other = other.value
-        return _mul_table[self.value][other]
-
 
     def __rmul__(self, other):
         """Multiply this and another number (reflected argument