상속: DkmsKey
예제 #1
0
        //public override void Receive(Message msg)
        //{
        //	Gate anchor, myGate;
        //	var ssmpcMsg = msg as ScalableMpcMessage;
        //	Debug.Assert(ssmpcMsg != null);

        //	switch (ssmpcMsg.StateKey.Stage)
        //	{
        //		case Stage.Input:
        //			var inputMsg = ssmpcMsg as InputMessage;

        //			// start a heavy-weight smpc with parent and sibling gates
        //			myGate = Circuit.FindGate(ssmpcMsg.StateKey.GateId);
        //			RunChildMpc(myGate.OutNodes[0], myGate, inputMsg.Data);
        //			break;

        //		case Stage.Mpc:
        //			MpcProtocol smpc;
        //			var mpcMsg = ssmpcMsg as MpcMessage;
        //			if (MpcSessions.ContainsKey(smpcMsg.StateKey))
        //				mpc = MpcSessions[mpcMsg.StateKey].Mpc;
        //			else
        //			{
        //				// I must be in the anchor gate
        //				Debug.Assert(mpcMsg.ToGateId == mpcMsg.AnchorId, "Synchronization exception: Why don't I have an session for this MPC?");

        //				// my child gate is asking me to participate in an MPC, so create an MPC protocol instance and join
        //				anchor = Circuit.FindGate(mpcMsg.AnchorId);
        //				mpc = RunAnchorMpc(anchor);
        //			}
        //			mpc.Receive(mpcMsg.InnerMessage);
        //			break;
        //	}
        //}

        /// <summary>
        /// Starts a heavy-weight SMPC instance for an SMPC child gate player.
        /// </summary>
        protected virtual BgwProtocol RunChildMpc(Gate anchor, Gate myGate, Zp myInput)
        {
            Debug.Assert(quorumsMap.ContainsKey(anchor.QuorumIndex));
            Debug.Assert(quorumsMap.ContainsKey(myGate.QuorumIndex));

            // find associated quorums
            var childGates = anchor.InNodes;
            var myGateId   = myGate.Id;

            var virtualIds = new List <int>(quorumsMap[anchor.QuorumIndex].Select(p => (anchor.Id << 16) + p));                         // TODO: IMPORTANT: THE ASSUMPTION HERE LIMITS ENTITY/GATE IDs TO 32768. TO INCREASE THIS LIMIT EITHER USE UINT/ULONG IDs OR CHANGE THIS CODE.

            foreach (var gate in childGates)
            {
                foreach (var playerId in quorumsMap[gate.QuorumIndex])
                {
                    virtualIds.Add((gate.Id << 16) + playerId);
                }
            }
            var myVirtualId = (myGateId << 16) + Party.Id;

            // run the protocol and keep it in a the session state
            var key = new MpcKey(myGateId, anchor.Id);

            // Mahdi (3/25/14: Do we really need virtual ids?)
            throw new NotImplementedException();

            //var mpc = new BgwProtocol(anchor.MpcCircuit, virtualIds.AsReadOnly(), myVirtualId, myInput, OnMpcSend, key);

            //mpc.MpcFinish += new FinishHandler(OnMpcFinish);
            //MpcSessions.Collect(key, new MpcSession(mpc));
            //mpc.Run();
            //return mpc;
        }
예제 #2
0
        /// <summary>
        /// Starts a heavy-weight SMPC instance for an anchor gate player.
        /// </summary>
        protected virtual BgwProtocol RunAnchorMpc(Gate anchor)
        {
            // NOTE: since in the HBC case all players have the same output, just one of them (the guy with min id) SMPCs his output to improve performance.
            Debug.Assert(quorumsMap.ContainsKey(anchor.QuorumIndex));

            // find associated quorums
            var anchorChildren = anchor.InNodes;
            var myQuorum       = quorumsMap[anchor.QuorumIndex];

            var virtualIds = new List <int>(myQuorum.Select(p => (anchor.Id << 16) + p));                       // TODO: IMPORTANT: THE ASSUMPTION HERE LIMITS ENTITY/GATE IDs TO 32768. TO INCREASE THIS LIMIT EITHER USE UINT/ULONG IDs OR CHANGE THIS CODE.

            foreach (var childGate in anchorChildren)
            {
                foreach (var playerId in quorumsMap[childGate.QuorumIndex])
                {
                    virtualIds.Add((childGate.Id << 16) + playerId);
                }
            }
            var myVirtualId = (anchor.Id << 16) + Party.Id;

            // if my id is the minimum in my quorum, then I should just SMPC with a zero, otherwise just SMPC with a random number (r_g).
            // save this random number in the session because it will be my input in next level's SMPC.
            BgwProtocol mpc;

            if (Party.Id == myQuorum.Min())
            {
                // run the protocol and keep it in a the session state
                var key = new MpcKey(anchor.Id, anchor.Id);

                // Mahdi (3/25/14: Do we really need virtual ids?)
                throw new NotImplementedException();

                //mpc = new BgwProtocol(anchor.MpcCircuit, virtualIds.AsReadOnly(), myVirtualId, new Zp(Prime), OnMpcSend, key);
                //mpc.MpcFinish += new FinishHandler(OnMpcFinish);
                //MpcSessions.Collect(key, new MpcSession(mpc));
                //mpc.Run();
            }
            else
            {
                // pick a number uniformly at random (r_g)
                // this random along with other players' randoms forms a global random in the quorum.
                var randomShare = new Zp(Prime, StaticRandom.Next(0, Prime));

                // run an SMPC protocol and keep it in a session state
                var key = new MpcKey(anchor.Id, anchor.Id);

                // Mahdi (3/25/14: Do we really need virtual ids?)
                throw new NotImplementedException();

                //mpc = new BgwProtocol(anchor.MpcCircuit, virtualIds.AsReadOnly(), myVirtualId, randomShare, OnMpcSend, key);
                //mpc.MpcFinish += new FinishHandler(OnMpcFinish);
                //MpcSessions.Collect(key, new MpcSession(mpc));
                //mpc.Run();
            }
            return(mpc);
        }
예제 #3
0
        //public override void Receive(Message msg)
        //{
        //    Gate anchor, myGate;
        //    var ssmpcMsg = msg as ScalableMpcMessage;
        //    Debug.Assert(ssmpcMsg != null);
        //    switch (ssmpcMsg.StateKey.Stage)
        //    {
        //        case Stage.Input:
        //            var inputMsg = ssmpcMsg as InputMessage;
        //            // start a heavy-weight smpc with parent and sibling gates
        //            myGate = Circuit.FindGate(ssmpcMsg.StateKey.GateId);
        //            RunChildMpc(myGate.OutNodes[0], myGate, inputMsg.Data);
        //            break;
        //        case Stage.Mpc:
        //            MpcProtocol smpc;
        //            var mpcMsg = ssmpcMsg as MpcMessage;
        //            if (MpcSessions.ContainsKey(smpcMsg.StateKey))
        //                mpc = MpcSessions[mpcMsg.StateKey].Mpc;
        //            else
        //            {
        //                // I must be in the anchor gate
        //                Debug.Assert(mpcMsg.ToGateId == mpcMsg.AnchorId, "Synchronization exception: Why don't I have an session for this MPC?");
        //                // my child gate is asking me to participate in an MPC, so create an MPC protocol instance and join
        //                anchor = Circuit.FindGate(mpcMsg.AnchorId);
        //                mpc = RunAnchorMpc(anchor);
        //            }
        //            mpc.Receive(mpcMsg.InnerMessage);
        //            break;
        //    }
        //}
        /// <summary>
        /// Starts a heavy-weight SMPC instance for an SMPC child gate player.
        /// </summary>
        protected virtual BgwProtocol RunChildMpc(Gate anchor, Gate myGate, Zp myInput)
        {
            Debug.Assert(quorumsMap.ContainsKey(anchor.QuorumIndex));
            Debug.Assert(quorumsMap.ContainsKey(myGate.QuorumIndex));

            // find associated quorums
            var childGates = anchor.InNodes;
            var myGateId = myGate.Id;

            var virtualIds = new List<int>(quorumsMap[anchor.QuorumIndex].Select(p => (anchor.Id << 16) + p));		// TODO: IMPORTANT: THE ASSUMPTION HERE LIMITS ENTITY/GATE IDs TO 32768. TO INCREASE THIS LIMIT EITHER USE UINT/ULONG IDs OR CHANGE THIS CODE.
            foreach (var gate in childGates)
            {
                foreach (var playerId in quorumsMap[gate.QuorumIndex])
                    virtualIds.Add((gate.Id << 16) + playerId);
            }
            var myVirtualId = (myGateId << 16) + Party.Id;

            // run the protocol and keep it in a the session state
            var key = new MpcKey(myGateId, anchor.Id);

            // Mahdi (3/25/14: Do we really need virtual ids?)
            throw new NotImplementedException();

            //var mpc = new BgwProtocol(anchor.MpcCircuit, virtualIds.AsReadOnly(), myVirtualId, myInput, OnMpcSend, key);

            //mpc.MpcFinish += new FinishHandler(OnMpcFinish);
            //MpcSessions.Collect(key, new MpcSession(mpc));
            //mpc.Run();
            //return mpc;
        }
예제 #4
0
        /// <summary>
        /// Starts a heavy-weight SMPC instance for an anchor gate player.
        /// </summary>
        protected virtual BgwProtocol RunAnchorMpc(Gate anchor)
        {
            // NOTE: since in the HBC case all players have the same output, just one of them (the guy with min id) SMPCs his output to improve performance.
            Debug.Assert(quorumsMap.ContainsKey(anchor.QuorumIndex));

            // find associated quorums
            var anchorChildren = anchor.InNodes;
            var myQuorum = quorumsMap[anchor.QuorumIndex];

            var virtualIds = new List<int>(myQuorum.Select(p => (anchor.Id << 16) + p));		// TODO: IMPORTANT: THE ASSUMPTION HERE LIMITS ENTITY/GATE IDs TO 32768. TO INCREASE THIS LIMIT EITHER USE UINT/ULONG IDs OR CHANGE THIS CODE.
            foreach (var childGate in anchorChildren)
            {
                foreach (var playerId in quorumsMap[childGate.QuorumIndex])
                    virtualIds.Add((childGate.Id << 16) + playerId);
            }
            var myVirtualId = (anchor.Id << 16) + Party.Id;

            // if my id is the minimum in my quorum, then I should just SMPC with a zero, otherwise just SMPC with a random number (r_g).
            // save this random number in the session because it will be my input in next level's SMPC.
            BgwProtocol mpc;
            if (Party.Id == myQuorum.Min())
            {
                // run the protocol and keep it in a the session state
                var key = new MpcKey(anchor.Id, anchor.Id);

                // Mahdi (3/25/14: Do we really need virtual ids?)
                throw new NotImplementedException();

                //mpc = new BgwProtocol(anchor.MpcCircuit, virtualIds.AsReadOnly(), myVirtualId, new Zp(Prime), OnMpcSend, key);
                //mpc.MpcFinish += new FinishHandler(OnMpcFinish);
                //MpcSessions.Collect(key, new MpcSession(mpc));
                //mpc.Run();
            }
            else
            {
                // pick a number uniformly at random (r_g)
                // this random along with other players' randoms forms a global random in the quorum.
                var randomShare = new Zp(Prime, StaticRandom.Next(0, Prime));

                // run an SMPC protocol and keep it in a session state
                var key = new MpcKey(anchor.Id, anchor.Id);

                // Mahdi (3/25/14: Do we really need virtual ids?)
                throw new NotImplementedException();

                //mpc = new BgwProtocol(anchor.MpcCircuit, virtualIds.AsReadOnly(), myVirtualId, randomShare, OnMpcSend, key);
                //mpc.MpcFinish += new FinishHandler(OnMpcFinish);
                //MpcSessions.Collect(key, new MpcSession(mpc));
                //mpc.Run();
            }
            return mpc;
        }