本文整理汇总了Java中java.security.spec.EllipticCurve.getField方法的典型用法代码示例。如果您正苦于以下问题:Java EllipticCurve.getField方法的具体用法?Java EllipticCurve.getField怎么用?Java EllipticCurve.getField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.security.spec.EllipticCurve
的用法示例。
在下文中一共展示了EllipticCurve.getField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertCurve
import java.security.spec.EllipticCurve; //导入方法依赖的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!!!");
}
}
示例2: convertCurve
import java.security.spec.EllipticCurve; //导入方法依赖的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);
}
}
示例3: mapNonceGMWithECDH
import java.security.spec.EllipticCurve; //导入方法依赖的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);
}
示例4: mapNonceGMWithECDH
import java.security.spec.EllipticCurve; //导入方法依赖的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);
}
示例5: getPoint
import java.security.spec.EllipticCurve; //导入方法依赖的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);
}
示例6: getWeakPublicKey
import java.security.spec.EllipticCurve; //导入方法依赖的package包/类
/**
* Returns a weak public key of order 3 such that the public key point is on the curve specified
* in ecParams. This method is used to check ECC implementations for missing step in the
* verification of the public key. E.g. implementations of ECDH must verify that the public key
* contains a point on the curve as well as public and secret key are using the same curve.
*
* @param ecParams the parameters of the key to attack. This must be a curve in Weierstrass form
* over a prime order field.
* @return a weak EC group with a genrator of order 3.
*/
public static ECPublicKeySpec getWeakPublicKey(ECParameterSpec ecParams)
throws GeneralSecurityException {
EllipticCurve curve = ecParams.getCurve();
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("EC");
keyGen.initialize(ecParams);
BigInteger p = getModulus(curve);
BigInteger three = new BigInteger("3");
while (true) {
// Generate a point on the original curve
KeyPair keyPair = keyGen.generateKeyPair();
ECPublicKey pub = (ECPublicKey) keyPair.getPublic();
ECPoint w = pub.getW();
BigInteger x = w.getAffineX();
BigInteger y = w.getAffineY();
// Find the curve parameters a,b such that 3*w = infinity.
// This is the case if the following equations are satisfied:
// 3x == l^2 (mod p)
// l == (3x^2 + a) / 2*y (mod p)
// y^2 == x^3 + ax + b (mod p)
BigInteger l;
try {
l = modSqrt(x.multiply(three), p);
} catch (GeneralSecurityException ex) {
continue;
}
BigInteger xSqr = x.multiply(x).mod(p);
BigInteger a = l.multiply(y.add(y)).subtract(xSqr.multiply(three)).mod(p);
BigInteger b = y.multiply(y).subtract(x.multiply(xSqr.add(a))).mod(p);
EllipticCurve newCurve = new EllipticCurve(curve.getField(), a, b);
// Just a sanity check.
checkPointOnCurve(w, newCurve);
// Cofactor and order are of course wrong.
ECParameterSpec spec = new ECParameterSpec(newCurve, w, p, 1);
return new ECPublicKeySpec(w, spec);
}
}
示例7: convertCurve
import java.security.spec.EllipticCurve; //导入方法依赖的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!!!");
}
}
示例8: convertCurve
import java.security.spec.EllipticCurve; //导入方法依赖的package包/类
public static ECCurve convertCurve(
EllipticCurve ec)
{
ECField field = ec.getField();
BigInteger a = ec.getA();
BigInteger b = ec.getB();
if (field instanceof ECFieldFp)
{
ECCurve.Fp curve = new ECCurve.Fp(((ECFieldFp)field).getP(), a, b);
if (customCurves.containsKey(curve))
{
return (ECCurve)customCurves.get(curve);
}
return curve;
}
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);
}
}
示例9: decodePoint
import java.security.spec.EllipticCurve; //导入方法依赖的package包/类
/**
* Decode a point on this curve which has been encoded using point
* compression (X9.62 s 4.2.1 and 4.2.2) or regular encoding.
*
* @param curve
* The elliptic curve.
* @param encoded
* The encoded point.
* @return the decoded point.
*/
public static ECPoint decodePoint(
EllipticCurve curve,
byte[] encoded)
{
ECCurve c = null;
if (curve.getField() instanceof ECFieldFp)
{
c = new ECCurve.Fp(
((ECFieldFp)curve.getField()).getP(), curve.getA(), curve.getB());
}
else
{
int k[] = ((ECFieldF2m)curve.getField()).getMidTermsOfReductionPolynomial();
if (k.length == 3)
{
c = new ECCurve.F2m(
((ECFieldF2m)curve.getField()).getM(), k[2], k[1], k[0], curve.getA(), curve.getB());
}
else
{
c = new ECCurve.F2m(
((ECFieldF2m)curve.getField()).getM(), k[0], curve.getA(), curve.getB());
}
}
org.bouncycastle.math.ec.ECPoint p = c.decodePoint(encoded);
return new ECPoint(p.getX().toBigInteger(), p.getY().toBigInteger());
}
示例10: toBouncyCastleECCurve
import java.security.spec.EllipticCurve; //导入方法依赖的package包/类
private static ECCurve toBouncyCastleECCurve(final ECParameterSpec params) {
final EllipticCurve curve = params.getCurve();
final ECField field = curve.getField();
if (!(field instanceof ECFieldFp)) {
throw new IllegalArgumentException(
"Solo se soporta 'ECFieldFp' y se proporciono " + field.getClass().getCanonicalName() //$NON-NLS-1$
);
}
final int coFactor = params.getCofactor();
final BigInteger order = params.getOrder();
final BigInteger a = curve.getA();
final BigInteger b = curve.getB();
final BigInteger p = getPrime(params);
return new ECCurve.Fp(p, a, b, order, BigInteger.valueOf(coFactor));
}
示例11: getPrime
import java.security.spec.EllipticCurve; //导入方法依赖的package包/类
private static BigInteger getPrime(final ECParameterSpec params) {
if (params == null) {
throw new IllegalArgumentException(
"Los parametros no pueden ser nulos" //$NON-NLS-1$
);
}
final EllipticCurve curve = params.getCurve();
final ECField field = curve.getField();
if (!(field instanceof ECFieldFp)) {
throw new IllegalStateException(
"Solo se soporta 'ECFieldFp' y se proporciono " + field.getClass().getCanonicalName() //$NON-NLS-1$
);
}
return ((ECFieldFp)field).getP();
}
示例12: toSpongyCastleECCurve
import java.security.spec.EllipticCurve; //导入方法依赖的package包/类
private static ECCurve toSpongyCastleECCurve(final ECParameterSpec params) {
final EllipticCurve curve = params.getCurve();
final ECField field = curve.getField();
if (!(field instanceof ECFieldFp)) {
throw new IllegalArgumentException(
"Solo se soporta 'ECFieldFp' y se proporciono " + field.getClass().getCanonicalName() //$NON-NLS-1$
);
}
final int coFactor = params.getCofactor();
final BigInteger order = params.getOrder();
final BigInteger a = curve.getA();
final BigInteger b = curve.getB();
final BigInteger p = getPrime(params);
return new ECCurve.Fp(p, a, b, order, BigInteger.valueOf(coFactor));
}
示例13: getModulus
import java.security.spec.EllipticCurve; //导入方法依赖的package包/类
/**
* Returns the modulus of the field used by the curve specified in ecParams.
*
* @param curve must be a prime order elliptic curve
* @return the order of the finite field over which curve is defined.
*/
public static BigInteger getModulus(EllipticCurve curve) throws GeneralSecurityException {
java.security.spec.ECField field = curve.getField();
if (field instanceof java.security.spec.ECFieldFp) {
return ((java.security.spec.ECFieldFp) field).getP();
} else {
throw new GeneralSecurityException("Only curves over prime order fields are supported");
}
}
示例14: decompressPoint
import java.security.spec.EllipticCurve; //导入方法依赖的package包/类
/**
* Decompress a point on an elliptic curve.
*
* @param bytes The compressed point. Its representation is z || x where z is 2+lsb(y) and x is
* using a unsigned fixed length big-endian representation.
* @param ecParams the specification of the curve. Only Weierstrass curves over prime order fields
* are implemented.
*/
public static ECPoint decompressPoint(byte[] bytes, 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();
int expectedLength = 1 + (p.bitLength() + 7) / 8;
if (bytes.length != expectedLength) {
throw new GeneralSecurityException("compressed point has wrong length");
}
boolean lsb;
switch (bytes[0]) {
case 2:
lsb = false;
break;
case 3:
lsb = true;
break;
default:
throw new GeneralSecurityException("Invalid format");
}
BigInteger x = new BigInteger(1, Arrays.copyOfRange(bytes, 1, bytes.length));
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 (lsb != y.testBit(0)) {
y = p.subtract(y).mod(p);
}
return new ECPoint(x, y);
}
示例15: decodePoint
import java.security.spec.EllipticCurve; //导入方法依赖的package包/类
/**
* Decode a point on this curve which has been encoded using point
* compression (X9.62 s 4.2.1 and 4.2.2) or regular encoding.
*
* @param curve
* The elliptic curve.
* @param encoded
* The encoded point.
* @return the decoded point.
*/
public static ECPoint decodePoint(
EllipticCurve curve,
byte[] encoded)
{
ECCurve c = null;
if (curve.getField() instanceof ECFieldFp)
{
c = new ECCurve.Fp(
((ECFieldFp)curve.getField()).getP(), curve.getA(), curve.getB());
}
else
{
int k[] = ((ECFieldF2m)curve.getField()).getMidTermsOfReductionPolynomial();
if (k.length == 3)
{
c = new ECCurve.F2m(
((ECFieldF2m)curve.getField()).getM(), k[2], k[1], k[0], curve.getA(), curve.getB());
}
else
{
c = new ECCurve.F2m(
((ECFieldF2m)curve.getField()).getM(), k[0], curve.getA(), curve.getB());
}
}
org.bouncycastle.math.ec.ECPoint p = c.decodePoint(encoded);
return new ECPoint(p.getAffineXCoord().toBigInteger(), p.getAffineYCoord().toBigInteger());
}