protected override Task <BitArray> ComputePairwiseMultiplicativeSharesAsync(ITwoPartyNetworkSession session, BitArray leftShares, BitArray rightShares, int numberOfInvocations) { // Given local shares x1, y1 // compute share of x1 * y2 + x2 * y1 return(session.RemoteParty.Id < session.LocalParty.Id ? ComputeSenderSharesAsync(session.Channel, leftShares, rightShares, numberOfInvocations) : ComputeReceiverSharesAsync(session.Channel, leftShares, rightShares, numberOfInvocations)); }
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 (ITwoPartyNetworkSession session = TestNetworkSession.EstablishTwoParty()) { ITwoChoicesObliviousTransferChannel baseOT = new StatelessTwoChoicesObliviousTransferChannel(new InsecureObliviousTransfer(), session.Channel); ITwoChoicesRandomObliviousTransferChannel obliviousTransfer = new TwoChoicesRandomExtendedObliviousTransferChannel(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 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 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]]) ); } } } } }
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]]) ); } } }
protected abstract Task <BitArray> ComputePairwiseMultiplicativeSharesAsync(ITwoPartyNetworkSession session, BitArray leftShares, BitArray rightShares, int numberOfInvocations);