Ejemplo n.º 1
0
        /// <summary>
        /// Deterministically generates a blinding polynomial from a seed and a message representative
        /// </summary>
        /// 
        /// <param name="Seed">The seed value</param>
        /// 
        /// <returns>A blinding polynomial</returns>
        private IPolynomial GenerateBlindingPoly(byte[] Seed)
        {
            int N = _encParams.N;
            IndexGenerator ig = new IndexGenerator(Seed, _encParams);

            if (_encParams.PolyType == TernaryPolynomialType.PRODUCT) //.8, .6
            {
                SparseTernaryPolynomial r1 = SparseTernaryPolynomial.GenerateBlindingPoly(ig, N, _encParams.DR1);
                SparseTernaryPolynomial r2 = SparseTernaryPolynomial.GenerateBlindingPoly(ig, N, _encParams.DR2);
                SparseTernaryPolynomial r3 = SparseTernaryPolynomial.GenerateBlindingPoly(ig, N, _encParams.DR3);

                return new ProductFormPolynomial(r1, r2, r3);
            }
            else
            {
                if (_encParams.Sparse)
                    return SparseTernaryPolynomial.GenerateBlindingPoly(ig, N, _encParams.DR);
                else
                    return DenseTernaryPolynomial.GenerateBlindingPoly(ig, N, _encParams.DR);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Generates a blinding polynomial using an IndexGenerator
 /// </summary>
 /// 
 /// <param name="Ig">An Index Generator</param>
 /// <param name="N">The number of coefficients</param>
 /// <param name="Dr">The number of ones / negative ones</param>
 /// 
 /// <returns>A blinding polynomial</returns>
 public static DenseTernaryPolynomial GenerateBlindingPoly(IndexGenerator Ig, int N, int Dr)
 {
     return new DenseTernaryPolynomial(GenerateBlindingCoeffs(Ig, N, Dr));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Generates a blinding polynomial using an IndexGenerator
        /// </summary>
        /// 
        /// <param name="Ig">An Index Generator</param>
        /// <param name="N">The number of coefficients</param>
        /// <param name="Dr">The number of ones / negative ones</param>
        /// 
        /// <returns>A blinding polynomial</returns>
        public static SparseTernaryPolynomial GenerateBlindingPoly(IndexGenerator Ig, int N, int Dr)
        {
            int[] coeffs = new int[N];   // an IntegerPolynomial-style representation of the new polynomial

            int[] ones = new int[Dr];
            int i = 0;
            while (i < Dr)
            {
                int r = Ig.NextIndex();
                if (coeffs[r] == 0)
                {
                    ones[i] = r;
                    coeffs[r] = 1;
                    i++;
                }
            }

            int[] negOnes = new int[Dr];
            i = 0;

            while (i < Dr)
            {
                int r = Ig.NextIndex();
                if (coeffs[r] == 0)
                {
                    negOnes[i] = r;
                    coeffs[r] = -1;
                    i++;
                }
            }

            return new SparseTernaryPolynomial(N, ones, negOnes);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Generates an <c>int</c> array containing <c>dr</c> elements equal to <c>1</c>
        /// and <c>dr</c> elements equal to <c>-1</c> using an index generator.
        /// </summary>
        /// 
        /// <param name="Ig">An Index Generator</param>
        /// <param name="N">The number of coefficients</param>
        /// <param name="Dr">The number of ones / negative ones</param>
        /// 
        /// <returns>An array containing numbers between <c>-1</c> and <c>1</c></returns>
        private static int[] GenerateBlindingCoeffs(IndexGenerator Ig, int N, int Dr)
        {
            int[] r = new int[N];
            for (int coeff = -1; coeff <= 1; coeff += 2)
            {
                int t = 0;
                while (t < Dr)
                {
                    int i = Ig.NextIndex();
                    if (r[i] == 0)
                    {
                        r[i] = coeff;
                        t++;
                    }
                }
            }

            return r;
        }