private void SetupResultBroadcast() { // we need to broadcast each result to every other quorum List <Protocol> resultProtocols = new List <Protocol>(); for (int i = 0; i < PartyIds.Count; i++) { Quorum evalQuorum = GateQuorumMapping[SortNetwork.LastGateForWire[i].Gate]; if (Result[i] == null) { // setup a receive for this result resultProtocols.Add(new MajorityFilteringProtocol <BigZp>(Me, PartyIds, evalQuorum.Members, ProtocolIdGenerator.ResultBroadcastIdentifier(i))); } else { // setup a broadcast for this result ISet <int> others = new SortedSet <int>(PartyIds); foreach (var qid in evalQuorum.Members) { others.Remove(qid); } resultProtocols.Add(new MajorityFilteringProtocol <BigZp>(Me, PartyIds, others, Result[i], ProtocolIdGenerator.ResultBroadcastIdentifier(i))); } } ExecuteSubProtocols(resultProtocols); }
public override void HandleMessage(int fromId, Msg msg) { if (Stage == 0) { ReceiveShareStage(msg); if (SharesReceived == EvalGate.InputCount) { StartGateEvaluation(); } } else if (Stage == 1) { Debug.Assert(msg.Type == MsgType.SubProtocolCompleted); var completedMsg = (SubProtocolCompletedMsg)msg; CollectGateEvaluation(completedMsg); SendShareStage(); } else if (Stage == 2) { // we loopback any shares that go to me in a different quorum. Debug.Assert(msg is SubProtocolCompletedMsg); SubProtocolCompletedMsg completedMsg = (SubProtocolCompletedMsg)msg; foreach (var loopback in OutputLoopbacksNeeded) { ulong counterpartEvalId = ProtocolIdGenerator.GateEvalIdentifier(loopback.Value.Gate.TopologicalRank); T loopbackVal = (T)completedMsg.Result[loopback.Key]; NetSimulator.Loopback(Me.Id, counterpartEvalId, new LoopbackMsg <T>(loopbackVal, loopback.Value.Port)); } IsCompleted = true; } }
public override void Start() { List <Protocol> evalProtocols = new List <Protocol>(); // we want to start protocols for all of the gates I'm involved with for (int i = 0; i < GateList.Count; i++) { Debug.Assert(GateList[i] is ComputationGate); var evalQuorum = GateQuorumMapping[GateList[i]]; if (evalQuorum == MyQuorum) { ulong evalProtocolId = ProtocolIdGenerator.GateEvalIdentifier(i); evalProtocols.Add(new MultiQuorumGateEvaluation <T>(Me, (ComputationGate)GateList[i], GateQuorumMapping, Circuit, ProtocolFactory, CircuitInputs, Prime, evalProtocolId)); } } if (evalProtocols.Count > 0) { ExecuteSubProtocols(evalProtocols); } else { IsCompleted = true; } }
/* * public static void SetupSimpleCircuitEvaluation(Quorum quorum) * { * int n = quorum.Size; * var polyDeg = (int)Math.Ceiling(n / 3.0) - 1; * * Debug.Assert((n & (n - 1)) == 0); // is power of 2 * * network = new LPSortingNetwork(n); * * IList<BigZp>[] shares = new IList<BigZp>[n]; * * for (int i = 0; i < n; i++) * shares[i] = BigShamirSharing.Share(new BigZp(prime, 500 - 2*i), n, polyDeg); * * foreach (var id in quorum.Members) * { * Dictionary<InputGateAddress, Share<BigZp>> inShares = new Dictionary<InputGateAddress, Share<BigZp>>(); * * int i = 0; * foreach (var inAddr in network.Circuit.InputAddrs) * { * inShares[inAddr] = new Share<BigZp>(shares[i][id]); * i++; * } * * TestParty<IDictionary<OutputGateAddress, Share<BigZp>>> party = new TestParty<IDictionary<OutputGateAddress, Share<BigZp>>>(); * party.UnderTest = new SecureGroupCircuitEvaluation(party, quorum.Clone() as Quorum, network.Circuit, inShares); * NetSimulator.RegisterParty(party); * } * } */ public static void SetupMultiQuorumCircuitEvaluation(Quorum bigQuorum) { int n = bigQuorum.Size; int qSize = n / 2; var polyDeg = (int)Math.Ceiling(qSize / 3.0) - 1; var quorums = new List <Quorum>(); quorums.Add(new Quorum(0, 0, qSize)); quorums.Add(new Quorum(1, qSize, 2 * qSize)); Debug.Assert((n & (n - 1)) == 0); // is power of 2 network = new LPSortingNetwork(n); //network = SortingNetworkFactory.CreateButterflyTournamentRound(n); network.CollapsePermutationGates(); IList <BigZp>[] shares = new IList <BigZp> [n]; for (int i = 0; i < n; i++) { shares[i] = BigShamirSharing.Share(new BigZp(prime, 500 - 2 * i), qSize, polyDeg); } Dictionary <Gate, Quorum> gqmapping = new Dictionary <Gate, Quorum>(); for (int i = 0; i < network.Circuit.TopologicalOrder.Count; i++) { gqmapping[network.Circuit.TopologicalOrder[i]] = quorums[i]; } foreach (var id in bigQuorum.Members) { Dictionary <InputGateAddress, Share <BigZp> > inShares = new Dictionary <InputGateAddress, Share <BigZp> >(); int i = 0; foreach (var inAddr in network.Circuit.InputAddrs) { inShares[inAddr] = new Share <BigZp>(shares[i][id % 4]); i++; } TestParty <IDictionary <OutputGateAddress, Share <BigZp> > > party = new TestParty <IDictionary <OutputGateAddress, Share <BigZp> > >(); Quorum[] quorumsClone = quorums.Select(a => a.Clone() as Quorum).ToArray(); party.UnderTest = new SecureMultiQuorumCircuitEvaluation <Share <BigZp> >(party, quorumsClone[id / qSize], quorumsClone, ProtocolIdGenerator.GenericIdentifier(0), network.Circuit, inShares, new BigZpShareGateEvaluationFactory(prime), gqmapping, prime); NetSimulator.RegisterParty(party); } }
public MpsParty(int numParties, BigZp input) { SortedSet <int> parties = new SortedSet <int>(); for (int i = 0; i < numParties; i++) { parties.Add(i); } Protocol = new MultiPartyShufflingProtocol(this, parties, ProtocolIdGenerator.GenericIdentifier(0), input, input.Prime); //Protocol = new MultiPartySortingProtocol(this, parties, ProtocolIdGenerator.GenericIdentifier(0), input, input.Prime); }
private void CollectResults(IDictionary <ulong, object> rawResults) { var allResults = rawResults.ToDictionary(k => k.Key, v => (BigZp)v.Value); for (int i = 0; i < PartyIds.Count; i++) { if (Result[i] == null) { Result[i] = allResults[ProtocolIdGenerator.ResultBroadcastIdentifier(i)]; } } }
public override void Start() { // if I am a sender, then multicast my value, // if i am a receiver do nothing. if (MyValue != null) { Multicast(new BasicMessage <T>(MyValue), Receivers); } if (Receivers != null && !Receivers.Contains(Me.Id)) { // do a no-op protocol to keep everybody synchronized ExecuteSubProtocol(new NopProtocol(Me, ProtocolIdGenerator.NopIdentifier(ProtocolId), 2)); } }
public void SetupInputDistribution() { int myPosition = Quorum.GetPositionOf(PartyIds, Me.Id); GateAddress myInputGateAddr = SortNetwork.FirstGateForWire[myPosition]; Quorum myInputQuorum = GateQuorumMapping[myInputGateAddr.Gate]; Protocol sortValueDistribution = new SharingProtocol(Me, Me.Id, myInputQuorum, SortValue, Prime, ProtocolIdGenerator.GateInputSharingIdentifier(myInputGateAddr.Gate.TopologicalRank, 2 * myInputGateAddr.Port)); Protocol secretDistribution = new SharingProtocol(Me, Me.Id, myInputQuorum, Secret, Prime, ProtocolIdGenerator.GateInputSharingIdentifier(myInputGateAddr.Gate.TopologicalRank, 2 * myInputGateAddr.Port + 1)); List <Protocol> inputProtocols = new List <Protocol>(); inputProtocols.Add(sortValueDistribution); inputProtocols.Add(secretDistribution); InputProtocolMapping = new Dictionary <InputGateAddress, Tuple <ulong, ulong> >(); for (int i = 0; i < PartyIds.Count; i++) { var gateAddr = SortNetwork.FirstGateForWire[i]; foreach (Quorum q in MyQuorums) { if (GateQuorumMapping[gateAddr.Gate] == q) { if (i == myPosition) { InputProtocolMapping[gateAddr] = new Tuple <ulong, ulong>(sortValueDistribution.ProtocolId, secretDistribution.ProtocolId); } else { ulong sortRecvId = ProtocolIdGenerator.GateInputSharingIdentifier(gateAddr.Gate.TopologicalRank, 2 * gateAddr.Port); ulong shareRecvId = ProtocolIdGenerator.GateInputSharingIdentifier(gateAddr.Gate.TopologicalRank, 2 * gateAddr.Port + 1); InputProtocolMapping[gateAddr] = new Tuple <ulong, ulong>(sortRecvId, shareRecvId); // I need to receive for this gate inputProtocols.Add(new SharingProtocol(Me, PartyIds.ElementAt(i), q, null, Prime, sortRecvId)); inputProtocols.Add(new SharingProtocol(Me, PartyIds.ElementAt(i), q, null, Prime, shareRecvId)); } } } } ExecuteSubProtocols(inputProtocols); }
public override void HandleMessage(int fromId, Msg msg) { Debug.Assert(msg.Type == MsgType.SubProtocolCompleted); var completedMsg = (SubProtocolCompletedMsg)msg; switch (Stage) { case 0: // reconstruct the rand we just created ExecuteSubProtocol(new ReconstructionProtocol(Me, RandGenQuorum, (Share <BigZp>)completedMsg.SingleResult)); break; case 1: ProtocolRandom = (BigZp)completedMsg.SingleResult; ExecuteSubProtocol(new MajorityFilteringProtocol <BigZp>(Me, PartyIds, PartyIds.Skip(TRUSTED_PARTY_COUNT).ToArray(), ProtocolRandom, ProtocolIdGenerator.GenericIdentifier(1))); break; case 2: if (!RandGenQuorum.HasMember(Me.Id)) { ProtocolRandom = (BigZp)completedMsg.SingleResult; } GenerateQuorums(); GenerateGateQuorumAssignment(); SetupInputDistribution(); break; case 3: UnpackCircuitInputs(completedMsg.Result); SetupQuorumExecutions(); break; case 4: UnpackCircuitResults((completedMsg.SingleResult as SubProtocolCompletedMsg).Result); SetupReconstruction(); break; case 5: UnpackReconstruction(completedMsg.Result); SetupResultBroadcast(); break; case 6: CollectResults(completedMsg.Result); IsCompleted = true; break; } Stage++; }
public MultiQuorumProtocol <Tuple <Share <BigZp>, Share <BigZp> > > GetResharingProtocol(Party me, Quorum fromQuorum, Quorum toQuorum, Tuple <Share <BigZp>, Share <BigZp> > value, int gateNumber, int portNumber) { return(new QuorumTaggedShareRenewalProtocol(me, fromQuorum, toQuorum, value, Prime, ProtocolIdGenerator.GateInputSharingIdentifier(gateNumber, portNumber * 3))); }
private void SetupQuorumExecutions() { List <Protocol> executionProtocols = new List <Protocol>(); EvalProtocolMapping = new Dictionary <Quorum, ulong>(); foreach (Quorum q in MyQuorums) { ulong evalProtocolId = q.GetNextProtocolId(); EvalProtocolMapping[q] = evalProtocolId; executionProtocols.Add(new SecureMultiQuorumCircuitEvaluation <Tuple <Share <BigZp>, Share <BigZp> > >( Me, q, EvalQuorums, evalProtocolId, SortNetwork.Circuit, CircuitInputs, GateProtocolEvaluationFactory, GateQuorumMapping, Prime)); } ExecuteSubProtocol(new SynchronizationProtocol(Me, PartyIds, executionProtocols, ProtocolIdGenerator.GenericIdentifier(CIRCUIT_EVAL_SYNC_PROTOCOL))); }
public void SetupRandGenStep() { Debug.Assert(PartyIds.Count > TRUSTED_PARTY_COUNT); RandGenQuorum = new Quorum(NextQuorumNumber++, PartyIds.Take(5).ToArray()); if (RandGenQuorum.HasMember(Me.Id)) { BigZp myRandom = new BigZp(Prime, Me.SafeRandGen.Next(Prime)); ExecuteSubProtocol(new RandomGenProtocol(Me, RandGenQuorum, myRandom, Prime)); } else { // receive the rand broadcast ExecuteSubProtocol(new MajorityFilteringProtocol <BigZp>(Me, PartyIds, RandGenQuorum.Members.ToList(), ProtocolIdGenerator.GenericIdentifier(1))); Stage = 2; } }
private void SendShareStage() { List <Protocol> reshareProtocols = new List <Protocol>(); OutputLoopbacksNeeded = new Dictionary <ulong, InputGateAddress>(); for (int i = 0; i < EvalGate.OutputCount; i++) { // figure out where this share is going to InputGateAddress counterpartGateAddr; if (Circuit.OutputConnectionCounterparties.TryGetValue(EvalGate.GetLocalOutputAddress(i), out counterpartGateAddr)) { var counterpartGate = counterpartGateAddr.Gate; var counterpartQuorum = GateQuorumMapping[counterpartGate]; bool needReshare; bool needLoopback; if (counterpartQuorum == EvalQuorum) { needLoopback = true; needReshare = false; } else if (counterpartQuorum.HasMember(Me.Id)) { needLoopback = true; needReshare = true; } else { needLoopback = false; needReshare = true; } if (needLoopback && !needReshare) { // loop a message back to the other protocol ulong counterpartEvalId = ProtocolIdGenerator.GateEvalIdentifier(counterpartGate.TopologicalRank); NetSimulator.Loopback(Me.Id, counterpartEvalId, new LoopbackMsg <T>(OutputShares[i], counterpartGateAddr.Port)); } if (needReshare) { Protocol reshareProtocol = ProtocolFactory.GetResharingProtocol(Me, EvalQuorum, counterpartQuorum, OutputShares[i], counterpartGate.TopologicalRank, counterpartGateAddr.Port); reshareProtocols.Add(reshareProtocol); if (needLoopback) { OutputLoopbacksNeeded[reshareProtocol.ProtocolId] = counterpartGateAddr; } } } else { // this was a circuit output Result[EvalGate.GetLocalOutputAddress(i)] = OutputShares[i]; } } Stage = 2; if (reshareProtocols.Count > 0) { ExecuteSubProtocols(reshareProtocols); } else { IsCompleted = true; } }