Пример #1
0
        private bool IsMultStepShareLegal(MultStepBCaseShare recvShareFromPlayer_i, MultStepVerificationPoly recvVerifcationPolynomial)
        {
            if (!IsRecvShareLegal(recvShareFromPlayer_i))
            {
                return(false);
            }

            var RxPolynomial = recvVerifcationPolynomial.RxPolynomial;
            Zp  Ratpoint0    = Zp.EvalutePolynomialAtPoint(RxPolynomial, new Zp(Prime, 0));

            if (!Ratpoint0.Equals(new Zp(Prime, 0)))
            {
                return(false);
            }
            int w                      = NumTheoryUtils.GetFieldMinimumPrimitive(Prime);
            var w_InMyIndex            = new Zp(Prime, NumTheoryUtils.ModPow(w, Party.Id, Prime));
            Zp  RjFromPublicPolynomial = Zp.EvalutePolynomialAtPoint(RxPolynomial, w_InMyIndex);

            Zp temp = recvShareFromPlayer_i.AShare.ConstMul(recvShareFromPlayer_i.BShare).ConstSub(recvShareFromPlayer_i.AbShare);
            Zp RjFromRecvPrivateInfo = w_InMyIndex.ConstMul(recvShareFromPlayer_i.RShare).ConstAdd(temp);

            if (!RjFromPublicPolynomial.Equals(RjFromRecvPrivateInfo))
            {
                return(false);
            }

            return(true);
        }
Пример #2
0
        protected override Zp GetRecombinedResult(IList <Zp> recvList, int prime)
        {
            // Scan recvList - if there are null elements replace them arbitrarily to Zp with zero value
            for (int i = 0; i < recvList.Count; i++)
            {
                if (recvList[i] == null)
                {
                    recvList[i] = new Zp(prime, 0);
                }
            }

            var xVlaues = new List <Zp>();
            int w       = NumTheoryUtils.GetFieldMinimumPrimitive(prime);

            for (int i = 0; i < recvList.Count; i++)
            {
                xVlaues.Add(new Zp(prime, NumTheoryUtils.ModPow(w, i, prime)));
            }

            // Should call Welch-Berlekamp Decoder to fix error at last stage
            var fixedShares = WelchBerlekampDecoder.Decode(xVlaues, recvList, PolynomialDeg, PolynomialDeg, prime);

            if (fixedShares == null)
            {
                throw new Exception("There were more then polynomialDegree = " + PolynomialDeg + " Cheaters - cannot extract results.");
            }

            return(ShamirSharing.Recombine(fixedShares, PolynomialDeg, prime, true));
        }
Пример #3
0
        private static Zp[] getWelchBerlekampConstraintVector(IList <Zp> XVlaues, IList <Zp> YVlaues, int n, int e, int prime)
        {
            var bVector = new Zp[n];

            for (int i = 0; i < n; i++)
            {
                bVector[i] = new Zp(prime, NumTheoryUtils.ModPow(XVlaues[i].Value, e, prime) * YVlaues[i].Value);
            }

            return(bVector);
        }
Пример #4
0
        private static IList <Zp> GenerateF_i_xPolynomial(ZpMatrix f_x_y,
                                                          Zp secret, int playerNum)
        {
            int w   = NumTheoryUtils.GetFieldMinimumPrimitive(secret.Prime);
            int w_i = NumTheoryUtils.ModPow(w, playerNum, secret.Prime);

            var y_values = new int[f_x_y.ColCount];

            for (int i = 0; i < f_x_y.ColCount; i++)
            {
                y_values[i] = NumTheoryUtils.ModPow(w_i, i, secret.Prime);
            }
            return(f_x_y.MulMatrixByScalarsVector(y_values).SumMatrixRows());
        }
Пример #5
0
        private static IList <Zp> GenerateG_i_yPolynomial(ZpMatrix f_x_y,
                                                          Zp secret, int playerNum)
        {
            int w   = NumTheoryUtils.GetFieldMinimumPrimitive(secret.Prime);
            int w_i = NumTheoryUtils.ModPow(w, playerNum, secret.Prime);

            var x_values = new Zp[f_x_y.RowCount];

            for (int i = 0; i < f_x_y.RowCount; i++)
            {
                x_values[i] = new Zp(secret.Prime, NumTheoryUtils.ModPow(w_i, i, secret.Prime));
            }

            var tempArr = f_x_y.Times(new ZpMatrix(x_values, VectorType.Column)).ZpVector;

            return(tempArr);
        }
Пример #6
0
        //public override void loadFromByteArrayNoHeader(BitStream bs, int prime)
        //{
        //    if (bs.readBoolean())
        //        fi_x = bs.readList(prime);
        //    if (bs.readBoolean())
        //        gi_y = bs.readList(prime);
        //}

        //public override void writeToBitStreamNoHeader(BitStream bs)
        //{
        //    bs.writeBoolean(fi_x != null);
        //    if (fi_x != null)
        //        bs.writeList(fi_x);
        //    bs.writeBoolean(gi_y != null);
        //    if (gi_y != null)
        //        bs.writeList(gi_y);
        //}

        //public override byte[] writeToByteArray()
        //{
        //    var bs = new BitStream();
        //    bs.writeMessageType(MessageType.ZP_LISTS);
        //    writeToBitStreamNoHeader(bs);
        //    bs.close();
        //    return bs.ByteArray;
        //}

        public virtual IList <Zp> CalculateF_i_xValuesForPlayers(int numOfPlayers, int prime)
        {
            int w_i, w = NumTheoryUtils.GetFieldMinimumPrimitive(prime);

            int value;
            var f_i_xValues = new List <Zp>();

            for (int playerNum = 0; playerNum < numOfPlayers; playerNum++)
            {
                w_i   = NumTheoryUtils.ModPow(w, playerNum, prime);
                value = 0;
                for (int j = 0; j < fi_x.Count; j++)
                {
                    value += NumTheoryUtils.ModPow(w_i, j, prime) * fi_x[j].Value;
                }
                f_i_xValues.Add(new Zp(prime, value));
            }

            return(f_i_xValues);
        }