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); }
private void RunObliviousTransferParty1oo2() { const int numberOfInvocations = 3; const int numberOfOptions = 2; Pair <byte[]>[] options = new Pair <byte[]> [numberOfInvocations]; options = new Pair <byte[]>[] { new Pair <byte[]>(TestOptions.Take(numberOfOptions).Select(s => Encoding.ASCII.GetBytes(s)).ToArray()), new Pair <byte[]>(TestOptions.Take(numberOfOptions).Select(s => Encoding.ASCII.GetBytes(s.ToLower())).ToArray()), new Pair <byte[]>(TestOptions.Take(numberOfOptions).Select(s => Encoding.ASCII.GetBytes(s.ToUpper())).ToArray()), }; using (CryptoContext cryptoContext = CryptoContext.CreateDefault()) { IStatelessTwoChoicesObliviousTransfer obliviousTransfer = new NaorPinkasObliviousTransfer( SecurityParameters.CreateDefault768Bit(), cryptoContext ); using (ITwoPartyNetworkSession session = TestNetworkSession.EstablishTwoParty()) { if (session.LocalParty.Id == 0) { obliviousTransfer.SendAsync(session.Channel, options, numberOfInvocations, 6).Wait(); } else { PairIndexArray indices = new PairIndexArray(new[] { 0, 1, 0 }); byte[][] results = obliviousTransfer.ReceiveAsync(session.Channel, indices, numberOfInvocations, 6).Result; Assert.IsNotNull(results, "Result is null."); Assert.AreEqual(numberOfInvocations, results.Length, "Result does not match the correct number of invocations."); for (int j = 0; j < numberOfInvocations; ++j) { CollectionAssert.AreEqual( results[j], options[j][indices[j]], "Incorrect message content {0} (should be {1}).", Encoding.ASCII.GetString(results[j]), Encoding.ASCII.GetString(options[j][indices[j]]) ); } } } } }
private static void PerformObliviousTransfer(ITwoPartyNetworkSession session) { Quadruple <byte[]>[] options = { new Quadruple <byte[]>(TestOptions.Select(s => Encoding.ASCII.GetBytes(s)).ToArray()), new Quadruple <byte[]>(TestOptions.Select(s => Encoding.ASCII.GetBytes(s.ToLower())).ToArray()), new Quadruple <byte[]>(TestOptions.Select(s => Encoding.ASCII.GetBytes(s.ToUpper())).ToArray()) }; using CryptoContext cryptoContext = CryptoContext.CreateDefault(); IGeneralizedObliviousTransfer obliviousTransfer = new NaorPinkasObliviousTransfer( SecurityParameters.CreateDefault768Bit(), cryptoContext ); if (session.LocalParty.Id == 0) { obliviousTransfer.SendAsync(session.Channel, options, 3, 6).Wait(); } else { QuadrupleIndexArray indices = new QuadrupleIndexArray(new[] { 0, 3, 2 }); byte[][] results = obliviousTransfer.ReceiveAsync(session.Channel, indices, 3, 6).Result; Assert.IsNotNull(results, "Result is null."); Assert.AreEqual(3, results.Length, "Result does not match the correct number of invocations."); for (int j = 0; j < 3; ++j) { CollectionAssert.AreEqual( results[j], options[j][indices[j]], "Incorrect message content {0} (should be {1}).", Encoding.ASCII.GetString(results[j]), Encoding.ASCII.GetString(options[j][indices[j]]) ); } } }