List of usage examples for org.bouncycastle.asn1.x9 ECNamedCurveTable getNames
public static Enumeration getNames()
From source file:com.yahoo.athenz.zts.store.DataStore.java
License:Apache License
String getCurveName(org.bouncycastle.jce.spec.ECParameterSpec ecParameterSpec) {
String curveName = null;/*w w w. j av a2 s .c o m*/
for (Enumeration names = ECNamedCurveTable.getNames(); names.hasMoreElements();) {
final String name = (String) names.nextElement();
final X9ECParameters params = ECNamedCurveTable.getByName(name);
if (params.getN().equals(ecParameterSpec.getN()) && params.getH().equals(ecParameterSpec.getH())
&& params.getCurve().equals(ecParameterSpec.getCurve())
&& params.getG().equals(ecParameterSpec.getG())) {
curveName = name;
break;
}
}
return curveName;
}
From source file:org.xipki.security.p11.sun.SunNamedCurveExtender.java
License:Open Source License
private static void addNamedCurves_jdk17() { final Class<?>[] Param_NamedCurve_add = new Class[] { String.class, String.class, int.class, String.class, String.class, String.class, String.class, String.class, String.class, int.class }; final Class<?>[] Param_getCurve = new Class[] { String.class }; Method method_add = getMethod(class_NamedCurve, "add", Param_NamedCurve_add); if (method_add == null) { return;//from www . j a v a2s . c o m } Method method_getCurve = getMethod(class_NamedCurve, "getECParameterSpec", Param_getCurve); if (method_getCurve == null) { return; } Field field_SPLIT_PATTERN = getField(class_NamedCurve, "SPLIT_PATTERN"); if (field_SPLIT_PATTERN == null) { return; } try { field_SPLIT_PATTERN.set(null, SPLIT_PATTERN); } catch (IllegalArgumentException | IllegalAccessException e) { final String message = "could not set Field SPLIT_PATTERN"; if (LOG.isWarnEnabled()) { LOG.warn(LogUtil.buildExceptionLogFormat(message), e.getClass().getName(), e.getMessage()); } LOG.debug(message, e); return; } Set<String> processedCurveOids = new HashSet<>(); Map<String, String> addedCurves = new HashMap<>(); Enumeration<?> curveNames = ECNamedCurveTable.getNames(); while (curveNames.hasMoreElements()) { String curveName = (String) curveNames.nextElement(); ASN1ObjectIdentifier curveId = getCurveId(curveName); if (curveId == null) { LOG.info("cound not find curve OID for curve {}, ignore it", curveName); continue; } String curveDesc = "named curve " + curveName + " (" + curveId + ")"; if (processedCurveOids.contains(curveId.getId())) { LOG.debug("{} is already processed, ignore it", curveDesc); continue; } processedCurveOids.add(curveId.getId()); if (curve_isRegistered(method_getCurve, curveId)) { LOG.debug("{} is already registered, ignore it", curveDesc); continue; } X9ECParameters params = ECNamedCurveTable.getByOID(curveId); ECCurve curve = params.getCurve(); if (curve instanceof ECCurve.Fp || curve instanceof ECCurve.F2m) { CurveData c = new CurveData(params); boolean added = NamedCurve_add(method_add, curveName, curveId.getId(), c.type, c.sfield, c.a, c.b, c.x, c.y, c.n, c.h); if (added) { LOG.debug("added {}", curveDesc); addedCurves.put(curveName, curveId.getId()); } else { LOG.warn("could not add {}", curveDesc); } } else { LOG.info("unknown curve type {}", curve.getClass().getName()); } } try { field_SPLIT_PATTERN.set(null, null); } catch (IllegalArgumentException | IllegalAccessException e) { final String message = "could not set Field SPLIT_PATTERN"; if (LOG.isWarnEnabled()) { LOG.warn(LogUtil.buildExceptionLogFormat(message), e.getClass().getName(), e.getMessage()); } LOG.debug(message, e); return; } logAddedCurves(addedCurves); }
From source file:org.xipki.security.p11.sun.SunNamedCurveExtender.java
License:Open Source License
private static void addNamedCurves_jdk18on() { final Class<?>[] Param_CurveDB_add = new Class[] { String.class, String.class, int.class, String.class, String.class, String.class, String.class, String.class, String.class, int.class, Pattern.class }; final Class<?>[] Param_getCurve = new Class[] { String.class }; Method method_add = getMethod(class_CurveDB, "add", Param_CurveDB_add); if (method_add == null) { return;//from ww w .jav a2 s. c o m } Method method_getCurve = getMethod(class_CurveDB, "lookup", Param_getCurve); if (method_getCurve == null) { return; } Field field_oidMap = getField(class_CurveDB, "oidMap"); if (field_oidMap == null) { return; } Field field_specCollection = getField(class_CurveDB, "specCollection"); if (field_specCollection == null) { return; } Set<String> processedCurveOids = new HashSet<>(); Map<String, String> addedCurves = new HashMap<>(); Enumeration<?> curveNames = ECNamedCurveTable.getNames(); while (curveNames.hasMoreElements()) { String curveName = (String) curveNames.nextElement(); ASN1ObjectIdentifier curveId = getCurveId(curveName); if (curveId == null) { LOG.debug("cound not find curve OID for curve {}, ignore it", curveName); continue; } String curveDesc = "named curve " + curveName + " (" + curveId + ")"; if (processedCurveOids.contains(curveId.getId())) { LOG.debug("{} is already processed, ignore it", curveDesc); continue; } processedCurveOids.add(curveId.getId()); if (curve_isRegistered(method_getCurve, curveId)) { LOG.info("{} is already registered, ignore it", curveDesc); continue; } X9ECParameters params = ECNamedCurveTable.getByOID(curveId); ECCurve curve = params.getCurve(); if (curve instanceof ECCurve.Fp || curve instanceof ECCurve.F2m) { CurveData c = new CurveData(params); boolean added = CurveDB_add(method_add, curveName, curveId.getId(), c.type, c.sfield, c.a, c.b, c.x, c.y, c.n, c.h); if (added) { LOG.debug("added {}", curveDesc); addedCurves.put(curveName, curveId.getId()); } else { LOG.warn("could not add {}", curveDesc); } } else { LOG.info("unknown curve type {}", curve.getClass().getName()); } } try { Map<?, ?> oidMap = (Map<?, ?>) field_oidMap.get(null); Collection<?> namedCurves = Collections.unmodifiableCollection(oidMap.values()); field_specCollection.set(null, namedCurves); } catch (IllegalArgumentException | IllegalAccessException | ClassCastException e) { final String message = "could not update change the value of field CurveDB.specCollection."; if (LOG.isWarnEnabled()) { LOG.warn(LogUtil.buildExceptionLogFormat(message), e.getClass().getName(), e.getMessage()); } LOG.debug(message, e); } logAddedCurves(addedCurves); }