Beispiel #1
0
        private bool verify(IntegerPolynomial i, IntegerPolynomial s, IntegerPolynomial h)
        {
            int    q           = param.q;
            double normBoundSq = param.normBoundSq;
            double betaSq      = param.betaSq;

            IntegerPolynomial t = h.Multiply(s, q);

            t.Subtract(i);
            long centeredNormSq = (long)(s.CenteredNormSq(q) + betaSq * t.CenteredNormSq(q));

            return(centeredNormSq <= normBoundSq);
        }
Beispiel #2
0
        private bool verify(IntegerPolynomial i, IntegerPolynomial s, IntegerPolynomial h)
        {
            int q = param.q;
            double normBoundSq = param.normBoundSq;
            double betaSq = param.betaSq;

            IntegerPolynomial t = h.Multiply(s, q);
            t.Subtract(i);
            long centeredNormSq = (long)(s.CenteredNormSq(q) + betaSq * t.CenteredNormSq(q));
            return centeredNormSq <= normBoundSq;
        }
Beispiel #3
0
 /**
  * Returns <code>true</code> if the norms of the polynomials <code>F</code> and <code>G</code>
  * are within {@link SignatureParameters#keyNormBound}.
  * @return
  */
 public bool isNormOk()
 {
     return(F.CenteredNormSq(q) < keyNormBoundSq && G.CenteredNormSq(q) < keyNormBoundSq);
 }
Beispiel #4
0
        /**
         * Tests if the basis is valid.
         * @param h the polynomial h (either from the public key or from this basis)
         * @return <code>true</code> if the basis is valid, <code>false</code> otherwise
         */
        public bool isValid(IntegerPolynomial h)
        {
            if (f.ToIntegerPolynomial().Coeffs.Length != N)
            {
                return(false);
            }
            if (fPrime.ToIntegerPolynomial().Coeffs.Length != N)
            {
                return(false);
            }

            if (h.Coeffs.Length != N || !h.IsReduced(q))
            {
                return(false);
            }

            // determine F, G, g from f, fPrime, h using the eqn. fG-Fg=q
            IPolynomial       FPoly = basisType == BasisType.STANDARD ? fPrime : f.Multiply(h, q);
            IntegerPolynomial F     = FPoly.ToIntegerPolynomial();
            IntegerPolynomial fq    = f.ToIntegerPolynomial().InvertFq(q);
            IPolynomial       g;

            if (basisType == BasisType.STANDARD)
            {
                g = f.Multiply(h, q);
            }
            else
            {
                g = fPrime;
            }
            IntegerPolynomial G = g.Multiply(F);

            G.Coeffs[0] -= q;
            G            = G.Multiply(fq, q);
            G.ModCenter(q);

            // check norms of F and G
            if (!new FGBasis(f, fPrime, h, F, G, q, polyType, basisType, keyNormBoundSq).isNormOk())
            {
                return(false);
            }
            // check norms of f and g
            int factor = N / 24;

            if (f.ToIntegerPolynomial().CenteredNormSq(q) * factor >= F.CenteredNormSq(q))
            {
                return(false);
            }
            if (g.ToIntegerPolynomial().CenteredNormSq(q) * factor >= G.CenteredNormSq(q))
            {
                return(false);
            }

            // check ternarity
            if (polyType == TernaryPolynomialType.SIMPLE)
            {
                if (!f.ToIntegerPolynomial().IsTernary())
                {
                    return(false);
                }
                if (!g.ToIntegerPolynomial().IsTernary())
                {
                    return(false);
                }
            }
            else
            {
                if (!(f.GetType().IsAssignableFrom(typeof(ProductFormPolynomial))))
                {
                    return(false);
                }
                if (!(g.GetType().IsAssignableFrom(typeof(ProductFormPolynomial))))
                {
                    return(false);
                }
            }

            return(true);
        }