public override void Start() { Stage = 0; ExecuteSubProtocol(new ShareAdditionProtocol(Me, Quorum, BigZpShareFactory.CreateConstantShare(Prime, 1), BigZpShareFactory.ShareAdditiveInverse(SwapBit))); }
public override void HandleMessage(int fromId, Msg msg) { Debug.Assert(msg is SubProtocolCompletedMsg); var completedMsg = msg as SubProtocolCompletedMsg; switch (Stage) { case 0: ExecuteSubProtocol(new LeastSignificantBitProtocol(Me, Quorum, (Share <BigZp>)completedMsg.SingleResult)); break; case 1: ExecuteSubProtocol(new ShareAdditionProtocol(Me, Quorum, BigZpShareFactory.CreateConstantShare(Share.Value.Prime, 1), BigZpShareFactory.ShareAdditiveInverse((Share <BigZp>)completedMsg.SingleResult))); break; case 2: Result = (Share <BigZp>)completedMsg.SingleResult; IsCompleted = true; break; } Stage++; }
private void ExecuteSubtractionStep() { var DLower = new List <Share <BigZp> >(D); var DUpper = new List <Share <BigZp> >(D); DLower.RemoveAt(DLower.Count - 1); // remove the highest order bit DUpper.RemoveAt(0); // shift right if (DLower.Count > 0) { for (int i = 0; i < DUpper.Count; i++) { DUpper[i] = BigZpShareFactory.ShareAdditiveInverse(DUpper[i]); // make this a subtraction } ExecuteSubProtocol(new BitwiseOperationProtocol(Me, Quorum, DLower, DUpper, new ShareAdditionProtocol.ProtocolFactory(Me, Quorum))); } else { // only 1 bit in input. no subtraction necessary ExecuteSubProtocol(new LoopbackProtocol(Me, new List <Share <BigZp> >(), Quorum.GetNextProtocolId())); } }
public override void HandleMessage(int fromId, Msg msg) { Debug.Assert(msg is SubProtocolCompletedMsg); var completedMsg = msg as SubProtocolCompletedMsg; switch (Stage) { case 0: ShareAMinusB = (Share <BigZp>)completedMsg.SingleResult; ExecuteSubProtocols(new Protocol[] { new LessThanHalfPrime(Me, Quorum, ShareA), new LessThanHalfPrime(Me, Quorum, ShareB), new LessThanHalfPrime(Me, Quorum, ShareAMinusB) }); break; case 1: W = (Share <BigZp>)completedMsg.ResultList[0]; X = (Share <BigZp>)completedMsg.ResultList[1]; Y = (Share <BigZp>)completedMsg.ResultList[2]; ExecuteSubProtocols(new Protocol[] { new ShareMultiplicationProtocol(Me, Quorum, X, Y), new ShareAdditionProtocol(Me, Quorum, X, Y), }); break; case 2: XY = (Share <BigZp>)completedMsg.ResultList[0]; XpY = (Share <BigZp>)completedMsg.ResultList[1]; ExecuteSubProtocol(new ShareMultiplicationProtocol(Me, Quorum, BigZpShareFactory.CreateConstantShare(Prime, 2), XY)); break; case 3: ExecuteSubProtocol(new ShareAdditionProtocol(Me, Quorum, XpY, BigZpShareFactory.ShareAdditiveInverse((Share <BigZp>)completedMsg.SingleResult))); break; case 4: ExecuteSubProtocol(new ShareMultiplicationProtocol(Me, Quorum, W, (Share <BigZp>)completedMsg.SingleResult)); break; case 5: ExecuteSubProtocol(new ShareAdditionProtocol(Me, Quorum, XY, (Share <BigZp>)completedMsg.SingleResult)); break; case 6: ExecuteSubProtocol(new ShareAdditionProtocol(Me, Quorum, BigZpShareFactory.ShareAdditiveInverse(XpY), (Share <BigZp>)completedMsg.SingleResult)); break; case 7: ExecuteSubProtocol(new ShareAdditionProtocol(Me, Quorum, BigZpShareFactory.CreateConstantShare(Prime, 1), (Share <BigZp>)completedMsg.SingleResult)); break; case 8: Result = (Share <BigZp>)completedMsg.SingleResult; IsCompleted = true; break; } Stage++; }
public override void Start() { Stage = 0; ExecuteSubProtocol(new ShareAdditionProtocol(Me, Quorum, ShareA, BigZpShareFactory.ShareAdditiveInverse(ShareB))); }