public void testEncodeDecodeModQ()
 {
     int[]  coeffs  = PolynomialGenerator.GenerateRandom(1000, 2048).coeffs;
     byte[] data    = ArrayEncoder.EncodeModQ(coeffs, 2048);
     int[]  coeffs2 = ArrayEncoder.DecodeModQ(data, 1000, 2048);
     Assert.True(coeffs.SequenceEqual(coeffs2));
 }
        private void GenerateFQ(IRandom Rng, out IPolynomial T, out IntegerPolynomial Fq, out IntegerPolynomial Fp)
        {
            var N        = this.m_ntruParams.N;
            var q        = this.m_ntruParams.Q;
            var df       = this.m_ntruParams.DF;
            var df1      = this.m_ntruParams.DF1;
            var df2      = this.m_ntruParams.DF2;
            var df3      = this.m_ntruParams.DF3;
            var fastFp   = this.m_ntruParams.FastFp;
            var sparse   = this.m_ntruParams.Sparse;
            var polyType = this.m_ntruParams.PolyType;

            Fp = null;

            // choose a random f that is invertible mod 3 and q
            while (true)
            {
                IntegerPolynomial f;

                // choose random t, calculate f and fp
                if (fastFp)
                {
                    // if fastFp=true, f is always invertible mod 3
                    if (polyType == TernaryPolynomialType.SIMPLE)
                    {
                        T = PolynomialGenerator.GenerateRandomTernary(N, df, df, sparse, Rng);
                    }
                    else
                    {
                        T = ProductFormPolynomial.GenerateRandom(N, df1, df2, df3, df3, Rng);
                    }

                    f = T.ToIntegerPolynomial();
                    f.Multiply(3);
                    f.Coeffs[0] += 1;
                }
                else
                {
                    if (polyType == TernaryPolynomialType.SIMPLE)
                    {
                        T = PolynomialGenerator.GenerateRandomTernary(N, df, df - 1, sparse, Rng);
                    }
                    else
                    {
                        T = ProductFormPolynomial.GenerateRandom(N, df1, df2, df3, df3 - 1, Rng);
                    }

                    f  = T.ToIntegerPolynomial();
                    Fp = f.InvertF3();

                    if (Fp == null)
                    {
                        continue;
                    }
                }

                Fq = f.InvertFq(q);

                if (Fq != null)
                {
                    break;
                }
            }
        }
        private void GenerateFQ(IRandom Rng, out IPolynomial t, out IntegerPolynomial fq, out IntegerPolynomial fp)
        {
            int  N      = _encParams.N;
            int  q      = _encParams.Q;
            int  df     = _encParams.DF;
            int  df1    = _encParams.DF1;
            int  df2    = _encParams.DF2;
            int  df3    = _encParams.DF3;
            bool fastFp = _encParams.FastFp;
            bool sparse = _encParams.Sparse;
            TernaryPolynomialType polyType = _encParams.PolyType;

            fp = null;

            // choose a random f that is invertible mod 3 and q
            while (true)
            {
                IntegerPolynomial f;

                // choose random t, calculate f and fp
                if (fastFp)
                {
                    // if fastFp=true, f is always invertible mod 3
                    if (polyType == TernaryPolynomialType.SIMPLE)
                    {
                        t = PolynomialGenerator.GenerateRandomTernary(N, df, df, sparse, Rng);
                    }
                    else
                    {
                        t = ProductFormPolynomial.GenerateRandom(N, df1, df2, df3, df3, Rng);
                    }

                    f = t.ToIntegerPolynomial();
                    f.Multiply(3);
                    f.Coeffs[0] += 1;
                }
                else
                {
                    if (polyType == TernaryPolynomialType.SIMPLE)
                    {
                        t = PolynomialGenerator.GenerateRandomTernary(N, df, df - 1, sparse, Rng);
                    }
                    else
                    {
                        t = ProductFormPolynomial.GenerateRandom(N, df1, df2, df3, df3 - 1, Rng);
                    }

                    f  = t.ToIntegerPolynomial();
                    fp = f.InvertF3();

                    if (fp == null)
                    {
                        continue;
                    }
                }

                fq = f.InvertFq(q);

                if (fq != null)
                {
                    break;
                }
            }
        }
Exemple #4
0
 //un constructeur privé qui ne fait pas de vérif sur les données d'entrée
 protected Curve( List<Vector2> keys, List<Polynomial> polyLst, PolynomialGenerator polyGen ) {
     this.keys = keys;
     this.polyLst = polyLst;
     this.polyGen = polyGen;
 }