Beispiel #1
0
        /*
         * 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);
            }
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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++;
        }
Beispiel #4
0
        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)));
        }
Beispiel #5
0
        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;
            }
        }