private static void RunSecureComputationParty(int startPort, int numberOfParties, int localPartyId, BitArray localInput, BitArray expectedOutput) { using (IMultiPartyNetworkSession session = TestNetworkSession.EstablishMultiParty(localPartyId, numberOfParties)) { using (CryptoContext cryptoContext = CryptoContext.CreateDefault()) { IObliviousTransfer obliviousTransfer = new NaorPinkasObliviousTransfer( new SecurityParameters(47, 23, 4, 1, 1), cryptoContext ); IMultiplicativeSharing multiplicativeSharing = new ObliviousTransferMultiplicativeSharing( obliviousTransfer, cryptoContext ); GMWSecureComputation computation = new GMWSecureComputation(session, multiplicativeSharing, cryptoContext); SetIntersectionCircuitRecorder circuitRecorder = new SetIntersectionCircuitRecorder(numberOfParties, localInput.Length); CircuitBuilder circuitBuilder = new CircuitBuilder(); circuitRecorder.Record(circuitBuilder); ForwardCircuit circuit = new ForwardCircuit(circuitBuilder.CreateCircuit()); BitArray output = computation.EvaluateAsync(circuit, circuitRecorder.InputMapping, circuitRecorder.OutputMapping, localInput).Result; CollectionAssert.AreEqual( expectedOutput, output, "Incorrect output {0} (should be {1}).", output.ToBinaryString(), expectedOutput.ToBinaryString() ); } } }
private static void RunSecureComputationParty(int localPartyId, BitArray localInput) { using (IMultiPartyNetworkSession session = CreateLocalSession(localPartyId, StartPort, NumberOfParties)) { using (CryptoContext cryptoContext = CryptoContext.CreateDefault()) { IObliviousTransfer obliviousTransfer = new NaorPinkasObliviousTransfer( SecurityParameters.CreateDefault768Bit(), cryptoContext ); IMultiplicativeSharing multiplicativeSharing = new ObliviousTransferMultiplicativeSharing( obliviousTransfer, cryptoContext ); GMWSecureComputation computation = new GMWSecureComputation(session, multiplicativeSharing, cryptoContext); Stopwatch stopwatch = Stopwatch.StartNew(); SetIntersectionSecureProgram secureProgram = new SetIntersectionSecureProgram(NumberOfParties, NumberOfElements); object[] outputPrimitives = secureProgram.EvaluateAsync(computation, new[] { localInput }).Result; BitArray intersection = (BitArray)outputPrimitives[0]; BigInteger count = (BigInteger)outputPrimitives[1]; stopwatch.Stop(); Console.WriteLine(); Console.WriteLine("Completed protocol as {0} in {1} ms.", session.LocalParty.Name, stopwatch.ElapsedMilliseconds); Console.WriteLine(" Local input: {0}", localInput.ToBinaryString()); Console.WriteLine(" Computed intersection: {0}", intersection.ToBinaryString()); Console.WriteLine(" Computed number of matches: {0}", count); } } }