diff -r 7cf3e950211d viff/field.py --- a/viff/field.py Sun Sep 21 19:25:14 2008 +0200 +++ b/viff/field.py Wed Sep 24 16:01:12 2008 +0200 @@ -85,6 +85,7 @@ #: Maps *(x,y)* to *xy*. See `_generate_tables`. _mul_table = {} +_mpz_type = type(mpz(1)) # The class name is slightly wrong since the class instances cannot be # said to be represent a field. Instead they represent instances of @@ -103,6 +104,8 @@ >>> GF256(1) == GF256(257) True """ + if isinstance(value, _mpz_type): + value = int(value) self.value = value % self.modulus def __add__(self, other): @@ -248,6 +251,14 @@ """ return self.value != 0 + @classmethod + def marshal_representation(cls, value): + """Returns a version of this value suitable for + serializing with marshal. + + We just return the value, as it is an int.""" + return value + # We provide the class here to make the construction of new elements # easy in a polymorphic context. GF256.field = GF256 @@ -337,8 +348,10 @@ class GFElement(FieldElement): def __init__(self, value): - self.value = value % self.modulus - + if isinstance(value, str): + self.value = mpz(value, 256) % self.modulus + else: + self.value = mpz(value) % self.modulus def __add__(self, other): """Addition.""" if not isinstance(other, (GFElement, int, long)): @@ -508,7 +521,15 @@ """ return self.value != 0 - GFElement.modulus = modulus + @classmethod + def marshal_representation(cls, value): + """Returns a version of this value suitable for + serializing with marshal. + + We take the string representation of the mpz""" + return value.binary() + + GFElement.modulus = mpz(modulus) GFElement.field = GFElement _field_cache[modulus] = GFElement diff -r 7cf3e950211d viff/runtime.py --- a/viff/runtime.py Sun Sep 21 19:25:14 2008 +0200 +++ b/viff/runtime.py Wed Sep 24 16:01:12 2008 +0200 @@ -320,7 +320,10 @@ The program counter and the share are marshalled and sent to the peer. """ - self.sendData(program_counter, "share", share.value) + if share.field is GF256: + self.sendData(program_counter, "share", share.value) + else: + self.sendData(program_counter, "share", share.value.binary()) def loseConnection(self): """Disconnect this protocol instance."""