public ECInfo apply()

in src/com/amazon/corretto/crypto/provider/EcUtils.java [30:90]


        public ECInfo apply(final String curveName) {
            final int[] m = new int[1];
            // 1024 bits is more than large enough for all of these values.
            // There is length checking on the native size.
            final byte[] fieldBasis = new byte[128];
            final byte[] a = new byte[128];
            final byte[] b = new byte[128];
            final byte[] cofactor = new byte[128];
            final byte[] gx = new byte[128];
            final byte[] gy = new byte[128];
            final byte[] order = new byte[128];
            final BigInteger bnCofactor;

            final int nid = curveNameToInfo(normalizeName(curveName), m, fieldBasis, a, b,
                    cofactor, gx, gy, order);

            final ECGenParameterSpec namedSpec = new ECGenParameterSpec(curveName);
            final ECParameterSpec explicitSpec;
            if (nid != 0) {
                // OpenSSL knows about this curve by name
                bnCofactor = new BigInteger(cofactor);
                if (bnCofactor.compareTo(MAX_COFACTOR) > 0) {
                    throw new IllegalArgumentException(
                            "Requested curve has a cofactor which is too large. Curve: " + curveName
                                    + " cofactor " + bnCofactor);
                }
                final ECField field;

                if (m[0] != 0) {
                    field = new ECFieldF2m(m[0], new BigInteger(fieldBasis));
                } else {
                    field = new ECFieldFp(new BigInteger(fieldBasis));
                }

                final EllipticCurve curve = new EllipticCurve(field, new BigInteger(a), new BigInteger(
                        b));
                final ECPoint g = new ECPoint(new BigInteger(gx), new BigInteger(gy));
                explicitSpec = new ECParameterSpec(curve, g, new BigInteger(order), bnCofactor.intValue());
            } else {
                explicitSpec = null;
            }

            ECParameterSpec spec;
            try {
                // First try to translate this to parameters representing a named curve
                AlgorithmParameters parameters = AlgorithmParameters.getInstance("EC");
                parameters.init(namedSpec);
                spec = parameters.getParameterSpec(ECParameterSpec.class);
            } catch (final InvalidParameterSpecException ex) {
                if (explicitSpec != null) {
                    spec = explicitSpec;
                } else {
                    // Neither Java nor OpenSSL know about this curve by name, so throw an exception
                    throw new IllegalArgumentException("Invalid curve name: " + curveName);
                }
            } catch (final NoSuchAlgorithmException ex) {
                throw new RuntimeCryptoException(ex);
            }

            return new ECInfo(curveName, spec, nid);
        }