Java Code Examples for org.bouncycastle.math.ec.ECCurve#getFieldSize()
The following examples show how to use
org.bouncycastle.math.ec.ECCurve#getFieldSize() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ECPointsCompact.java From InflatableDonkey with MIT License | 6 votes |
@Deprecated public static ECPoint decodeFPPoint(ECCurve curve, byte[] data) { // Patched org.bouncycastle.math.ec.ECCurve#decodePoint code. int expectedLength = (curve.getFieldSize() + 7) / 8; if (expectedLength != data.length) { throw new IllegalArgumentException("incorrect data length for compact encoding"); } BigInteger X = BigIntegers.fromUnsignedByteArray(data, 0, expectedLength); ECPoint p = decompressFPPoint(curve, X); if (!satisfiesCofactor(curve, p)) { throw new IllegalArgumentException("invalid point"); } return p; }
Example 2
Source File: RFC6637.java From InflatableDonkey with MIT License | 5 votes |
ECPoint decodePoint(byte[] data) { ECCurve curve = ECNamedCurveTable.getByName(curveName).getCurve(); int compactExportSize = (curve.getFieldSize() + 7) / 8; return data.length == compactExportSize ? ECPointsCompact.decodeFPPoint(curve, data) // Compact keys support, non RFC6636 compliant. : curve.decodePoint(data); }
Example 3
Source File: BaseCertprofile.java From xipki with Apache License 2.0 | 5 votes |
private static void checkEcSubjectPublicKeyInfo(ASN1ObjectIdentifier curveOid, byte[] encoded) throws BadCertTemplateException { Args.notNull(curveOid, "curveOid"); Args.notNull(encoded, "encoded"); Args.positive(encoded.length, "encoded.length"); Integer expectedLength = ecCurveFieldSizes.get(curveOid); if (expectedLength == null) { X9ECParameters ecP = ECUtil.getNamedCurveByOid(curveOid); ECCurve curve = ecP.getCurve(); expectedLength = (curve.getFieldSize() + 7) / 8; ecCurveFieldSizes.put(curveOid, expectedLength); } switch (encoded[0]) { case 0x02: // compressed case 0x03: // compressed if (encoded.length != (expectedLength + 1)) { throw new BadCertTemplateException("incorrect length for compressed encoding"); } break; case 0x04: // uncompressed case 0x06: // hybrid case 0x07: // hybrid if (encoded.length != (2 * expectedLength + 1)) { throw new BadCertTemplateException("incorrect length for uncompressed/hybrid encoding"); } break; default: throw new BadCertTemplateException( String.format("invalid point encoding 0x%02x", encoded[0])); } }
Example 4
Source File: PublicKeyChecker.java From xipki with Apache License 2.0 | 5 votes |
private static void checkECSubjectPublicKeyInfo(ASN1ObjectIdentifier curveOid, byte[] encoded) throws BadCertTemplateException { Integer expectedLength = EC_CURVEFIELD_SIZES.get(curveOid); if (expectedLength == null) { X9ECParameters ecP = ECUtil.getNamedCurveByOid(curveOid); ECCurve curve = ecP.getCurve(); expectedLength = (curve.getFieldSize() + 7) / 8; EC_CURVEFIELD_SIZES.put(curveOid, expectedLength); } switch (encoded[0]) { case 0x02: // compressed case 0x03: // compressed if (encoded.length != (expectedLength + 1)) { throw new BadCertTemplateException("incorrect length for compressed encoding"); } break; case 0x04: // uncompressed case 0x06: // hybrid case 0x07: // hybrid if (encoded.length != (2 * expectedLength + 1)) { throw new BadCertTemplateException("incorrect length for uncompressed/hybrid encoding"); } break; default: throw new BadCertTemplateException( "invalid point encoding 0x" + Integer.toString(encoded[0], 16)); } // end switch }