当前位置: 首页>>代码示例>>Java>>正文


Java ECAlgorithms类代码示例

本文整理汇总了Java中org.bouncycastle.math.ec.ECAlgorithms的典型用法代码示例。如果您正苦于以下问题:Java ECAlgorithms类的具体用法?Java ECAlgorithms怎么用?Java ECAlgorithms使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ECAlgorithms类属于org.bouncycastle.math.ec包,在下文中一共展示了ECAlgorithms类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: serializeECPoint

import org.bouncycastle.math.ec.ECAlgorithms; //导入依赖的package包/类
public static byte[] serializeECPoint(short[] ecPointFormats, ECPoint point) throws IOException
{
    ECCurve curve = point.getCurve();

    /*
     * RFC 4492 5.7. ...an elliptic curve point in uncompressed or compressed format. Here, the
     * format MUST conform to what the server has requested through a Supported Point Formats
     * Extension if this extension was used, and MUST be uncompressed if this extension was not
     * used.
     */
    boolean compressed = false;
    if (ECAlgorithms.isFpCurve(curve))
    {
        compressed = isCompressionPreferred(ecPointFormats, ECPointFormat.ansiX962_compressed_prime);
    }
    else if (ECAlgorithms.isF2mCurve(curve))
    {
        compressed = isCompressionPreferred(ecPointFormats, ECPointFormat.ansiX962_compressed_char2);
    }
    return point.getEncoded(compressed);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:22,代码来源:TlsECCUtils.java

示例2: main

import org.bouncycastle.math.ec.ECAlgorithms; //导入依赖的package包/类
public static void main(String[] args)
{
    SortedSet names = new TreeSet(enumToList(ECNamedCurveTable.getNames()));
    names.addAll(enumToList(CustomNamedCurves.getNames()));

    Iterator it = names.iterator();
    while (it.hasNext())
    {
        String name = (String)it.next();
        X9ECParameters x9 = CustomNamedCurves.getByName(name);
        if (x9 == null)
        {
            x9 = ECNamedCurveTable.getByName(name);
        }
        if (x9 != null && ECAlgorithms.isF2mCurve(x9.getCurve()))
        {
            System.out.print(name + ":");
            implPrintNonZeroTraceBits(x9);
        }
    }
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:22,代码来源:TraceOptimizer.java

示例3: discoverEndomorphisms

import org.bouncycastle.math.ec.ECAlgorithms; //导入依赖的package包/类
public static void discoverEndomorphisms(X9ECParameters x9)
{
    if (x9 == null)
    {
        throw new NullPointerException("x9");
    }

    ECCurve c = x9.getCurve();
    if (ECAlgorithms.isFpCurve(c))
    {
        BigInteger characteristic = c.getField().getCharacteristic();

        if (c.getA().isZero() && characteristic.mod(ECConstants.THREE).equals(ECConstants.ONE))
        {
            System.out.println("Curve has a 'GLV Type B' endomorphism with these parameters:");
            printGLVTypeBParameters(x9);
        }
    }
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:20,代码来源:DiscoverEndomorphisms.java

示例4: main

import org.bouncycastle.math.ec.ECAlgorithms; //导入依赖的package包/类
public static void main(String[] args)
{
    SortedSet names = new TreeSet(enumToList(ECNamedCurveTable.getNames()));
    names.addAll(enumToList(CustomNamedCurves.getNames()));

    Iterator it = names.iterator();
    while (it.hasNext())
    {
        String name = (String)it.next();
        X9ECParameters x9 = CustomNamedCurves.getByName(name);
        if (x9 == null)
        {
            x9 = ECNamedCurveTable.getByName(name);
        }
        if (x9 != null && ECAlgorithms.isF2mCurve(x9.getCurve()))
        {
            System.out.print(name + ":");
            implPrintRootZ(x9);
        }
    }
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:22,代码来源:F2mSqrtOptimizer.java

示例5: discoverEndomorphism

import org.bouncycastle.math.ec.ECAlgorithms; //导入依赖的package包/类
private static void discoverEndomorphism(String curveName)
{
    X9ECParameters x9 = ECNamedCurveTable.getByName(curveName);
    if (x9 == null)
    {
        System.err.println("Unknown curve: " + curveName);
        return;
    }

    ECCurve c = x9.getCurve();
    if (ECAlgorithms.isFpCurve(c))
    {
        BigInteger characteristic = c.getField().getCharacteristic();

        if (c.getA().isZero() && characteristic.mod(ECConstants.THREE).equals(ECConstants.ONE))
        {
            System.out.println("Curve '" + curveName + "' has a 'GLV Type B' endomorphism with these parameters: ");
            printGLVTypeBParameters(x9);
        }
    }
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:22,代码来源:DiscoverEndomorphisms.java

示例6: DSTU4145ECBinary

import org.bouncycastle.math.ec.ECAlgorithms; //导入依赖的package包/类
public DSTU4145ECBinary(ECDomainParameters params)
{
    ECCurve curve = params.getCurve();
    if (!ECAlgorithms.isF2mCurve(curve))
    {
        throw new IllegalArgumentException("only binary domain is possible");
    }

    // We always use big-endian in parameter encoding

    PolynomialExtensionField field = (PolynomialExtensionField)curve.getField();
    int[] exponents = field.getMinimalPolynomial().getExponentsPresent();
    if (exponents.length == 3)
    {
        f = new DSTU4145BinaryField(exponents[2], exponents[1]);
    }
    else if (exponents.length == 5)
    {
        f = new DSTU4145BinaryField(exponents[4], exponents[1], exponents[2], exponents[3]);
    }

    a = new ASN1Integer(curve.getA().toBigInteger());
    b = new DEROctetString(curve.getB().getEncoded());
    n = new ASN1Integer(params.getN());
    bp = new DEROctetString(DSTU4145PointEncoder.encodePoint(params.getG()));
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:27,代码来源:DSTU4145ECBinary.java

示例7: hasError

import org.bouncycastle.math.ec.ECAlgorithms; //导入依赖的package包/类
private boolean hasError(ECDSASignature signature) {
    final BigInteger r = signature.r;
    final BigInteger s = signature.s;
    if (!(r.compareTo(BigInteger.ZERO) == 1 && r.compareTo(key.params.getN()) == -1) || !(s.compareTo(BigInteger.ZERO) == 1 && s.compareTo(key.params.getN()) == -1)) {
        //r and s not in range
        return true;
    }
    final BigInteger e = BigIntegerUtil.fromBytes(hashbuf, 16, endian);
    final BigInteger n = key.params.getN();
    final BigInteger sinv = s.modInverse(n);
    final BigInteger u1 = sinv.multiply(e).mod(n);
    final BigInteger u2 = sinv.multiply(r).mod(n);
    final ECPoint g = key.params.getG();
    final ECPoint p = ECAlgorithms.sumOfTwoMultiplies(g, u1, key.curve.getCurve().decodePoint(key.getPublic()), u2).normalize();
    if (p.isInfinity()) {
        //p is infinity
        return true;
    }
    if (p.getAffineXCoord().toBigInteger().mod(n).compareTo(r) != 0) {
        //invalid signature
        return true;
    } else {
        return false;
    }
}
 
开发者ID:bushidowallet,项目名称:bushido-java-core,代码行数:26,代码来源:ECDSA.java

示例8: verifySignature

import org.bouncycastle.math.ec.ECAlgorithms; //导入依赖的package包/类
public boolean verifySignature(byte[] message, BigInteger r, BigInteger s)
{
    if (r.signum() == 0 || s.signum() == 0)
    {
        return false;
    }
    if (r.compareTo(key.getParameters().getN()) >= 0 || s.compareTo(key.getParameters().getN()) >= 0)
    {
        return false;
    }

    ECFieldElement h = hash2FieldElement(key.getParameters().getCurve(), message);
    if (h.toBigInteger().signum() == 0)
    {
        h = key.getParameters().getCurve().fromBigInteger(ONE);
    }

    ECPoint R = ECAlgorithms.sumOfTwoMultiplies(key.getParameters().getG(), s, ((ECPublicKeyParameters)key).getQ(), r);

    // components must be bogus.
    if (R.isInfinity())
    {
        return false;
    }

    ECFieldElement y = h.multiply(R.getX());
    return fieldElement2Integer(key.getParameters().getN(), y).compareTo(r) == 0;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:29,代码来源:DSTU4145Signer.java

示例9: calculateMqvAgreement

import org.bouncycastle.math.ec.ECAlgorithms; //导入依赖的package包/类
private ECPoint calculateMqvAgreement(
    ECDomainParameters      parameters,
    ECPrivateKeyParameters  d1U,
    ECPrivateKeyParameters  d2U,
    ECPublicKeyParameters   Q2U,
    ECPublicKeyParameters   Q1V,
    ECPublicKeyParameters   Q2V)
{
    BigInteger n = parameters.getN();
    int e = (n.bitLength() + 1) / 2;
    BigInteger powE = ECConstants.ONE.shiftLeft(e);

    ECCurve curve = parameters.getCurve();

    ECPoint[] points = new ECPoint[]{
        // The Q2U public key is optional
        ECAlgorithms.importPoint(curve, Q2U == null ? parameters.getG().multiply(d2U.getD()) : Q2U.getQ()),
        ECAlgorithms.importPoint(curve, Q1V.getQ()),
        ECAlgorithms.importPoint(curve, Q2V.getQ())
    };

    curve.normalizeAll(points);

    ECPoint q2u = points[0], q1v = points[1], q2v = points[2];

    BigInteger x = q2u.getAffineXCoord().toBigInteger();
    BigInteger xBar = x.mod(powE);
    BigInteger Q2UBar = xBar.setBit(e);
    BigInteger s = d1U.getD().multiply(Q2UBar).add(d2U.getD()).mod(n);

    BigInteger xPrime = q2v.getAffineXCoord().toBigInteger();
    BigInteger xPrimeBar = xPrime.mod(powE);
    BigInteger Q2VBar = xPrimeBar.setBit(e);

    BigInteger hs = parameters.getH().multiply(s).mod(n);

    return ECAlgorithms.sumOfTwoMultiplies(
        q1v, Q2VBar.multiply(hs).mod(n), q2v, hs);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:40,代码来源:ECMQVBasicAgreement.java

示例10: verifySignature

import org.bouncycastle.math.ec.ECAlgorithms; //导入依赖的package包/类
public boolean verifySignature(byte[] message, BigInteger r, BigInteger s)
{
    if (r.signum() <= 0 || s.signum() <= 0)
    {
        return false;
    }

    ECDomainParameters parameters = key.getParameters();

    BigInteger n = parameters.getN();
    if (r.compareTo(n) >= 0 || s.compareTo(n) >= 0)
    {
        return false;
    }

    ECCurve curve = parameters.getCurve();

    ECFieldElement h = hash2FieldElement(curve, message);
    if (h.isZero())
    {
        h = curve.fromBigInteger(ONE);
    }

    ECPoint R = ECAlgorithms.sumOfTwoMultiplies(parameters.getG(), s, ((ECPublicKeyParameters)key).getQ(), r).normalize();

    // components must be bogus.
    if (R.isInfinity())
    {
        return false;
    }

    ECFieldElement y = h.multiply(R.getAffineXCoord());
    return fieldElement2Integer(n, y).compareTo(r) == 0;
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:35,代码来源:DSTU4145Signer.java

示例11: setFieldIdentifier

import org.bouncycastle.math.ec.ECAlgorithms; //导入依赖的package包/类
private void setFieldIdentifier()
{
    if (ECAlgorithms.isFpCurve(curve))
    {
        fieldIdentifier = prime_field;
    }
    else if (ECAlgorithms.isF2mCurve(curve))
    {
        fieldIdentifier = characteristic_two_field;
    }
    else
    {
        throw new IllegalArgumentException("This type of ECCurve is not implemented");
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:16,代码来源:X9Curve.java

示例12: X9ECParameters

import org.bouncycastle.math.ec.ECAlgorithms; //导入依赖的package包/类
public X9ECParameters(
    ECCurve     curve,
    X9ECPoint   g,
    BigInteger  n,
    BigInteger  h,
    byte[]      seed)
{
    this.curve = curve;
    this.g = g;
    this.n = n;
    this.h = h;
    this.seed = seed;

    if (ECAlgorithms.isFpCurve(curve))
    {
        this.fieldID = new X9FieldID(curve.getField().getCharacteristic());
    }
    else if (ECAlgorithms.isF2mCurve(curve))
    {
        PolynomialExtensionField field = (PolynomialExtensionField)curve.getField();
        int[] exponents = field.getMinimalPolynomial().getExponentsPresent();
        if (exponents.length == 3)
        {
            this.fieldID = new X9FieldID(exponents[2], exponents[1]);
        }
        else if (exponents.length == 5)
        {
            this.fieldID = new X9FieldID(exponents[4], exponents[1], exponents[2], exponents[3]);
        }
        else
        {
            throw new IllegalArgumentException("Only trinomial and pentomial curves are supported");
        }
    }
    else
    {
        throw new IllegalArgumentException("'curve' is of an unsupported type");
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:40,代码来源:X9ECParameters.java

示例13: DSTU4145ECBinary

import org.bouncycastle.math.ec.ECAlgorithms; //导入依赖的package包/类
public DSTU4145ECBinary(ECDomainParameters params)
{
    ECCurve curve = params.getCurve();
    if (!ECAlgorithms.isF2mCurve(curve))
    {
        throw new IllegalArgumentException("only binary domain is possible");
    }

    // We always use big-endian in parameter encoding

    PolynomialExtensionField field = (PolynomialExtensionField)curve.getField();
    int[] exponents = field.getMinimalPolynomial().getExponentsPresent();
    if (exponents.length == 3)
    {
        f = new DSTU4145BinaryField(exponents[2], exponents[1]);
    }
    else if (exponents.length == 5)
    {
        f = new DSTU4145BinaryField(exponents[4], exponents[1], exponents[2], exponents[3]);
    }
    else
    {
        throw new IllegalArgumentException("curve must have a trinomial or pentanomial basis");
    }

    a = new ASN1Integer(curve.getA().toBigInteger());
    b = new DEROctetString(curve.getB().getEncoded());
    n = new ASN1Integer(params.getN());
    bp = new DEROctetString(DSTU4145PointEncoder.encodePoint(params.getG()));
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:31,代码来源:DSTU4145ECBinary.java

示例14: printNonZeroTraceBits

import org.bouncycastle.math.ec.ECAlgorithms; //导入依赖的package包/类
public static void printNonZeroTraceBits(X9ECParameters x9)
{
    if (!ECAlgorithms.isF2mCurve(x9.getCurve()))
    {
        throw new IllegalArgumentException("Trace only defined over characteristic-2 fields");
    }

    implPrintNonZeroTraceBits(x9);
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:10,代码来源:TraceOptimizer.java

示例15: printRootZ

import org.bouncycastle.math.ec.ECAlgorithms; //导入依赖的package包/类
public static void printRootZ(X9ECParameters x9)
{
    if (!ECAlgorithms.isF2mCurve(x9.getCurve()))
    {
        throw new IllegalArgumentException("Sqrt optimization only defined over characteristic-2 fields");
    }

    implPrintRootZ(x9);
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:10,代码来源:F2mSqrtOptimizer.java


注:本文中的org.bouncycastle.math.ec.ECAlgorithms类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。