viff

changeset 861:f0aa454c9b91

Generate multiplication triples with PRSS.
author Martin Geisler <mg@daimi.au.dk>
date Wed, 30 Jul 2008 22:46:53 +0200
parents b6ae408a0b4f
children 14be5568022c
files viff/runtime.py
diffstat 1 files changed, 31 insertions(+), 1 deletions(-) [+]
line diff
     1.1 --- a/viff/runtime.py	Wed Jul 30 22:45:42 2008 +0200
     1.2 +++ b/viff/runtime.py	Wed Jul 30 22:46:53 2008 +0200
     1.3 @@ -1127,7 +1127,7 @@
     1.4          # This will be the result, a Share object.
     1.5          result = Share(self, share_x.field)
     1.6          # This is the Deferred we will do processing on.
     1.7 -        triple = self.get_triple(share_x.field)
     1.8 +        triple = self.prss_get_triple(share_x.field)
     1.9          self.schedule_callback(triple, finish_mul)
    1.10          # We add the result to the chains in triple.
    1.11          triple.chainDeferred(result)
    1.12 @@ -1364,6 +1364,36 @@
    1.13          return T, result
    1.14  
    1.15      @increment_pc
    1.16 +    @preprocess("prss_generate_triple")
    1.17 +    def prss_get_triple(self, field):
    1.18 +        count, result = self.prss_generate_triple(field)
    1.19 +        result.addCallback(lambda triples: triples[0])
    1.20 +        return result
    1.21 +
    1.22 +    @increment_pc
    1.23 +    def prss_generate_triple(self, field):
    1.24 +        """Generate a multiplication triple using PRSS.
    1.25 +
    1.26 +        These are random numbers *a*, *b*, and *c* such that ``c =
    1.27 +        ab``. This function can be used in pre-processing.
    1.28 +
    1.29 +        Returns a tuple with the number of triples generated (1) and a
    1.30 +        Deferred which will yield a singleton-list with a 3-tuple.
    1.31 +        """
    1.32 +        a_t = self.prss_share_random(field)
    1.33 +        b_t = self.prss_share_random(field)
    1.34 +        r_t, r_2t = self.prss_double_share(field)
    1.35 +
    1.36 +        # Multiply a and b without resharing.
    1.37 +        c_2t = gather_shares([a_t, b_t])
    1.38 +        c_2t.addCallback(lambda (a, b): a * b)
    1.39 +
    1.40 +        d_2t = c_2t - r_2t
    1.41 +        d = self.open(d_2t, threshold=2*self.threshold)
    1.42 +        c_t = r_t + d
    1.43 +        return 1, succeed([(a_t, b_t, c_t)])
    1.44 +
    1.45 +    @increment_pc
    1.46      def _broadcast(self, sender, message=None):
    1.47          """Perform a Bracha broadcast.
    1.48