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); } } }
private static async Task RunSecureComputationPartyAsync(int localPartyId, BitArray localInput) { Console.WriteLine($"Starting party {localPartyId}..."); using IMultiPartyNetworkSession session = await TcpMultiPartyNetworkSession.EstablishLoopbackAsync( new Party (localPartyId), StartPort, NumberOfParties ); using CryptoContext cryptoContext = CryptoContext.CreateDefault(); IObliviousTransfer obliviousTransfer = new NaorPinkasObliviousTransfer( SecurityParameters.CreateDefault768Bit(), cryptoContext ); IMultiplicativeSharing multiplicativeSharing = new ObliviousTransferMultiplicativeSharing( obliviousTransfer, cryptoContext ); SecretSharingSecureComputation computation = new SecretSharingSecureComputation( session, multiplicativeSharing, cryptoContext ); Stopwatch stopwatch = Stopwatch.StartNew(); SetIntersectionSecureProgram secureProgram = new SetIntersectionSecureProgram(NumberOfParties, NumberOfElements); object[] outputPrimitives = await secureProgram.EvaluateAsync(computation, new object[] { localInput }); BitArray intersection = (BitArray)outputPrimitives[0]; BigInteger count = (BigInteger)outputPrimitives[1]; stopwatch.Stop(); Console.WriteLine(); Console.WriteLine($"Completed protocol as {session.LocalParty.Name} in {stopwatch.ElapsedMilliseconds} ms."); Console.WriteLine($" Local input: {localInput.ToBinaryString()}"); Console.WriteLine($" Computed intersection: {intersection.ToBinaryString()}"); Console.WriteLine($" Computed number of matches: {count}"); Console.WriteLine(); Console.WriteLine("Press any key to exit."); Console.ReadKey(true); }