Exemplo n.º 1
0
  /**
   * return a parameter spec representing the passed in named curve. The routine returns null if the
   * curve is not present.
   *
   * @param name the name of the curve requested
   * @return a parameter spec for the curve, null if it is not available.
   */
  public static ECNamedCurveParameterSpec getParameterSpec(String name) {
    X9ECParameters ecP = org.spongycastle.crypto.ec.CustomNamedCurves.getByName(name);
    if (ecP == null) {
      try {
        ecP = org.spongycastle.crypto.ec.CustomNamedCurves.getByOID(new ASN1ObjectIdentifier(name));
      } catch (IllegalArgumentException e) {
        // ignore - not an oid
      }

      if (ecP == null) {
        ecP = org.spongycastle.asn1.x9.ECNamedCurveTable.getByName(name);
        if (ecP == null) {
          try {
            ecP =
                org.spongycastle.asn1.x9.ECNamedCurveTable.getByOID(new ASN1ObjectIdentifier(name));
          } catch (IllegalArgumentException e) {
            // ignore - not an oid
          }
        }
      }
    }

    if (ecP == null) {
      return null;
    }

    return new ECNamedCurveParameterSpec(
        name, ecP.getCurve(), ecP.getG(), ecP.getN(), ecP.getH(), ecP.getSeed());
  }
Exemplo n.º 2
0
 static {
   // Tell Bouncy Castle to precompute data that's needed during secp256k1 calculations. Increasing
   // the width
   // number makes calculations faster, but at a cost of extra memory usage and with decreasing
   // returns. 12 was
   // picked after consulting with the BC team.
   FixedPointUtil.precompute(CURVE_PARAMS.getG(), 12);
   CURVE =
       new ECDomainParameters(
           CURVE_PARAMS.getCurve(), CURVE_PARAMS.getG(), CURVE_PARAMS.getN(), CURVE_PARAMS.getH());
   HALF_CURVE_ORDER = CURVE_PARAMS.getN().shiftRight(1);
 }