def _generate_triple_candidates(self, n): """Generates triple candidates for use in the BeDOZa protocol. Returns a deferred that will eventually yield a list of 3n shares of type viff.bedoza.shares.BeDOZaShare corresponding to n multiplicative tuples. The first n are the a's, then comes n b's followed by n c's. The triples are only candidates because consistency of the triples is only half-way guaranteed in the precense of active adversaries. More concretely, the triples returned by this method are guaranteed - even in the precense of an active adversary - to be of the right size. But they may not satisfy the equation c = a * b. """ self.runtime.increment_pc() gen = PartialShareGenerator(self.Zp, self.runtime, self.random, self.paillier) partial_shares = [] for _ in xrange(2 * n): partial_shares.append( gen.generate_share(self.random.randint(0, self.Zp.modulus - 1))) partial_shares_c = self._full_mul(partial_shares[0:n], partial_shares[n:2 * n]) full_shares = add_macs(self.runtime, self.Zp, self.u_bound, self.alpha, self.random, self.paillier, partial_shares + partial_shares_c) return full_shares
def _generate_triple_candidates(self, n): """Generates triple candidates for use in the BeDOZa protocol. Returns a deferred that will eventually yield a list of 3n shares of type viff.bedoza.shares.BeDOZaShare corresponding to n multiplicative tuples. The first n are the a's, then comes n b's followed by n c's. The triples are only candidates because consistency of the triples is only half-way guaranteed in the precense of active adversaries. More concretely, the triples returned by this method are guaranteed - even in the precense of an active adversary - to be of the right size. But they may not satisfy the equation c = a * b. """ self.runtime.increment_pc() gen = PartialShareGenerator(self.Zp, self.runtime, self.random, self.paillier) partial_shares = [] for _ in xrange(2 * n): partial_shares.append( gen.generate_share( self.random.randint(0, self.Zp.modulus - 1))) partial_shares_c = self._full_mul(partial_shares[0: n], partial_shares[n: 2 * n]) full_shares = add_macs(self.runtime, self.Zp, self.u_bound, self.alpha, self.random, self.paillier, partial_shares + partial_shares_c) return full_shares
def test_add_macs_produces_correct_sharing(self, runtime): # TODO: Here we use the open method of the BeDOZa runtime in # order to verify the macs of the generated full share. In # order to be more unit testish, this test should use its own # way of verifying these. p = 17 Zp = GF(p) secret = 6 random = Random(283883) paillier_random = Random(random.getrandbits(128)) paillier = ModifiedPaillier(runtime, random) add_macs_random = Random(random.getrandbits(128)) shares_random = Random(random.getrandbits(128)) shares = [] shares.append( partial_share(shares_random, runtime, Zp, secret, paillier=paillier)) shares.append( partial_share(shares_random, runtime, Zp, secret + 1, paillier=paillier)) shares.append( partial_share(shares_random, runtime, Zp, secret + 2, paillier=paillier)) shares.append( partial_share(shares_random, runtime, Zp, secret + 3, paillier=paillier)) bits_in_p = 5 u_bound = 2**(4 * bits_in_p) alpha = 15 zs = add_macs(runtime, Zp, u_bound, alpha, add_macs_random, paillier, shares) def verify(open_shares): inx = secret for open_share in open_shares: self.assertEquals(inx, open_share.value) inx += 1 opened_shares = [] for s in zs: opened_shares.append(runtime.open(s)) d = gather_shares(opened_shares) d.addCallback(verify) return d
def test_add_macs_produces_correct_sharing(self, runtime): # TODO: Here we use the open method of the BeDOZa runtime in # order to verify the macs of the generated full share. In # order to be more unit testish, this test should use its own # way of verifying these. p = 17 Zp = GF(p) secret = 6 random = Random(283883) paillier_random = Random(random.getrandbits(128)) paillier = ModifiedPaillier(runtime, random) add_macs_random = Random(random.getrandbits(128)) shares_random = Random(random.getrandbits(128)) shares = [] shares.append(partial_share(shares_random, runtime, Zp, secret, paillier=paillier)) shares.append(partial_share(shares_random, runtime, Zp, secret + 1, paillier=paillier)) shares.append(partial_share(shares_random, runtime, Zp, secret + 2, paillier=paillier)) shares.append(partial_share(shares_random, runtime, Zp, secret + 3, paillier=paillier)) bits_in_p = 5 u_bound = 2**(4 * bits_in_p) alpha = 15 zs = add_macs(runtime, Zp, u_bound, alpha, add_macs_random, paillier, shares) def verify(open_shares): inx = secret for open_share in open_shares: self.assertEquals(inx, open_share.value) inx += 1 opened_shares = [] for s in zs: opened_shares.append(runtime.open(s)) d = gather_shares(opened_shares) d.addCallback(verify) return d
def generate_share(self, value): self.runtime.increment_pc() partial_share = PartialShareGenerator.generate_share(self, value) full_share = add_macs(self.runtime, self.Zp, self.u_bound, self.alpha, self.random, self.paillier, [partial_share]) return full_share[0]
def generate_random_shares(self, n): self.runtime.increment_pc() partial_shares = TestPartialShareGenerator.generate_random_shares( self, n) return add_macs(self.runtime, self.Zp, self.u_bound, self.alpha, self.random, self.paillier, partial_shares)
def generate_random_shares(self, n): self.runtime.increment_pc() partial_shares = TestPartialShareGenerator.generate_random_shares(self, n) return add_macs(self.runtime, self.Zp, self.u_bound, self.alpha, self.random, self.paillier, partial_shares)