viff

view viff/bedoza/share.py @ 1572:54f02cd75714

BeDOZa: Improved comments.
author Thomas P Jakobsen <tpj@cs.au.dk>
date Mon Oct 04 10:58:23 2010 +0200 (19 months ago)
parents 3bf0533ed32c
children 0d3b99e1e3eb
line source
1 # Copyright 2010 VIFF Development Team.
2 #
3 # This file is part of VIFF, the Virtual Ideal Functionality Framework.
4 #
5 # VIFF is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU Lesser General Public License (LGPL) as
7 # published by the Free Software Foundation, either version 3 of the
8 # License, or (at your option) any later version.
9 #
10 # VIFF is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
13 # Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with VIFF. If not, see <http://www.gnu.org/licenses/>.
18 from twisted.internet.defer import gatherResults
20 from viff.bedoza.shares import PartialShareContents
21 from viff.bedoza.util import _convolute
23 def generate_partial_share_contents(field_elements, runtime, paillier):
24 """Protocol for generating partial shares.
26 This protocol corresponds to the "Share" protocol in the document
27 "A new On- and Off-line Phase for MPC".
29 Each party inputs a list of field elements *field_elements*. The
30 values of the field elements are encrypted, the encrypted values
31 are exchanged, and for each player, a zero-knowledge proof is
32 carried out, proving that each player knows the plaintexts
33 corresponding to the ciphertexts, he broadcasts, and that the
34 plaintexts are of limited size.
36 Returns a deferred, which yields a list of PartialShareContents.
37 """
39 runtime.increment_pc()
41 N_squared_list = [paillier.get_modulus_square(player_id)
42 for player_id in runtime.players]
44 list_of_enc_shares = []
45 for field_element in field_elements:
46 list_of_enc_shares.append(paillier.encrypt(field_element.value))
48 list_of_enc_shares = runtime.broadcast(runtime.players.keys(), runtime.players.keys(),
49 str(list_of_enc_shares))
51 def create_partial_share(list_of_enc_shares, field_elements):
52 list_of_enc_shares = [eval(x) for x in list_of_enc_shares]
54 reordered_encrypted_shares = [[] for _ in list_of_enc_shares[0]]
55 for enc_shares in list_of_enc_shares:
56 for inx, enc_share in enumerate(enc_shares):
57 reordered_encrypted_shares[inx].append(enc_share)
59 partialShareContents = []
60 for enc_shares, field_element in zip(reordered_encrypted_shares, field_elements):
61 partialShareContents.append(PartialShareContents(field_element, enc_shares, N_squared_list))
62 return partialShareContents
64 d = gatherResults(list_of_enc_shares)
65 runtime.schedule_callback(d, create_partial_share, field_elements)
66 return d