viff

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 diff
     1.1 --- a/viff/field.py	Tue Oct 06 18:37:52 2009 +0200
     1.2 +++ b/viff/field.py	Thu Oct 22 19:38:16 2009 +0200
     1.3 @@ -162,15 +162,16 @@
     1.4          >>> GF256(0x01) + 1
     1.5          [0]
     1.6          """
     1.7 -        if not isinstance(other, (GF256, int, long)):
     1.8 +        if isinstance(other, GF256):
     1.9 +            return _add_table[self.value][other.value]
    1.10 +        elif isinstance(other, (int, long)):
    1.11 +            return _add_table[self.value][other]
    1.12 +        else:
    1.13              # This occurs with code like 'a + b' where b is a Share.
    1.14              # In that case we must return NotImplemented to signal
    1.15              # that b.__radd__(a) should be run instead. The Share will
    1.16              # then schedule things correctly.
    1.17              return NotImplemented
    1.18 -        if isinstance(other, GF256):
    1.19 -            other = other.value
    1.20 -        return _add_table[self.value][other]
    1.21  
    1.22      def __radd__(self, other):
    1.23          """Add this and another number (reflected argument version).
    1.24 @@ -206,12 +207,12 @@
    1.25          >>> GF256(16) * GF256(32)
    1.26          [54]
    1.27          """
    1.28 -        if not isinstance(other, (GF256, int, long)):
    1.29 +        if isinstance(other, GF256):
    1.30 +            return _mul_table[self.value][other.value]
    1.31 +        elif isinstance(other, (int, long)):
    1.32 +            return _mul_table[self.value][other]
    1.33 +        else:
    1.34              return NotImplemented
    1.35 -        if isinstance(other, GF256):
    1.36 -            other = other.value
    1.37 -        return _mul_table[self.value][other]
    1.38 -
    1.39  
    1.40      def __rmul__(self, other):
    1.41          """Multiply this and another number (reflected argument