public async Task <byte[][]> ReceiveAsync(BitArray selectionIndices, int numberOfInvocations, int numberOfMessageBytes)
        {
            if (selectionIndices.Length != numberOfInvocations)
            {
                throw new ArgumentException("Amount of selection indices must match the specified number of invocations.", nameof(selectionIndices));
            }

            if (_receiverState.SeededRandomOracles == null)
            {
                await ExecuteReceiverBaseOTAsync();
            }

            // note(lumip): we need a random bit matrix t as per the construction
            //  of Ishai et al. and we use the trick of Asharov et al. and populate it with the random
            //  expansion of the base OT seeds, i.e., t_k = H(seed_0). Since these are calculated later,
            //  we only set up the matrix structure here.
            BitMatrix tTransposed = new BitMatrix((uint)SecurityParameter, (uint)numberOfInvocations);

            // "perform" _securityParams many 1-out-of-2 OTs with numberOfInvocations bits message length
            // by extending the _securityParams many 1-out-of-2 OTs with _securityParams bits message length
            // (using the seeded random oracles)
            // the purpose of these OTs is to offer to the _sender_ either a column of t or the column xor'ed with
            // the selection bits of the receiver

            // todo(lumip): should try-catch in case random oracle runs out
            //  and ideally performs new base OTs and repeat
            int numberOfRandomBytes = BitArray.RequiredBytes(numberOfInvocations);

            byte[][][] sendBuffer = new byte[SecurityParameter][][];

            Parallel.For(0, SecurityParameter, k =>
            {
                BitArray tColumn = BitArray.FromBytes(
                    _receiverState.SeededRandomOracles[k][0].Take(numberOfRandomBytes).ToArray(),
                    numberOfInvocations
                    );
                tTransposed.SetRow((uint)k, tColumn);

                BitArray mask = BitArray.FromBytes(
                    _receiverState.SeededRandomOracles[k][1].Take(numberOfRandomBytes).ToArray(),
                    numberOfInvocations
                    );

                BitArray maskedSecondOption = tColumn ^ mask ^ selectionIndices;
                sendBuffer[k] = new byte[1][] { maskedSecondOption.ToBytes() };
            });

            await CommunicationTools.WriteOptionsAsync(Channel, sendBuffer, 1, SecurityParameter, numberOfRandomBytes);

            return(await ReceiveMaskedOptionsAsync(selectionIndices, tTransposed, numberOfInvocations, numberOfMessageBytes));
        }
        public async Task <Pair <byte[]>[]> SendAsync(byte[][] correlationStrings, int numberOfInvocations, int numberOfMessageBytes)
        {
            if (correlationStrings.Length != numberOfInvocations)
            {
                throw new ArgumentException("Amount of provided correlation strings must match the specified number of invocations.", nameof(correlationStrings));
            }

            foreach (byte[] message in correlationStrings)
            {
                if (message.Length != numberOfMessageBytes)
                {
                    throw new ArgumentException("The length of of at least one correlation string does not match the specified message length.", nameof(correlationStrings));
                }
            }

            BitMatrix q = await ReceiveQMatrix(numberOfInvocations);

            Debug.Assert(q.Rows == numberOfInvocations);
            Debug.Assert(q.Cols == SecurityParameter);

            Pair <byte[]>[] options       = new Pair <byte[]> [numberOfInvocations];
            byte[][][]      maskedOptions = new byte[numberOfInvocations][][];
            Parallel.For(0, numberOfInvocations, i =>
            {
                Debug.Assert(correlationStrings[i].Length == numberOfMessageBytes);
                RandomOracle randomOracle = RandomOracleProvider.Create();

                options[i] = new Pair <byte[]>();

                BitArray qRow = q.GetRow((uint)i);

                byte[] query  = qRow.ToBytes();
                options[i][0] = randomOracle.Invoke(query).Take(numberOfMessageBytes).ToArray();

                options[i][1] = ByteBuffer.Xor(correlationStrings[i], options[i][0]);

                query = (qRow ^ SenderChoices).ToBytes();

                maskedOptions[i] = new[] { randomOracle.Mask(options[i][1], query) };
                Debug.Assert(maskedOptions[i][0].Length == numberOfMessageBytes);
            });

            await CommunicationTools.WriteOptionsAsync(Channel, maskedOptions, 1, numberOfInvocations, numberOfMessageBytes);

            return(options);
        }
示例#3
0
        public async Task SendAsync(Pair <byte[]>[] options, int numberOfInvocations, int numberOfMessageBytes)
        {
            if (options.Length != numberOfInvocations)
            {
                throw new ArgumentException("Amount of provided option pairs must match the specified number of invocations.", nameof(options));
            }

            for (int j = 0; j < options.Length; ++j)
            {
                foreach (byte[] message in options[j])
                {
                    if (message.Length != numberOfMessageBytes)
                    {
                        throw new ArgumentException("The length of of at least one option does not match the specified message length.", nameof(options));
                    }
                }
            }

            BitMatrix q = await ReceiveQMatrix(numberOfInvocations);

            Debug.Assert(q.Rows == numberOfInvocations);
            Debug.Assert(q.Cols == SecurityParameter);

            byte[][][] maskedOptions = new byte[numberOfInvocations][][];
            Parallel.For(0, numberOfInvocations, i =>
            {
                maskedOptions[i] = new byte[2][];
                BitArray qRow    = q.GetRow((uint)i);
                for (int j = 0; j < 2; ++j)
                {
                    Debug.Assert(options[i][j].Length == numberOfMessageBytes);
                    if (j == 1)
                    {
                        qRow.Xor(SenderChoices);
                    }
                    byte[] query        = qRow.ToBytes();
                    maskedOptions[i][j] = RandomOracleProvider.Create().Mask(options[i][j], query);
                }
            });

            await CommunicationTools.WriteOptionsAsync(Channel, maskedOptions, 2, numberOfInvocations, numberOfMessageBytes);
        }