Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6542846

EllipticCurve does not allow coefficients with value 0

XMLWordPrintable

    • b01
    • generic, x86
    • generic, windows_xp
    • Verified

        FULL PRODUCT VERSION :
        java version "1.5.0_09"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_09-b01)
        Java HotSpot(TM) Client VM (build 1.5.0_09-b01, mixed mode, sharing)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows XP [Version 5.1.2600]

        A DESCRIPTION OF THE PROBLEM :
        When attempting to create an java.security.spec.EllipticCurve object, and specifying BigInteger.ZERO as either the first or second coefficient, the following exception results.

        java.lang.IllegalArgumentException: first coefficient is negative

        First, the exception is clearly wrong... the first coefficient in this case is not negative, it is zero.

        Secondly, it is possible to have valid elliptic curves that have coefficients of zero. For example, refer to ANSI X9.63-2001, and look at the definitions for any of the following curves: ansip160k1, ansip192k1, ansip224k1, ansip256k1.

        Solving the problem is simply... below is the source from EllipticCurve that contains the bug:

            // Check coefficient c is a valid element in ECField field.
            private static void checkValidity(ECField field, BigInteger c,
        String cName) {
        // can only perform check if field is ECFieldFp or ECFieldF2m.
        if (field instanceof ECFieldFp) {
        BigInteger p = ((ECFieldFp)field).getP();
        if (p.compareTo(c) != 1) {
        throw new IllegalArgumentException(cName + " is too large");
        } else if (c.signum() != 1) {
        throw new IllegalArgumentException(cName + " is negative");
        }
        } else if (field instanceof ECFieldF2m) {
        int m = ((ECFieldF2m)field).getM();
        if (c.bitLength() > m) {
        throw new IllegalArgumentException(cName + " is too large");
        }
        }
            }

        The lines:

        } else if (c.signum() != 1) {
        throw new IllegalArgumentException(cName + " is negative");

        Should be changed to:

        } else if (c.signum() < 0) {
        throw new IllegalArgumentException(cName + " is negative");


        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Call the EllipticCurve constructor as follows:

        new EllipticCurve(new ECFieldFp(new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73", 16)), BigInteger.ZERO, BigInteger.valueOf(7));

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Success, the result should be an EllipticCurve object instance representing the requested curve.
        ACTUAL -
        Failure:

        java.lang.IllegalArgumentException: first coefficient is negative

        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        java.lang.IllegalArgumentException: first coefficient is negative

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        new EllipticCurve(new ECFieldFp(new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73", 16)), BigInteger.ZERO, BigInteger.valueOf(7));
        ---------- END SOURCE ----------

              miroslawzn Miroslaw Niemiec (Inactive)
              ndcosta Nelson Dcosta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: