本文整理汇总了Java中java.security.spec.ECFieldFp类的典型用法代码示例。如果您正苦于以下问题:Java ECFieldFp类的具体用法?Java ECFieldFp怎么用?Java ECFieldFp使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ECFieldFp类属于java.security.spec包,在下文中一共展示了ECFieldFp类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decodeTest
import java.security.spec.ECFieldFp; //导入依赖的package包/类
private void decodeTest()
{
EllipticCurve curve = new EllipticCurve(
new ECFieldFp(new BigInteger("6277101735386680763835789423207666416083908700390324961279")), // q
new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), // a
new BigInteger("64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1", 16)); // b
ECPoint p = ECPointUtil.decodePoint(curve, Hex.decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012"));
if (!p.getAffineX().equals(new BigInteger("188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012", 16)))
{
fail("x uncompressed incorrectly");
}
if (!p.getAffineY().equals(new BigInteger("7192b95ffc8da78631011ed6b24cdd573f977a11e794811", 16)))
{
fail("y uncompressed incorrectly");
}
}
示例2: encodeECParameterSpec
import java.security.spec.ECFieldFp; //导入依赖的package包/类
public static ECParameterSpec encodeECParameterSpec(EllipticCurveParameters params) {
// Field
final BigInteger pInt = new BigInteger(1, params.getP());
final ECField field = new ECFieldFp(pInt);
final BigInteger aInt = new BigInteger(1, params.getA());
final BigInteger bInt = new BigInteger(1, params.getB());
final EllipticCurve curve = new EllipticCurve(field, aInt, bInt);
// Fixed Point G
final BigInteger xInt = new BigInteger(1, params.getX());
final BigInteger yInt = new BigInteger(1, params.getY());
final ECPoint g = new ECPoint(xInt, yInt);
// Order N
final BigInteger nInt = new BigInteger(1, params.getN());
return new ECParameterSpec(curve, g, nInt, params.getH());
}
示例3: addPointsA
import java.security.spec.ECFieldFp; //导入依赖的package包/类
private static BigInteger[] addPointsA(BigInteger[] P1, BigInteger[] P2,
ECParameterSpec params) {
final BigInteger p = ((ECFieldFp) params.getCurve().getField()).getP();
if (P2[0] == null || P2[1] == null) return P1;
if (P1[0] == null || P1[1] == null) return P2;
BigInteger d = (P2[1].subtract(P1[1])).multiply((P2[0].subtract(P1[0]))
.modInverse(p));
BigInteger[] R = new BigInteger[2];
R[0] = d.pow(2).subtract(P1[0]).subtract(P2[0]).mod(p);
R[1] = d.multiply(P1[0].subtract(R[0])).subtract(P1[1]).mod(p);
return R;
}
示例4: convertCurve
import java.security.spec.ECFieldFp; //导入依赖的package包/类
private static ECCurve convertCurve(
EllipticCurve ec)
{
ECField field = ec.getField();
BigInteger a = ec.getA();
BigInteger b = ec.getB();
if (field instanceof ECFieldFp)
{
return new ECCurve.Fp(((ECFieldFp)field).getP(), a, b);
}
else
{
throw new IllegalStateException("not implemented yet!!!");
}
}
示例5: convertCurve
import java.security.spec.ECFieldFp; //导入依赖的package包/类
public static ECCurve convertCurve(
EllipticCurve ec)
{
ECField field = ec.getField();
BigInteger a = ec.getA();
BigInteger b = ec.getB();
if (field instanceof ECFieldFp)
{
return new ECCurve.Fp(((ECFieldFp)field).getP(), a, b);
}
else
{
ECFieldF2m fieldF2m = (ECFieldF2m)field;
int m = fieldF2m.getM();
int ks[] = ECUtil.convertMidTerms(fieldF2m.getMidTermsOfReductionPolynomial());
return new ECCurve.F2m(m, ks[0], ks[1], ks[2], a, b);
}
}
示例6: getCurveName
import java.security.spec.ECFieldFp; //导入依赖的package包/类
public static String getCurveName(ECParameterSpec spec)
throws InvalidAlgorithmParameterException
{
int curve_id;
/* Ecc object doesn't need to be initialied before call */
if (!(spec.getCurve().getField() instanceof ECFieldFp)) {
throw new InvalidAlgorithmParameterException(
"Currently only ECFieldFp fields supported");
}
ECFieldFp field = (ECFieldFp)spec.getCurve().getField();
EllipticCurve curve = spec.getCurve();
curve_id = wc_ecc_get_curve_id_from_params(
field.getFieldSize(),
field.getP().toByteArray(),
curve.getA().toByteArray(),
curve.getB().toByteArray(),
spec.getOrder().toByteArray(),
spec.getGenerator().getAffineX().toByteArray(),
spec.getGenerator().getAffineY().toByteArray(),
spec.getCofactor());
return wc_ecc_get_curve_name_from_id(curve_id);
}
示例7: mapNonceGMWithECDH
import java.security.spec.ECFieldFp; //导入依赖的package包/类
private static ECParameterSpec mapNonceGMWithECDH(final BigInteger nonceS,
final ECPoint sharedSecretPointH,
final ECParameterSpec params) {
// D~ = (p, a, b, G~, n, h) where G~ = [s]G + H
final ECPoint generator = params.getGenerator();
final EllipticCurve curve = params.getCurve();
final BigInteger a = curve.getA();
final BigInteger b = curve.getB();
final ECFieldFp field = (ECFieldFp)curve.getField();
final BigInteger p = field.getP();
final BigInteger order = params.getOrder();
final int cofactor = params.getCofactor();
final ECPoint ephemeralGenerator = add(multiply(nonceS, generator, params), sharedSecretPointH, params);
if (!toBouncyCastleECPoint(ephemeralGenerator, params).isValid()) {
LOGGER.warning("Se ha generado un punto invalido"); //$NON-NLS-1$
}
return new ECParameterSpec(new EllipticCurve(new ECFieldFp(p), a, b), ephemeralGenerator, order, cofactor);
}
示例8: mapNonceGMWithECDH
import java.security.spec.ECFieldFp; //导入依赖的package包/类
private static ECParameterSpec mapNonceGMWithECDH(final BigInteger nonceS,
final ECPoint sharedSecretPointH,
final ECParameterSpec params) {
// D~ = (p, a, b, G~, n, h) where G~ = [s]G + H
final ECPoint generator = params.getGenerator();
final EllipticCurve curve = params.getCurve();
final BigInteger a = curve.getA();
final BigInteger b = curve.getB();
final ECFieldFp field = (ECFieldFp)curve.getField();
final BigInteger p = field.getP();
final BigInteger order = params.getOrder();
final int cofactor = params.getCofactor();
final ECPoint ephemeralGenerator = add(multiply(nonceS, generator, params), sharedSecretPointH, params);
if (!toSpongyCastleECPoint(ephemeralGenerator, params).isValid()) {
LOGGER.warning("Se ha generado un punto invalido"); //$NON-NLS-1$
}
return new ECParameterSpec(new EllipticCurve(new ECFieldFp(p), a, b), ephemeralGenerator, order, cofactor);
}
示例9: CfcaCurve
import java.security.spec.ECFieldFp; //导入依赖的package包/类
public static ECParameterSpec CfcaCurve() {
// 素数P
BigInteger p = new BigInteger("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF", 16);
// 基于素数P的有限域
ECFieldFp gfp = new ECFieldFp(p);
// 在有限域上的椭圆曲线y2 = x3 + ax + b
EllipticCurve ellipticCurve = new EllipticCurve(gfp,
new BigInteger("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC", 16),
new BigInteger("28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93", 16));
// 基点G
ECPoint G = new ECPoint(new BigInteger("32C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7", 16),
new BigInteger("BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0", 16));
// G的阶
BigInteger n = new BigInteger("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123", 16);
// 设置基点
ECParameterSpec ecParameterSpec = new ECParameterSpec(ellipticCurve, G, n, 1);
return ecParameterSpec;
}
示例10: getECParameterSpec
import java.security.spec.ECFieldFp; //导入依赖的package包/类
ECParameterSpec getECParameterSpec() {
final String curveName = NativeCrypto.EC_GROUP_get_curve_name(groupCtx);
final byte[][] curveParams = NativeCrypto.EC_GROUP_get_curve(groupCtx);
final BigInteger p = new BigInteger(curveParams[0]);
final BigInteger a = new BigInteger(curveParams[1]);
final BigInteger b = new BigInteger(curveParams[2]);
final ECField field = new ECFieldFp(p);
final EllipticCurve curve = new EllipticCurve(field, a, b);
final OpenSSLECPointContext generatorCtx = new OpenSSLECPointContext(this,
new NativeRef.EC_POINT(NativeCrypto.EC_GROUP_get_generator(groupCtx)));
final ECPoint generator = generatorCtx.getECPoint();
final BigInteger order = new BigInteger(NativeCrypto.EC_GROUP_get_order(groupCtx));
final BigInteger cofactor = new BigInteger(NativeCrypto.EC_GROUP_get_cofactor(groupCtx));
ECParameterSpec spec = new ECParameterSpec(curve, generator, order, cofactor.intValue());
Platform.setCurveName(spec, curveName);
return spec;
}
示例11: getSpec
import java.security.spec.ECFieldFp; //导入依赖的package包/类
/**
* Returns this key as ECPublicKeySpec or null if the key cannot be represented as
* ECPublicKeySpec. The later happens for example if the order of cofactor are not positive.
*/
public ECPublicKeySpec getSpec() {
try {
ECFieldFp fp = new ECFieldFp(p);
EllipticCurve curve = new EllipticCurve(fp, a, b);
ECPoint g = new ECPoint(gx, gy);
// ECParameterSpec requires that the cofactor h is specified.
if (h == null) {
return null;
}
ECParameterSpec params = new ECParameterSpec(curve, g, n, h);
ECPoint pubPoint = new ECPoint(pubx, puby);
ECPublicKeySpec pub = new ECPublicKeySpec(pubPoint, params);
return pub;
} catch (Exception ex) {
System.out.println(comment + " throws " + ex.toString());
return null;
}
}
示例12: getNistCurveSpec
import java.security.spec.ECFieldFp; //导入依赖的package包/类
public static ECParameterSpec getNistCurveSpec(
String decimalP, String decimalN, String hexB, String hexGX, String hexGY) {
final BigInteger p = new BigInteger(decimalP);
final BigInteger n = new BigInteger(decimalN);
final BigInteger three = new BigInteger("3");
final BigInteger a = p.subtract(three);
final BigInteger b = new BigInteger(hexB, 16);
final BigInteger gx = new BigInteger(hexGX, 16);
final BigInteger gy = new BigInteger(hexGY, 16);
final int h = 1;
ECFieldFp fp = new ECFieldFp(p);
java.security.spec.EllipticCurve curveSpec = new java.security.spec.EllipticCurve(fp, a, b);
ECPoint g = new ECPoint(gx, gy);
ECParameterSpec ecSpec = new ECParameterSpec(curveSpec, g, n, h);
return ecSpec;
}
示例13: getBrainpoolP256r1Params
import java.security.spec.ECFieldFp; //导入依赖的package包/类
public static ECParameterSpec getBrainpoolP256r1Params() {
BigInteger p =
new BigInteger("A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377", 16);
BigInteger a =
new BigInteger("7D5A0975FC2C3057EEF67530417AFFE7FB8055C126DC5C6CE94A4B44F330B5D9", 16);
BigInteger b =
new BigInteger("26DC5C6CE94A4B44F330B5D9BBD77CBF958416295CF7E1CE6BCCDC18FF8C07B6", 16);
BigInteger x =
new BigInteger("8BD2AEB9CB7E57CB2C4B482FFC81B7AFB9DE27E1E3BD23C23A4453BD9ACE3262", 16);
BigInteger y =
new BigInteger("547EF835C3DAC4FD97F8461A14611DC9C27745132DED8E545C1D54C72F046997", 16);
BigInteger n =
new BigInteger("A9FB57DBA1EEA9BC3E660A909D838D718C397AA3B561A6F7901E0E82974856A7", 16);
final int h = 1;
ECFieldFp fp = new ECFieldFp(p);
EllipticCurve curve = new EllipticCurve(fp, a, b);
ECPoint g = new ECPoint(x, y);
return new ECParameterSpec(curve, g, n, h);
}
示例14: getPoint
import java.security.spec.ECFieldFp; //导入依赖的package包/类
/**
* Decompress a point
*
* @param x The x-coordinate of the point
* @param bit0 true if the least significant bit of y is set.
* @param ecParams contains the curve of the point. This must be over a prime order field.
*/
public static ECPoint getPoint(BigInteger x, boolean bit0, ECParameterSpec ecParams)
throws GeneralSecurityException {
EllipticCurve ec = ecParams.getCurve();
ECField field = ec.getField();
if (!(field instanceof ECFieldFp)) {
throw new GeneralSecurityException("Only curves over prime order fields are supported");
}
BigInteger p = ((java.security.spec.ECFieldFp) field).getP();
if (x.compareTo(BigInteger.ZERO) == -1 || x.compareTo(p) != -1) {
throw new GeneralSecurityException("x is out of range");
}
// Compute rhs == x^3 + a x + b (mod p)
BigInteger rhs = x.multiply(x).add(ec.getA()).multiply(x).add(ec.getB()).mod(p);
BigInteger y = modSqrt(rhs, p);
if (bit0 != y.testBit(0)) {
y = p.subtract(y).mod(p);
}
return new ECPoint(x, y);
}
示例15: convertCurve
import java.security.spec.ECFieldFp; //导入依赖的package包/类
private static ECCurve convertCurve(
EllipticCurve ec, BigInteger order, int coFactor)
{
ECField field = ec.getField();
BigInteger a = ec.getA();
BigInteger b = ec.getB();
if (field instanceof ECFieldFp)
{
return new ECCurve.Fp(((ECFieldFp)field).getP(), a, b, order, BigInteger.valueOf(coFactor));
}
else
{
throw new IllegalStateException("not implemented yet!!!");
}
}