Esempio n. 1
0
        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()
                        );
                }
            }
        }
Esempio n. 2
0
        private void RunObliviousTransferParty1oo2Resumed()
        {
            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())
            {
                using (ITwoPartyNetworkSession session = TestNetworkSession.EstablishTwoParty())
                {
                    ITwoChoicesObliviousTransferChannel baseOT            = new StatelessTwoChoicesObliviousTransferChannel(new InsecureObliviousTransfer(), session.Channel);
                    ITwoChoicesObliviousTransferChannel obliviousTransfer = new TwoChoicesExtendedObliviousTransferChannel(baseOT, 8, cryptoContext);

                    if (session.LocalParty.Id == 0)
                    {
                        for (int i = 0; i < 2; ++i)
                        {
                            obliviousTransfer.SendAsync(options, numberOfInvocations, 6).Wait();
                        }
                    }
                    else
                    {
                        PairIndexArray[] allIndices = new[] { new PairIndexArray(new[] { 0, 1, 0 }), new PairIndexArray(new[] { 1, 0, 0 }) };
                        for (int i = 0; i < 2; ++i)
                        {
                            PairIndexArray indices = allIndices[i];
                            byte[][]       results = obliviousTransfer.ReceiveAsync(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 byte[][] RunObliviousTransferReceiverParty(BitArray selectionBits)
        {
            using (CryptoContext cryptoContext = CryptoContext.CreateDefault())
            {
                using (var session = TestNetworkSession.EstablishTwoParty())
                {
                    ITwoChoicesObliviousTransferChannel           baseOT            = new StatelessTwoChoicesObliviousTransferChannel(new InsecureObliviousTransfer(), session.Channel);
                    ITwoChoicesCorrelatedObliviousTransferChannel obliviousTransfer = new TwoChoicesCorrelatedExtendedObliviousTransferChannel(baseOT, 8, cryptoContext);

                    return(obliviousTransfer.ReceiveAsync(selectionBits, selectionBits.Length, NumberOfMessageBytes).Result);
                }
            }
        }
        private Pair <byte[]>[] RunObliviousTransferSenderParty(int numberOfInvocations)
        {
            using (CryptoContext cryptoContext = CryptoContext.CreateDefault())
            {
                using (ITwoPartyNetworkSession session = TestNetworkSession.EstablishTwoParty())
                {
                    ITwoChoicesObliviousTransferChannel       baseOT            = new StatelessTwoChoicesObliviousTransferChannel(new InsecureObliviousTransfer(), session.Channel);
                    ITwoChoicesRandomObliviousTransferChannel obliviousTransfer = new TwoChoicesRandomExtendedObliviousTransferChannel(baseOT, 8, cryptoContext);

                    return(obliviousTransfer.SendAsync(numberOfInvocations, NumberOfMessageBytes).Result);
                }
            }
        }
        private Pair <byte[]>[] RunObliviousTransferSenderParty(byte[][] correlationStrings)
        {
            using (CryptoContext cryptoContext = CryptoContext.CreateDefault())
            {
                using (var session = TestNetworkSession.EstablishTwoParty())
                {
                    ITwoChoicesObliviousTransferChannel           baseOT            = new StatelessTwoChoicesObliviousTransferChannel(new InsecureObliviousTransfer(), session.Channel);
                    ITwoChoicesCorrelatedObliviousTransferChannel obliviousTransfer = new TwoChoicesCorrelatedExtendedObliviousTransferChannel(baseOT, 8, cryptoContext);

                    return(obliviousTransfer.SendAsync(
                               correlationStrings, correlationStrings.Length, NumberOfMessageBytes).Result);
                }
            }
        }
Esempio n. 6
0
        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 Pair <Pair <byte[]>[]> RunResumedObliviousTransferSenderParty(byte[][] firstCorrelationStrings, byte[][] secondCorrelationStrings)
        {
            using (CryptoContext cryptoContext = CryptoContext.CreateDefault())
            {
                using (var session = TestNetworkSession.EstablishTwoParty())
                {
                    ITwoChoicesObliviousTransferChannel           baseOT            = new StatelessTwoChoicesObliviousTransferChannel(new InsecureObliviousTransfer(), session.Channel);
                    ITwoChoicesCorrelatedObliviousTransferChannel obliviousTransfer = new TwoChoicesCorrelatedExtendedObliviousTransferChannel(baseOT, 8, cryptoContext);

                    Pair <byte[]>[] firstRoundResults = obliviousTransfer.SendAsync(
                        firstCorrelationStrings, firstCorrelationStrings.Length, NumberOfMessageBytes).Result;
                    Pair <byte[]>[] secondRoundResults = obliviousTransfer.SendAsync(
                        secondCorrelationStrings, secondCorrelationStrings.Length, NumberOfMessageBytes).Result;
                    return(new Pair <Pair <byte[]>[]>(firstRoundResults, secondRoundResults));
                }
            }
        }
        private Pair <byte[][]> RunResumedObliviousTransferReceiverParty(BitArray firstRoundSelectionBits, BitArray secondRoundSelectionBits)
        {
            using (CryptoContext cryptoContext = CryptoContext.CreateDefault())
            {
                using (ITwoPartyNetworkSession session = TestNetworkSession.EstablishTwoParty())
                {
                    ITwoChoicesObliviousTransferChannel       baseOT            = new StatelessTwoChoicesObliviousTransferChannel(new InsecureObliviousTransfer(), session.Channel);
                    ITwoChoicesRandomObliviousTransferChannel obliviousTransfer = new TwoChoicesRandomExtendedObliviousTransferChannel(baseOT, 8, cryptoContext);

                    byte[][] firstRoundResults = obliviousTransfer.ReceiveAsync(
                        firstRoundSelectionBits, firstRoundSelectionBits.Length, NumberOfMessageBytes).Result;
                    byte[][] secondRoundResults = obliviousTransfer.ReceiveAsync(
                        secondRoundSelectionBits, secondRoundSelectionBits.Length, NumberOfMessageBytes).Result;
                    return(new Pair <byte[][]>(firstRoundResults, secondRoundResults));
                }
            }
        }
Esempio n. 9
0
        private void RunInsecureObliviousTransferParty1oo6()
        {
            const int numberOfInvocations = 4;
            const int numberOfOptions     = 6;

            byte[][][] options = new byte[][][]
            {
                TestOptions.Take(numberOfOptions).Select(s => Encoding.ASCII.GetBytes(s)).ToArray(),
                TestOptions.Take(numberOfOptions).Select(s => Encoding.ASCII.GetBytes(s.ToLower())).ToArray(),
                TestOptions.Take(numberOfOptions).Select(s => Encoding.ASCII.GetBytes(s.ToUpper())).ToArray(),
                TestOptions.Take(numberOfOptions).Select(s => Encoding.ASCII.GetBytes(s.ToUpper())).ToArray(),
            };

            using (CryptoContext cryptoContext = CryptoContext.CreateDefault())
            {
                InsecureObliviousTransfer obliviousTransfer = new InsecureObliviousTransfer();

                using (ITwoPartyNetworkSession session = TestNetworkSession.EstablishTwoParty())
                {
                    if (session.LocalParty.Id == 0)
                    {
                        obliviousTransfer.SendAsync(session.Channel, options, numberOfOptions, numberOfInvocations, 6).Wait();
                    }
                    else
                    {
                        int[]    indices = new[] { 4, 1, 3, 5 };
                        byte[][] results = obliviousTransfer.ReceiveAsync(session.Channel, indices, numberOfOptions, 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]])
                                );
                        }
                    }
                }
            }
        }