コード例 #1
0
        private void SelectCircuit()
        {
            _circuit = CircuitBuilder.CreateCircuit(SelectedCircuit);

            if (_circuit == null)
            {
                ConsoleOutput.Add("Circuit is not valid.");
                return;
            }

            SourceNodes.Clear();
            foreach (Source source in _circuit.GetSourceNodes())
            {
                SourceNodes.Add(source);
            }
            Nodes.Clear();
            foreach (Node node in _circuit.GetNodes())
            {
                Nodes.Add(node);
            }
            ProbeNodes.Clear();
            foreach (Node node in _nodes.Where(n => n.TypeName == "PROBE").ToList())
            {
                ProbeNodes.Add(node);
            }
        }
コード例 #2
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()
                        );
                }
            }
        }
コード例 #3
0
        public void TestCircuitEvaluation()
        {
            BitArray[] inputs =
            {
                BitArray.FromBinaryString("0111010011"),
                BitArray.FromBinaryString("1101100010"),
                BitArray.FromBinaryString("0111110011")
            };

            Bit[] sequentialInput = inputs.SelectMany(bits => bits).ToArray();

            CircuitBuilder builder = new CircuitBuilder();
            SetIntersectionCircuitRecorder setIntersectionCircuitRecorder =
                new SetIntersectionCircuitRecorder(inputs.Length, inputs[0].Length);

            setIntersectionCircuitRecorder.Record(builder);

            Circuit        circuit        = builder.CreateCircuit();
            ForwardCircuit forwardCircuit = new ForwardCircuit(circuit);

            ICircuitEvaluator <Bit> evaluator = new LocalCircuitEvaluator();
            ReportingBatchCircuitEvaluator <Bit> batchCircuitEvaluator =
                new ReportingBatchCircuitEvaluator <Bit>(new BatchCircuitEvaluator <Bit>(evaluator));

            BitArray lazyEvaluationOutput     = new BitArray(circuit.Evaluate(evaluator, sequentialInput));
            BitArray forwardEvaluationOutput  = new BitArray(forwardCircuit.Evaluate(batchCircuitEvaluator, sequentialInput));
            BitArray expectedEvaluationOutput = BitArray.FromBinaryString("01010000101100");

            EnumerableAssert.AreEqual(
                expectedEvaluationOutput,
                lazyEvaluationOutput
                );

            EnumerableAssert.AreEqual(
                expectedEvaluationOutput,
                forwardEvaluationOutput
                );

            int[] actualBatchSizes   = batchCircuitEvaluator.BatchSizes;
            int[] expectedBatchSizes = { 10, 10, 9, 9, 8 };

            EnumerableAssert.AreEqual(
                expectedBatchSizes,
                actualBatchSizes
                );
        }
コード例 #4
0
        public async Task <object[]> EvaluateAsync(ISecureComputation secureComputation, object[] localInputPrimitives)
        {
            InputPrimitiveDeclaration[]  inputDeclaration  = InputDeclaration;
            OutputPrimitiveDeclaration[] outputDeclaration = OutputDeclaration;

            CircuitBuilder builder = new CircuitBuilder();

            SecurePrimitive[] inputPrimitives  = InputPrimitives(builder, inputDeclaration);
            SecurePrimitive[] outputPrimitives = Run(builder, inputPrimitives);
            OutputPrimitives(builder, outputPrimitives);

            BitArray outputBuffer = await secureComputation.EvaluateAsync(
                new ForwardCircuit(builder.CreateCircuit()),
                CreateInputMapping(inputDeclaration),
                CreateOutputMapping(outputDeclaration),
                CreateLocalInputBuffer(inputDeclaration, localInputPrimitives, secureComputation.MultiPartySession.LocalParty.Id)
                );

            return(CreateLocalOutputPrimitives(outputDeclaration, outputBuffer, secureComputation.MultiPartySession.LocalParty.Id));
        }
コード例 #5
0
        private static void PerformSecureComputation(IMultiPartyNetworkSession session, BitArray expectedOutput)
        {
            BitArray localInput = Inputs[session.LocalParty.Id];

            using CryptoContext cryptoContext = CryptoContext.CreateDefault();

            IObliviousTransfer obliviousTransfer = new NaorPinkasObliviousTransfer(
                new SecurityParameters(47, 23, 4, 1, 1),
                cryptoContext
                );

            IMultiplicativeSharing multiplicativeSharing = new ObliviousTransferMultiplicativeSharing(
                obliviousTransfer,
                cryptoContext
                );

            SecretSharingSecureComputation computation = new SecretSharingSecureComputation(
                session,
                multiplicativeSharing,
                cryptoContext
                );

            SetIntersectionCircuitRecorder circuitRecorder = new SetIntersectionCircuitRecorder(
                session.NumberOfParties,
                localInput.Length
                );

            CircuitBuilder circuitBuilder = new CircuitBuilder();

            circuitRecorder.Record(circuitBuilder);

            ForwardCircuit circuit      = new ForwardCircuit(circuitBuilder.CreateCircuit());
            BitArray       actualOutput = computation
                                          .EvaluateAsync(circuit, circuitRecorder.InputMapping, circuitRecorder.OutputMapping, localInput)
                                          .Result;

            EnumerableAssert.AreEqual(
                expectedOutput,
                actualOutput
                );
        }
コード例 #6
0
        public void TestCircuitEvaluation()
        {
            BitArray[] inputs = new BitArray[]
            {
                BitArray.FromBinaryString("0111010011"),
                BitArray.FromBinaryString("1101100010"),
                BitArray.FromBinaryString("0111110011")
            };

            Bit[] sequentialInput = inputs.SelectMany(bits => bits).ToArray();

            CircuitBuilder builder = new CircuitBuilder();

            (new SetIntersectionCircuitRecorder(inputs.Length, inputs[0].Length)).Record(builder);

            Circuit circuit = builder.CreateCircuit();

            BitArray lazyEvaluationOutput     = new BitArray(circuit.Evaluate(new LocalCircuitEvaluator(), sequentialInput));
            BitArray forwardEvaluationOutput  = new BitArray(new ForwardCircuit(circuit).Evaluate(new LocalCircuitEvaluator(), sequentialInput));
            BitArray expectedEvaluationOutput = BitArray.FromBinaryString("01010000101100");

            CollectionAssert.AreEqual(
                expectedEvaluationOutput,
                lazyEvaluationOutput,
                "Incorrect lazy evaluation output {0} (should be {1}).",
                lazyEvaluationOutput.ToBinaryString(),
                expectedEvaluationOutput.ToBinaryString()
                );

            CollectionAssert.AreEqual(
                expectedEvaluationOutput,
                forwardEvaluationOutput,
                "Incorrect forward evaluation output {0} (should be {1}).",
                forwardEvaluationOutput.ToBinaryString(),
                expectedEvaluationOutput.ToBinaryString()
                );
        }