Exemplo n.º 1
0
        public static void SetupBitwiseAndProtocol(Quorum quorum)
        {
            int n = quorum.Size;

            var polyDeg = (int)Math.Ceiling(n / 3.0) - 1;

            var sharesA = BigShamirSharing.Share(new BigZp(prime, 0), n, polyDeg);
            var sharesB = BigShamirSharing.Share(new BigZp(prime, 1), n, polyDeg);
            var sharesC = BigShamirSharing.Share(new BigZp(prime, 0), n, polyDeg);

            var sharesD = BigShamirSharing.Share(new BigZp(prime, 0), n, polyDeg);
            var sharesE = BigShamirSharing.Share(new BigZp(prime, 1), n, polyDeg);
            var sharesF = BigShamirSharing.Share(new BigZp(prime, 1), n, polyDeg);


            for (int i = 0; i < n; i++)
            {
                Quorum q = quorum.Clone() as Quorum;
                TestParty <List <Share <BigZp> > > party = new TestParty <List <Share <BigZp> > >();
                party.UnderTest = new BitwiseOperationProtocol(party, q,
                                                               MakeList(sharesA[i], sharesB[i], sharesC[i]),
                                                               MakeList(sharesD[i], sharesE[i], sharesF[i]),
                                                               new SharedBitAnd.ProtocolFactory(party, q));
                NetSimulator.RegisterParty(party);
            }
        }
Exemplo n.º 2
0
        public static void TestShamir(int n, BigInteger prime, int seed)
        {
            var PolyDegree = (int)Math.Ceiling(n / 3.0);
            var i1         = new BigZp(prime, StaticRandom.Next(1000000000));
            var i2         = new BigZp(prime, StaticRandom.Next(1000000000));
            var i3         = new BigZp(prime, StaticRandom.Next(1000000000));
            var i4         = new BigZp(prime, StaticRandom.Next(1000000000));
            var a          = i1 + i2 + i3 + i4;

            var shares1 = BigShamirSharing.Share(i1, n, PolyDegree - 1);
            var shares2 = BigShamirSharing.Share(i2, n, PolyDegree - 1);
            var shares3 = BigShamirSharing.Share(i3, n, PolyDegree - 1);
            var shares4 = BigShamirSharing.Share(i4, n, PolyDegree - 1);

            var rs = new List <BigZp>(n);

            for (int i = 0; i < n; i++)
            {
                rs.Add(new BigZp(prime));
                rs[i] += shares1[i];
                rs[i] += shares2[i];
                rs[i] += shares3[i];
                rs[i] += shares4[i];
            }

            var t = BigShamirSharing.Recombine(rs, PolyDegree - 1, prime);
        }
Exemplo n.º 3
0
        /*
         * public static void SetupSimpleCircuitEvaluation(Quorum quorum)
         * {
         *  int n = quorum.Size;
         *  var polyDeg = (int)Math.Ceiling(n / 3.0) - 1;
         *
         *  Debug.Assert((n & (n - 1)) == 0); // is power of 2
         *
         *  network = new LPSortingNetwork(n);
         *
         *  IList<BigZp>[] shares = new IList<BigZp>[n];
         *
         *  for (int i = 0; i < n; i++)
         *      shares[i] = BigShamirSharing.Share(new BigZp(prime, 500 - 2*i), n, polyDeg);
         *
         *  foreach (var id in quorum.Members)
         *  {
         *      Dictionary<InputGateAddress, Share<BigZp>> inShares = new Dictionary<InputGateAddress, Share<BigZp>>();
         *
         *      int i = 0;
         *      foreach (var inAddr in network.Circuit.InputAddrs)
         *      {
         *          inShares[inAddr] = new Share<BigZp>(shares[i][id]);
         *          i++;
         *      }
         *
         *      TestParty<IDictionary<OutputGateAddress, Share<BigZp>>> party = new TestParty<IDictionary<OutputGateAddress, Share<BigZp>>>();
         *      party.UnderTest = new SecureGroupCircuitEvaluation(party, quorum.Clone() as Quorum, network.Circuit, inShares);
         *      NetSimulator.RegisterParty(party);
         *  }
         * }
         */
        public static void SetupMultiQuorumCircuitEvaluation(Quorum bigQuorum)
        {
            int n = bigQuorum.Size;

            int qSize = n / 2;

            var polyDeg = (int)Math.Ceiling(qSize / 3.0) - 1;

            var quorums = new List <Quorum>();

            quorums.Add(new Quorum(0, 0, qSize));
            quorums.Add(new Quorum(1, qSize, 2 * qSize));

            Debug.Assert((n & (n - 1)) == 0); // is power of 2

            network = new LPSortingNetwork(n);
            //network = SortingNetworkFactory.CreateButterflyTournamentRound(n);

            network.CollapsePermutationGates();

            IList <BigZp>[] shares = new IList <BigZp> [n];

            for (int i = 0; i < n; i++)
            {
                shares[i] = BigShamirSharing.Share(new BigZp(prime, 500 - 2 * i), qSize, polyDeg);
            }

            Dictionary <Gate, Quorum> gqmapping = new Dictionary <Gate, Quorum>();

            for (int i = 0; i < network.Circuit.TopologicalOrder.Count; i++)
            {
                gqmapping[network.Circuit.TopologicalOrder[i]] = quorums[i];
            }

            foreach (var id in bigQuorum.Members)
            {
                Dictionary <InputGateAddress, Share <BigZp> > inShares = new Dictionary <InputGateAddress, Share <BigZp> >();

                int i = 0;
                foreach (var inAddr in network.Circuit.InputAddrs)
                {
                    inShares[inAddr] = new Share <BigZp>(shares[i][id % 4]);
                    i++;
                }

                TestParty <IDictionary <OutputGateAddress, Share <BigZp> > > party = new TestParty <IDictionary <OutputGateAddress, Share <BigZp> > >();
                Quorum[] quorumsClone = quorums.Select(a => a.Clone() as Quorum).ToArray();

                party.UnderTest =
                    new SecureMultiQuorumCircuitEvaluation <Share <BigZp> >(party, quorumsClone[id / qSize], quorumsClone,
                                                                            ProtocolIdGenerator.GenericIdentifier(0), network.Circuit, inShares, new BigZpShareGateEvaluationFactory(prime), gqmapping, prime);

                NetSimulator.RegisterParty(party);
            }
        }
Exemplo n.º 4
0
        private void Reshare(BigZp secret)
        {
            Debug.Assert(Prime == secret.Prime);

            IList <BigZp> coeffs = null;

            var shares = BigShamirSharing.Share(secret, FinalShareCount, NewPolyDeg, out coeffs);

            MG[] witnesses  = null;
            MG   commitment = null;

            if (PolyCommit != null)
            {
                commitment = BigShamirSharing.GenerateCommitment(FinalShareCount, coeffs.ToArray(), Prime, ref witnesses, (Quorums[TO] as ByzantineQuorum).PolyCommit);

                // fake random generation round
                for (int i = 0; i < Quorums[TO].Size; i++)
                {
                    NetSimulator.FakeMulticast(Quorums[TO].Size, secret.Size);
                }
                // fake commitment and challenge response
                NetSimulator.FakeMulticast(Quorums[TO].Size, secret.Size);
                NetSimulator.FakeMulticast(Quorums[TO].Size, secret.Size);
            }
            else
            {
                witnesses = new MG[FinalShareCount];
            }

            QuorumBroadcast(new CommitMsg(commitment), TO);

            // create the share messages
            if (PolyCommit != null)
            {
                Debug.Assert(PolyCommit.VerifyEval(commitment, new BigZp(Prime, 2), shares[1], witnesses[1]));
            }
            Debug.Assert(BigShamirSharing.Recombine(shares, NewPolyDeg, Prime) == secret);

            int numSent = 0;

            //int delay = (PolyCommit != null) ? 1 : 0;
            foreach (var toMember in Quorums[TO].Members)
            {
                for (int i = 0; i < FinalSharesPerParty; i++)
                {
                    Send(toMember, new ShareWitnessMsg <BigZp>(shares[numSent], witnesses[numSent]));
                    numSent++;
                }
            }
        }
Exemplo n.º 5
0
        public static void SetupCompareAndSwap(Quorum quorum)
        {
            int n       = quorum.Size;
            var polyDeg = (int)Math.Ceiling(n / 3.0) - 1;

            var sharesA = BigShamirSharing.Share(new BigZp(prime, 440), n, polyDeg);
            var sharesB = BigShamirSharing.Share(new BigZp(prime, 450), n, polyDeg);

            for (int i = 0; i < n; i++)
            {
                TestParty <Share <BigZp>[]> party = new TestParty <Share <BigZp>[]>();
                party.UnderTest = new CompareAndSwapProtocol(party, quorum.Clone() as Quorum, new Share <BigZp>(sharesA[i]), new Share <BigZp>(sharesB[i]));
                NetSimulator.RegisterParty(party);
            }
        }
Exemplo n.º 6
0
        public static void SetupLessThan(Quorum quorum)
        {
            int n       = quorum.Size;
            var polyDeg = (int)Math.Ceiling(n / 3.0) - 1;

            var sharesA = BigShamirSharing.Share(new BigZp(prime, 700), n, polyDeg);
            var sharesB = BigShamirSharing.Share(new BigZp(prime, 549), n, polyDeg);

            for (int i = 0; i < n; i++)
            {
                TestParty <Share <BigZp> > party = new TestParty <Share <BigZp> >();
                party.UnderTest = new ShareLessThanProtocol(party, quorum, new Share <BigZp>(sharesA[i]), new Share <BigZp>(sharesB[i]));
                NetSimulator.RegisterParty(party);
            }
        }
Exemplo n.º 7
0
        public static void SetupLeastSignificantBit(Quorum quorum)
        {
            int n = quorum.Size;

            var input   = new BigZp(prime, 2);
            var polyDeg = (int)Math.Ceiling(n / 3.0) - 1;

            var shares = BigShamirSharing.Share(input, n, polyDeg);

            for (int i = 0; i < n; i++)
            {
                TestParty <Share <BigZp> > party = new TestParty <Share <BigZp> >();
                party.UnderTest = new LeastSignificantBitProtocol(party, quorum, new Share <BigZp>(shares[i]));
                NetSimulator.RegisterParty(party);
            }
        }
Exemplo n.º 8
0
        public static void SetupReconstructionProtocol(Quorum quorum)
        {
            int n       = quorum.Size;
            var input   = new BigZp(prime, 20);
            var polyDeg = (int)Math.Ceiling(n / 3.0) - 1;

            var shares = BigShamirSharing.Share(input, n, polyDeg);

            for (int i = 0; i < n; i++)
            {
                TestParty <BigZp>      party = new TestParty <BigZp>();
                ReconstructionProtocol rp    = new ReconstructionProtocol(party, quorum, new Share <BigZp>(shares[i]));
                party.UnderTest = rp;
                NetSimulator.RegisterParty(party);
            }
        }
Exemplo n.º 9
0
        public static void SetupBitCompositionProtocol(Quorum quorum)
        {
            int n = quorum.Size;

            var polyDeg = (int)Math.Ceiling(n / 3.0) - 1;

            var sharesA = BigShamirSharing.Share(new BigZp(prime, 0), n, polyDeg);
            var sharesB = BigShamirSharing.Share(new BigZp(prime, 1), n, polyDeg);
            var sharesC = BigShamirSharing.Share(new BigZp(prime, 1), n, polyDeg);

            for (int i = 0; i < n; i++)
            {
                TestParty <Share <BigZp> > party = new TestParty <Share <BigZp> >();
                party.UnderTest = new BitCompositionProtocol(party, quorum,
                                                             MakeList(sharesA[i], sharesB[i], sharesC[i]), prime);
                NetSimulator.RegisterParty(party);
            }
        }
Exemplo n.º 10
0
        public static void SetupPrefixOrProtocol(Quorum quorum)
        {
            int n       = quorum.Size;
            var polyDeg = (int)Math.Ceiling(n / 3.0) - 1;

            var sharesA = BigShamirSharing.Share(new BigZp(prime, 0), n, polyDeg);
            var sharesB = BigShamirSharing.Share(new BigZp(prime, 0), n, polyDeg);
            var sharesC = BigShamirSharing.Share(new BigZp(prime, 0), n, polyDeg);
            var sharesD = BigShamirSharing.Share(new BigZp(prime, 0), n, polyDeg);

            for (int i = 0; i < n; i++)
            {
                TestParty <List <Share <BigZp> > > party = new TestParty <List <Share <BigZp> > >();
                party.UnderTest = new PrefixOperationProtocol(party, quorum,
                                                              MakeList(sharesA[i], sharesB[i], sharesC[i], sharesD[i]),
                                                              new SharedBitOr.ProtocolFactory(party, quorum));
                NetSimulator.RegisterParty(party);
            }
        }
Exemplo n.º 11
0
        public BigZp GenerateRandom()
        {
            int polyDegree = NumParties / 3;

            BigInteger myRandom;

            if (Prime > int.MaxValue)
            {
                myRandom = StaticRandom.Next(Prime);
            }
            else
            {
                myRandom = StaticRandom.Next((int)Prime);
            }

            IList <BigZp>       shares   = BigShamirSharing.Share(new BigZp(Prime, myRandom), PartyIds.Count, PartyIds.Count / 3);
            IList <BigShareMsg> sendMsgs = new List <BigShareMsg>();

            foreach (BigZp share in shares)
            {
                sendMsgs.Add(new BigShareMsg(share));
            }

            IList <BigShareMsg> recvMsgs = SendReceive(PartyIds, sendMsgs);

            List <BigZp> receivedShares = new List <BigZp>();

            foreach (BigShareMsg shareMsg in recvMsgs)
            {
                receivedShares.Add(shareMsg.Value);
            }

            /*
             * eVSS sharing = new eVSS(Party, PartyIds, Prime, NumParties / 3);
             * sharing.Setup(RandGen.Next(int.MinValue, int.MaxValue));
             *
             * List<BigZp> receivedShares = sharing.ShareVerify(new BigZp(Prime, myRandom), true);
             */

            BigZp combinedShare = new BigZp(Prime);

            for (var i = 0; i < receivedShares.Count; i++)
            {
                combinedShare += receivedShares[i];
            }

            //BigZp random = sharing.Reconst(combinedShare);

            var finalShareMsgs = BroadcastReceive(new BigShareMsg(combinedShare));

            finalShareMsgs.Sort(new SenderComparer());

            var finalShares = new List <BigZp>();

            foreach (var finalShareMsg in finalShareMsgs)
            {
                finalShares.Add(finalShareMsg.Value);
            }

            BigZp random = BigShamirSharing.Recombine(finalShares, PartyIds.Count / 3, Prime, false);

            return(random);
        }