Recombine() public static method

public static Recombine ( IList sharedSecrets, int polyDeg, System.Numerics.BigInteger prime ) : BigZp
sharedSecrets IList
polyDeg int
prime System.Numerics.BigInteger
return BigZp
示例#1
0
        public void Share(BigZp secret)
        {
            Debug.Assert(Prime == secret.Prime);
            IList <BigZp> coeffs = null;

            int polyDegree = (int)Math.Ceiling(DstQuorum.Size / 3.0) - 1;

            // generate a random polynomial
            var shares = BigShamirSharing.Share(secret, DstQuorum.Size, PolyDegree, out coeffs);

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

            if (PolyCommit != null)
            {
                commitment = BigShamirSharing.GenerateCommitment(DstQuorum.Size, coeffs.ToArray(), Prime, ref witnesses, PolyCommit);
            }
            else
            {
                witnesses = new MG[DstQuorum.Size];
            }

            Multicast(new CommitMsg(commitment), DstQuorum.Members);

            // create share messages
            var shareMsgs = new ShareWitnessMsg <BigZp> [DstQuorum.Size];

            for (int i = 0; i < DstQuorum.Size; i++)
            {
                shareMsgs[i] = new ShareWitnessMsg <BigZp>(shares[i], witnesses[i]);
            }

            if (PolyCommit != null)
            {
                Debug.Assert(PolyCommit.VerifyEval(commitment, new BigZp(Prime, 2), shareMsgs[1].Share, shareMsgs[1].Witness));
            }
            Debug.Assert(BigShamirSharing.Recombine(shares, PolyDegree, Prime) == secret);

            // send the i-th share message to the i-th party
            Send(shareMsgs, DstQuorum.Members);
        }
示例#2
0
        public override void HandleMessage(int fromId, Msg msg)
        {
            Debug.Assert(msg.Type == MsgType.Reconst);
            ReconstRecv[fromId] = (msg as ShareMsg <BigZp>).Share;

            if (ReconstRecv.Count == Quorum.Size)
            {
                // reconstruct the output
                var orderedShares = ReconstRecv.OrderBy(p => p.Key).Select(p => p.Value).ToList();
                int polyDegree    = (int)Math.Ceiling(Quorum.Size / 3.0) - 1;

                Result      = BigShamirSharing.Recombine(orderedShares, polyDegree, Prime);
                IsCompleted = true;
                // Error-correction procedure
                //var xValues = new List<BigZp>();
                //for (int i = 1; i <= reconstRecv.Count; i++)
                //    xValues.Add(new BigZp(Prime, i));

                //var fixedShares = WelchBerlekampDecoder.Decode(xValues, reconstRecv, PolyDegree, PolyDegree, Prime);

                //// interpolate again
                //return BigShamirSharing.Recombine(fixedShares, PolyDegree, Prime);
            }
        }