viff

changeset 910:3f5367d1fcc7

Moved prss_generate_triple to a new mixin.
author Martin Geisler <mg@daimi.au.dk>
date Mon, 15 Sep 2008 16:46:41 +0200
parents e36009fd979a
children 47734eb343ed
files doc/active.txt viff/active.py
diffstat 2 files changed, 37 insertions(+), 32 deletions(-) [+]
line diff
     1.1 --- a/doc/active.txt	Mon Sep 15 16:24:06 2008 +0200
     1.2 +++ b/doc/active.txt	Mon Sep 15 16:46:41 2008 +0200
     1.3 @@ -12,3 +12,6 @@
     1.4  
     1.5     .. autoclass:: TriplesHyperinvertibleMatricesMixin
     1.6        :members:
     1.7 +
     1.8 +   .. autoclass:: TriplesPRSSMixin
     1.9 +      :members:
     2.1 --- a/viff/active.py	Mon Sep 15 16:24:06 2008 +0200
     2.2 +++ b/viff/active.py	Mon Sep 15 16:46:41 2008 +0200
     2.3 @@ -408,8 +408,41 @@
     2.4          self.schedule_callback(result, make_triple)
     2.5          return T, result
     2.6  
     2.7 +class TriplesPRSSMixin:
     2.8 +    """Mixin class for generating multiplication triples using PRSS."""
     2.9  
    2.10 -class ActiveRuntime(Runtime):
    2.11 +    @increment_pc
    2.12 +    @preprocess("generate_triple")
    2.13 +    def prss_get_triple(self, field):
    2.14 +        count, result = self.prss_generate_triple(field)
    2.15 +        result.addCallback(lambda triples: triples[0])
    2.16 +        return result
    2.17 +
    2.18 +    @increment_pc
    2.19 +    def prss_generate_triple(self, field):
    2.20 +        """Generate a multiplication triple using PRSS.
    2.21 +
    2.22 +        These are random numbers *a*, *b*, and *c* such that ``c =
    2.23 +        ab``. This function can be used in pre-processing.
    2.24 +
    2.25 +        Returns a tuple with the number of triples generated (1) and a
    2.26 +        Deferred which will yield a singleton-list with a 3-tuple.
    2.27 +        """
    2.28 +        a_t = self.prss_share_random(field)
    2.29 +        b_t = self.prss_share_random(field)
    2.30 +        r_t, r_2t = self.prss_double_share(field)
    2.31 +
    2.32 +        # Multiply a and b without resharing.
    2.33 +        c_2t = gather_shares([a_t, b_t])
    2.34 +        c_2t.addCallback(lambda (a, b): a * b)
    2.35 +
    2.36 +        d_2t = c_2t - r_2t
    2.37 +        d = self.open(d_2t, threshold=2*self.threshold)
    2.38 +        c_t = r_t + d
    2.39 +        return 1, succeed([(a_t, b_t, c_t)])
    2.40 +
    2.41 +
    2.42 +class ActiveRuntime(Runtime, TriplesPRSSMixin):
    2.43      """A runtime secure against active adversaries.
    2.44  
    2.45      This class currently inherits most of its functionality from the
    2.46 @@ -466,34 +499,3 @@
    2.47          # We add the result to the chains in triple.
    2.48          triple.chainDeferred(result)
    2.49          return result
    2.50 -
    2.51 -    @increment_pc
    2.52 -    @preprocess("generate_triple")
    2.53 -    def prss_get_triple(self, field):
    2.54 -        count, result = self.prss_generate_triple(field)
    2.55 -        result.addCallback(lambda triples: triples[0])
    2.56 -        return result
    2.57 -
    2.58 -    @increment_pc
    2.59 -    def prss_generate_triple(self, field):
    2.60 -        """Generate a multiplication triple using PRSS.
    2.61 -
    2.62 -        These are random numbers *a*, *b*, and *c* such that ``c =
    2.63 -        ab``. This function can be used in pre-processing.
    2.64 -
    2.65 -        Returns a tuple with the number of triples generated (1) and a
    2.66 -        Deferred which will yield a singleton-list with a 3-tuple.
    2.67 -        """
    2.68 -        a_t = self.prss_share_random(field)
    2.69 -        b_t = self.prss_share_random(field)
    2.70 -        r_t, r_2t = self.prss_double_share(field)
    2.71 -
    2.72 -        # Multiply a and b without resharing.
    2.73 -        c_2t = gather_shares([a_t, b_t])
    2.74 -        c_2t.addCallback(lambda (a, b): a * b)
    2.75 -
    2.76 -        d_2t = c_2t - r_2t
    2.77 -        d = self.open(d_2t, threshold=2*self.threshold)
    2.78 -        c_t = r_t + d
    2.79 -        return 1, succeed([(a_t, b_t, c_t)])
    2.80 -