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


Java ECPoint.isInfinity方法代码示例

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


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

示例1: calculatePoint

import org.bouncycastle.math.ec.ECPoint; //导入方法依赖的package包/类
public ECPoint calculatePoint(CipherParameters pubKey) {
    ECPublicKeyParameters pub = (ECPublicKeyParameters) pubKey;
    ECPoint P = pub.getQ().multiply(key.getD()).normalize();

    if (P.isInfinity()) {
        throw new IllegalStateException("Infinity is not a valid agreement value for ECDH");
    }
    return P;
}
 
开发者ID:mDL-ILP,项目名称:mDL-ILP,代码行数:10,代码来源:ECKABasicAgreement.java

示例2: verifySignature

import org.bouncycastle.math.ec.ECPoint; //导入方法依赖的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

示例3: calculateMqvAgreement

import org.bouncycastle.math.ec.ECPoint; //导入方法依赖的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);

        // The Q2U public key is optional
        ECPoint q;
        if (Q2U == null)
        {
            q = parameters.getG().multiply(d2U.getD());
        }
        else
        {
            q = Q2U.getQ();
        }

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

        BigInteger xPrime = Q2V.getQ().getX().toBigInteger();
        BigInteger xPrimeBar = xPrime.mod(powE);
        BigInteger Q2VBar = xPrimeBar.setBit(e);

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

//        ECPoint p = Q1V.getQ().multiply(Q2VBar).add(Q2V.getQ()).multiply(hs);
        ECPoint p = ECAlgorithms.sumOfTwoMultiplies(
            Q1V.getQ(), Q2VBar.multiply(hs).mod(n), Q2V.getQ(), hs);

        if (p.isInfinity())
        {
            throw new IllegalStateException("Infinity is not a valid agreement value for MQV");
        }

        return p;
    }
 
开发者ID:Appdome,项目名称:ipack,代码行数:46,代码来源:ECMQVBasicAgreement.java

示例4: verifySignature

import org.bouncycastle.math.ec.ECPoint; //导入方法依赖的package包/类
/**
 * return true if the value r and s represent a DSA signature for
 * the passed in message (for standard DSA the message should be
 * a SHA-1 hash of the real message to be verified).
 */
public boolean verifySignature(
    byte[]      message,
    BigInteger  r,
    BigInteger  s)
{
    BigInteger n = key.getParameters().getN();
    BigInteger e = calculateE(n, message);

    // r in the range [1,n-1]
    if (r.compareTo(ONE) < 0 || r.compareTo(n) >= 0)
    {
        return false;
    }

    // s in the range [1,n-1]
    if (s.compareTo(ONE) < 0 || s.compareTo(n) >= 0)
    {
        return false;
    }

    BigInteger c = s.modInverse(n);

    BigInteger u1 = e.multiply(c).mod(n);
    BigInteger u2 = r.multiply(c).mod(n);

    ECPoint G = key.getParameters().getG();
    ECPoint Q = ((ECPublicKeyParameters)key).getQ();

    ECPoint point = ECAlgorithms.sumOfTwoMultiplies(G, u1, Q, u2);

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

    BigInteger v = point.getX().toBigInteger().mod(n);

    return v.equals(r);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:46,代码来源:ECDSASigner.java

示例5: verifySignature

import org.bouncycastle.math.ec.ECPoint; //导入方法依赖的package包/类
/**
 * return true if the value r and s represent a signature for the 
 * message passed in. Generally, the order of the curve should be at 
 * least as long as the hash of the message of interest, and with 
 * ECNR, it *must* be at least as long.  But just in case the signer
 * applied mod(n) to the longer digest, this implementation will
 * apply mod(n) during verification.
 *
 * @param digest  the digest to be verified.
 * @param r       the r value of the signature.
 * @param s       the s value of the signature.
 * @exception DataLengthException if the digest is longer than the key allows
 */
public boolean verifySignature(
    byte[]      digest,
    BigInteger  r,
    BigInteger  s)
{
    if (this.forSigning) 
    {
        throw new IllegalStateException("not initialised for verifying");
    }

    ECPublicKeyParameters pubKey = (ECPublicKeyParameters)key;
    BigInteger n = pubKey.getParameters().getN();
    int nBitLength = n.bitLength();
    
    BigInteger e = new BigInteger(1, digest);
    int eBitLength = e.bitLength();
    
    if (eBitLength > nBitLength) 
    {
        throw new DataLengthException("input too large for ECNR key.");
    }
    
    // r in the range [1,n-1]
    if (r.compareTo(ECConstants.ONE) < 0 || r.compareTo(n) >= 0) 
    {
        return false;
    }

    // s in the range [0,n-1]           NB: ECNR spec says 0
    if (s.compareTo(ECConstants.ZERO) < 0 || s.compareTo(n) >= 0) 
    {
        return false;
    }

    // compute P = sG + rW

    ECPoint G = pubKey.getParameters().getG();
    ECPoint W = pubKey.getQ();
    // calculate P using Bouncy math
    ECPoint P = ECAlgorithms.sumOfTwoMultiplies(G, s, W, r);

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

    BigInteger x = P.getX().toBigInteger();
    BigInteger t = r.subtract(x).mod(n);

    return t.equals(e);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:66,代码来源:ECNRSigner.java

示例6: verifySignature

import org.bouncycastle.math.ec.ECPoint; //导入方法依赖的package包/类
/**
 * return true if the value r and s represent a GOST3410 signature for
 * the passed in message (for standard GOST3410 the message should be
 * a GOST3411 hash of the real message to be verified).
 */
public boolean verifySignature(
    byte[]      message,
    BigInteger  r,
    BigInteger  s)
{
    byte[] mRev = new byte[message.length]; // conversion is little-endian
    for (int i = 0; i != mRev.length; i++)
    {
        mRev[i] = message[mRev.length - 1 - i];
    }
    
    BigInteger e = new BigInteger(1, mRev);
    BigInteger n = key.getParameters().getN();

    // r in the range [1,n-1]
    if (r.compareTo(ECConstants.ONE) < 0 || r.compareTo(n) >= 0)
    {
        return false;
    }

    // s in the range [1,n-1]
    if (s.compareTo(ECConstants.ONE) < 0 || s.compareTo(n) >= 0)
    {
        return false;
    }

    BigInteger v = e.modInverse(n);

    BigInteger z1 = s.multiply(v).mod(n);
    BigInteger z2 = (n.subtract(r)).multiply(v).mod(n);

    ECPoint G = key.getParameters().getG(); // P
    ECPoint Q = ((ECPublicKeyParameters)key).getQ();

    ECPoint point = ECAlgorithms.sumOfTwoMultiplies(G, z1, Q, z2);

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

    BigInteger R = point.getX().toBigInteger().mod(n);

    return R.equals(r);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:52,代码来源:ECGOST3410Signer.java


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