Example #1
0
        private static ZpMatrix getWelchBerlekampMatrix(IList <Zp> XVlaues, IList <Zp> YVlaues, int n, int e, int prime)
        {
            var NVanderMonde = ZpMatrix.GetVandermondeMatrix(n - e, XVlaues, prime).Transpose;
            var EVanderMonde = ZpMatrix.GetVandermondeMatrix(e, XVlaues, prime).Transpose;

            int[] scalarVector = new int[YVlaues.Count];
            int   i            = 0;

            foreach (Zp zp in YVlaues)
            {
                scalarVector[i++] = -zp.Value;
            }

            EVanderMonde = EVanderMonde.MulMatrixByScalarsVector(scalarVector);
            return(ZpMatrix.GetConcatenationMatrix(NVanderMonde, EVanderMonde));
        }
Example #2
0
        /// <summary>
        /// Evaluates the shares of secret with polynomial of degree 'polynomDeg' and 'numPlayers' players.
        /// </summary>
        private static IList <Zp> Share(Zp secret, int numPlayers, int polynomDeg, bool usePrimitiveShare, out IList <Zp> coeffs)
        {
#if NO_COMPUTATION
            // send some dummy shares
            var shares = new Zp[numPlayers];
            for (int i = 0; i < numPlayers; i++)
            {
                shares[i] = new Zp(secret.Prime);
            }
            return(shares);
#else
            Debug.Assert(numPlayers > polynomDeg, "Polynomial degree cannot be greater than or equal to the number of players!");

            // Create a random polynomial - f(x)
            // Note: Polynomial of degree d has d+1 coefficients
            var randomMatrix = ZpMatrix.GetRandomMatrix(1, polynomDeg + 1, secret.Prime);

            // The free variable in the Random Polynomial (i.e.	f(x)) is the secret
            randomMatrix.SetMatrixCell(0, 0, secret);

            // Polynomial coefficients
            coeffs = randomMatrix.GetMatrixRow(0);

            // Create vanderMonde matrix
            ZpMatrix vanderMonde;
            if (usePrimitiveShare)
            {
                vanderMonde = ZpMatrix.GetPrimitiveVandermondeMatrix(polynomDeg + 1, numPlayers, secret.Prime);
            }
            else
            {
                vanderMonde = ZpMatrix.GetVandermondeMatrix(polynomDeg + 1, numPlayers, secret.Prime);
            }

            // Compute f(i) for the i-th  player
            var sharesArr = randomMatrix.Times(vanderMonde).ZpVector;
            Debug.Assert(sharesArr != null);
            Debug.Assert(sharesArr.Length == numPlayers);
            return(sharesArr);
#endif
        }
Example #3
0
        /// <summary>
        /// Each party in the new quorum needs to call this with the shares received from the old quorum to calculate its share
        /// </summary>
        public static Zp CombineReshares(IList <Zp> reshares, int newQuorumSize, int prime)
        {
            int oldQuorumSize = reshares.Count;

            if (oldQuorumSize != newQuorumSize)
            {
                throw new System.ArgumentException("Do not support case where quorums are of different sizes");
            }

            // Compute the first row of the inverse Vandermonde matrix
            var vandermonde    = ZpMatrix.GetVandermondeMatrix(oldQuorumSize, newQuorumSize, prime);
            var vandermondeInv = vandermonde.Inverse.GetMatrixColumn(0);

            var S = new Zp(prime);

            for (var i = 0; i < newQuorumSize; i++)
            {
                S += vandermondeInv[i] * reshares[i];
            }

            return(S);
        }