viff

changeset 1355:58ebae853020

Orlandi:Inlined step2 a and b of triple_gen.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Tue, 27 Oct 2009 22:01:24 +0100
parents f0ef1b584a44
children c467cba12cfb
files viff/orlandi.py
diffstat 1 files changed, 23 insertions(+), 31 deletions(-) [+]
line diff
     1.1 --- a/viff/orlandi.py	Tue Oct 27 21:41:00 2009 +0100
     1.2 +++ b/viff/orlandi.py	Tue Oct 27 22:01:24 2009 +0100
     1.3 @@ -864,7 +864,7 @@
     1.4                                                As, Bs, ai, bi, ci, r, s, t, dijs))
     1.5              return result
     1.6  
     1.7 -        def step2c(Bs, As, alphas, alpha_randomness, ai, bj, r, s):
     1.8 +        def step2c((alphas, As, Bs), alpha_randomness, ai, bj, r, s):
     1.9              """(c) P_j do, towards every other party:
    1.10                     i. choose random d_i,j in Z_p^3
    1.11                     ii. compute and send
    1.12 @@ -904,26 +904,6 @@
    1.13              result.addErrback(self.error_handler)
    1.14              return result
    1.15  
    1.16 -        def step2ab((alphas, As), ai, r, alpha_randomness):
    1.17 -            """2) Every party P_j does:
    1.18 -                  (a) choose random b_j, s_j in Z_p X (Z_p)^2.
    1.19 -
    1.20 -                  (b) compute B_j = Com_ck(b_j, s_j) and broadcast it.
    1.21 -            """
    1.22 -            # (a) choose random b_j, s_j in Z_p X (Z_p)^2.
    1.23 -            bj = random_number(field.modulus)
    1.24 -            s1 = random_number(field.modulus)
    1.25 -            s2 = random_number(field.modulus)
    1.26 -            # (b) compute B_j = Com_ck(b_j, s_j).
    1.27 -            Bj = commitment.commit(bj.value, s1.value, s2.value)
    1.28 -
    1.29 -            # Broadcast B_j.
    1.30 -            results = self.broadcast(self.players.keys(), self.players.keys(), repr(Bj))
    1.31 -            result = gatherResults(results)
    1.32 -            self.schedule_callback(result, step2c, As, alphas, alpha_randomness,
    1.33 -                                   ai, bj, r, (s1, s2))
    1.34 -            result.addErrback(self.error_handler)
    1.35 -            return result
    1.36  
    1.37          # 1) Every party P_i chooses random values a_i, r_i in Z_p X (Z_p)^2,
    1.38          #    compute alpha_i = Enc_eki(a_i) and Ai = Com_ck(a_i, r_i), and
    1.39 @@ -941,24 +921,36 @@
    1.40          # and A_i = Com_ck(a_i, r_i).
    1.41          Ai = commitment.commit(ai.value, r1.value, r2.value)
    1.42  
    1.43 -        # broadcast alpha_i and A_i.
    1.44 +        # choose random b_j, s_j in Z_p X (Z_p)^2.
    1.45 +        bj = random_number(field.modulus)
    1.46 +        s1 = random_number(field.modulus)
    1.47 +        s2 = random_number(field.modulus)
    1.48 +        # compute B_j = Com_ck(b_j, s_j).
    1.49 +        Bj = commitment.commit(bj.value, s1.value, s2.value)
    1.50 +
    1.51 +        # broadcast alpha_i, A_i, B_j.
    1.52          ds = self.broadcast(sorted(self.players.keys()),
    1.53                              sorted(self.players.keys()),
    1.54 -                            str(alphai) + ":" + repr(Ai))
    1.55 +                            str(alphai) + ":" + repr(Ai) + ":" + repr(Bj))
    1.56  
    1.57 -        result = gatherResults(ds)
    1.58 -        def split_alphas_and_As(ls):
    1.59 +        alphas_As_Bs = gatherResults(ds)
    1.60 +        def split_alphas_As_Bs(ls):
    1.61              alphas = []
    1.62              As = []
    1.63 +            Bs = []
    1.64              for x in ls:
    1.65 -                alpha, Ai = x.split(':')
    1.66 +                alpha, Ai, Bj = x.split(':')
    1.67                  alphas.append(long(alpha))
    1.68                  As.append(Ai)
    1.69 -            return alphas, As
    1.70 -        self.schedule_callback(result, split_alphas_and_As)
    1.71 -        self.schedule_callback(result, step2ab, ai, (r1, r2), alpha_randomness)
    1.72 -        result.addErrback(self.error_handler)
    1.73 -        return result
    1.74 +                Bs.append(Bj)
    1.75 +            return alphas, As, Bs
    1.76 +        alphas_As_Bs.addCallbacks(split_alphas_As_Bs, self.error_handler)
    1.77 +
    1.78 +        self.schedule_callback(alphas_As_Bs, step2c, alpha_randomness, 
    1.79 +                               ai, bj, (r1, r2), (s1, s2))
    1.80 +        alphas_As_Bs.addErrback(self.error_handler)
    1.81 +        return alphas_As_Bs
    1.82 +
    1.83  
    1.84      def triple_test(self, field):
    1.85          """Generate a triple ``(a, b, c)`` where ``c = a * b``.