Esempio n. 1
0
 public void TestRequiredBytes()
 {
     Assert.AreEqual(0, BitQuadrupleArray.RequiredBytes(0));
     Assert.AreEqual(1, BitQuadrupleArray.RequiredBytes(1));
     Assert.AreEqual(1, BitQuadrupleArray.RequiredBytes(2));
     Assert.AreEqual(2, BitQuadrupleArray.RequiredBytes(3));
 }
        public Task <PreprocessedSenderBatch> PreprocessSenderAsync(IMessageChannel channel, int numberOfInvocations)
        {
            byte[]            randomOptionsBuffer = _randomNumberGenerator.GetBytes(BitQuadrupleArray.RequiredBytes(numberOfInvocations));
            BitQuadrupleArray randomOptions       = BitQuadrupleArray.FromBytes(randomOptionsBuffer, numberOfInvocations);

            return(_obliviousTransfer.SendAsync(channel, randomOptions, numberOfInvocations)
                   .ContinueWith(task => new PreprocessedSenderBatch(randomOptions)));
        }
Esempio n. 3
0
        public async Task <BitArray> ReceiveAsync(IMessageChannel channel, QuadrupleIndexArray selectionIndices, int numberOfInvocations)
        {
            if (selectionIndices.Length != numberOfInvocations)
            {
                throw new ArgumentException("Provided selection indices must match the specified number of invocations.", nameof(selectionIndices));
            }

            if (_receiverBatch == null || _nextReceiverInstanceId + numberOfInvocations > _receiverBatch.NumberOfInstances)
            {
                throw new InvalidOperationException("Not enough preprocessed receiver data available.");
            }


            QuadrupleIndexArray deltaSelectionIndices = new QuadrupleIndexArray(numberOfInvocations);

            for (int i = 0; i < numberOfInvocations; ++i)
            {
                int deltaSelectionIndex = (_receiverBatch.GetSelectionIndex(_nextReceiverInstanceId + i) - selectionIndices[i] + 4) % 4;
                deltaSelectionIndices[i] = deltaSelectionIndex;
            }

            await channel.WriteMessageAsync(deltaSelectionIndices.ToBytes());

            byte[] packedMaskedOptionQuadruples = await channel.ReadMessageAsync();

            if (packedMaskedOptionQuadruples.Length != BitQuadrupleArray.RequiredBytes(numberOfInvocations))
            {
                throw new DesynchronizationException("Received incorrect number of masked option quadruples.");
            }

            BitQuadrupleArray maskedOptionQuadruples = BitQuadrupleArray.FromBytes(packedMaskedOptionQuadruples, numberOfInvocations);

            BitArray selectedBits = new BitArray(numberOfInvocations);

            for (int i = 0; i < numberOfInvocations; ++i)
            {
                BitQuadruple maskedOptions = maskedOptionQuadruples[i];
                selectedBits[i] = maskedOptions[selectionIndices[i]] ^ _receiverBatch.GetSelectedOption(_nextReceiverInstanceId + i);
            }

            _nextReceiverInstanceId += numberOfInvocations;

            return(selectedBits);
        }