viff

changeset 635:a7f03661f81d

FieldElements are now multiplied locally, skipping the resharing step.
author Mikkel Krøigård <mk@daimi.au.dk>
date Fri, 04 Apr 2008 21:16:26 +0200
parents 9d4a0ade3918
children ba9166a59c20
files viff/runtime.py
diffstat 1 files changed, 20 insertions(+), 5 deletions(-) [+]
line diff
     1.1 --- a/viff/runtime.py	Fri Apr 04 11:03:26 2008 +0200
     1.2 +++ b/viff/runtime.py	Fri Apr 04 21:16:26 2008 +0200
     1.3 @@ -717,15 +717,30 @@
     1.4  
     1.5          Communication cost: 1 Shamir sharing.
     1.6          """
     1.7 -        # TODO:  mul accept FieldElements and do quick local
     1.8 -        # multiplication in that case. If two FieldElements are given,
     1.9 -        # return a FieldElement.
    1.10 +        # If one of the arguments is a FieldElement, we do a local
    1.11 +        # multiplication and skip the resharing step.
    1.12 +
    1.13          field = getattr(share_a, "field", getattr(share_b, "field", None))
    1.14 -        if not isinstance(share_a, Share):
    1.15 +
    1.16 +        if not isinstance(share_a, Share) and not isinstance(share_a,
    1.17 +                                                             FieldElement):
    1.18              share_a = Share(self, field, share_a)
    1.19 -        if not isinstance(share_b, Share):
    1.20 +
    1.21 +        if not isinstance(share_b, Share) and not isinstance(share_b,
    1.22 +                                                             FieldElement):
    1.23              share_b = Share(self, field, share_b)
    1.24  
    1.25 +        if isinstance(share_a, FieldElement) and isinstance(share_b,
    1.26 +                                                            FieldElement):
    1.27 +            return Share(self, field, share_a * share_b)
    1.28 +        
    1.29 +        if isinstance(share_a, FieldElement):
    1.30 +            share_b.addCallback(lambda x: Share(self, field, share_a*x.value))
    1.31 +            return share_b
    1.32 +        if isinstance(share_b, FieldElement):
    1.33 +            share_a.addCallback(lambda x: Share(self, field, x.value*share_b))
    1.34 +            return share_a
    1.35 +
    1.36          result = gather_shares([share_a, share_b])
    1.37          result.addCallback(lambda (a, b): a * b)
    1.38          self.schedule_callback(result, self._shamir_share)