Esempio n. 1
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);
                }
            }
        }
        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));
                }
            }
        }