org.bouncycastle.math.ec.ECPoint.multiply()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(252)

本文整理了Java中org.bouncycastle.math.ec.ECPoint.multiply()方法的一些代码示例,展示了ECPoint.multiply()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ECPoint.multiply()方法的具体详情如下:
包路径:org.bouncycastle.math.ec.ECPoint
类名称:ECPoint
方法名:multiply

ECPoint.multiply介绍

[英]Multiplies this ECPoint by the given number.
[中]将这个ECPoint乘以给定的数字。

代码示例

代码示例来源:origin: web3j/web3j

if (!R.multiply(n).isInfinity()) {
  return null;

代码示例来源:origin: SeanDragon/protools

/**
 * 判断生成的公钥是否合法
 *
 * @param publicKey
 * @return
 */
private boolean checkPublicKey(ECPoint publicKey) {
  if (!publicKey.isInfinity()) {
    BigInteger x = publicKey.getXCoord().toBigInteger();
    BigInteger y = publicKey.getYCoord().toBigInteger();
    if (between(x, new BigInteger("0"), p) && between(y, new BigInteger("0"), p)) {
      BigInteger xResult = x.pow(3).add(a.multiply(x)).add(b).mod(p);
      BigInteger yResult = y.pow(2).mod(p);
      return yResult.equals(xResult) && publicKey.multiply(n).isInfinity();
    }
  }
  return false;
}

代码示例来源:origin: SeanDragon/protools

/**
 * 生成密钥对
 *
 * @return
 */
public SM2KeyPair generateKeyPair() {
  BigInteger d = random(n.subtract(new BigInteger("1")));
  SM2KeyPair keyPair = new SM2KeyPair(G.multiply(d).normalize(), d);
  if (checkPublicKey(keyPair.getPublicKey())) {
    return keyPair;
  } else {
    return null;
  }
}

代码示例来源:origin: SeanDragon/protools

/**
 * 签名
 *
 * @param M       签名信息
 * @param IDA     签名方唯一标识
 * @param keyPair 签名方密钥对
 * @return 签名
 */
public Signature sign(String M, String IDA, SM2KeyPair keyPair) {
  byte[] ZA = ZA(IDA, keyPair.getPublicKey());
  byte[] M_ = join(ZA, M.getBytes());
  BigInteger e = new BigInteger(1, sm3hash(M_));
  // BigInteger k = new BigInteger(
  // "6CB28D99 385C175C 94F94E93 4817663F C176D925 DD72B727 260DBAAE
  // 1FB2F96F".replace(" ", ""), 16);
  BigInteger k;
  BigInteger r;
  do {
    k = random(n);
    ECPoint p1 = G.multiply(k).normalize();
    BigInteger x1 = p1.getXCoord().toBigInteger();
    r = e.add(x1);
    r = r.mod(n);
  } while (r.equals(BigInteger.ZERO) || r.add(k).equals(n));
  BigInteger s = ((keyPair.getPrivateKey().add(BigInteger.ONE).modInverse(n))
      .multiply((k.subtract(r.multiply(keyPair.getPrivateKey()))).mod(n))).mod(n);
  return new Signature(r, s);
}

代码示例来源:origin: SeanDragon/protools

/**
 * 密钥协商发起第一步
 *
 * @return
 */
public TransportEntity keyExchange_1() {
  rA = random(n);
  // rA=new BigInteger("83A2C9C8 B96E5AF7 0BD480B4 72409A9A 327257F1
  // EBB73F5B 073354B2 48668563".replace(" ", ""),16);
  RA = G.multiply(rA).normalize();
  return new TransportEntity(RA.getEncoded(false), null, Z, keyPair.getPublicKey());
}

代码示例来源:origin: SeanDragon/protools

/**
 * 验签
 *
 * @param M          签名信息
 * @param signature  签名
 * @param IDA        签名方唯一标识
 * @param aPublicKey 签名方公钥
 * @return true or false
 */
public boolean verify(String M, Signature signature, String IDA, ECPoint aPublicKey) {
  if (!between(signature.r, BigInteger.ONE, n))
    return false;
  if (!between(signature.s, BigInteger.ONE, n))
    return false;
  byte[] M_ = join(ZA(IDA, aPublicKey), M.getBytes());
  BigInteger e = new BigInteger(1, sm3hash(M_));
  BigInteger t = signature.r.add(signature.s).mod(n);
  if (t.equals(BigInteger.ZERO))
    return false;
  ECPoint p1 = G.multiply(signature.s).normalize();
  ECPoint p2 = aPublicKey.multiply(t).normalize();
  BigInteger x1 = p1.add(p2).normalize().getXCoord().toBigInteger();
  BigInteger R = e.add(x1).mod(n);
  if (R.equals(signature.r))
    return true;
  return false;
}

代码示例来源:origin: SeanDragon/protools

ECPoint C1 = G.multiply(k);
C1Buffer = C1.getEncoded(false);
  ECPoint S = publicKey.multiply(h);
  if (S.isInfinity())
    throw new IllegalStateException();
kpb = publicKey.multiply(k).normalize();

代码示例来源:origin: SeanDragon/protools

ECPoint S = C1.multiply(h);
  if (S.isInfinity())
    throw new IllegalStateException();
ECPoint dBC1 = C1.multiply(privateKey).normalize();

代码示例来源:origin: SeanDragon/protools

ECPoint RB = G.multiply(rB).normalize();
ECPoint temp = aPublicKey.add(RA.multiply(x1).normalize()).normalize();
ECPoint V = temp.multiply(ecc_bc_spec.getH().multiply(tB)).normalize();
if (V.isInfinity())
  throw new IllegalStateException();

代码示例来源:origin: SeanDragon/protools

ECPoint temp = bPublicKey.add(RB.multiply(x2).normalize()).normalize();
ECPoint U = temp.multiply(ecc_bc_spec.getH().multiply(tA)).normalize();
if (U.isInfinity())
  throw new IllegalStateException();

代码示例来源:origin: nuls-io/nuls

public void initDec(BigInteger userD, ECPoint c1) {
  this.p2 = c1.multiply(userD);
  reset();
}

代码示例来源:origin: gotoworld/hsd-cipher-sm

public void Init_dec(BigInteger userD, ECPoint c1)
{
  this.p2 = c1.multiply(userD);
  Reset();
}

代码示例来源:origin: ch.dissem.jabit/jabit-domain

/**
 * @param privateKey private key as byte array
 * @return a public key corresponding to the given private key
 */
public static ECPoint createPublicKey(byte[] privateKey) {
  return EC_CURVE_PARAMETERS.getG().multiply(keyToBigInt(privateKey)).normalize();
}

代码示例来源:origin: horrorho/InflatableDonkey

public byte[] agreement(BigInteger d) {
  // TODO thread safety of ECPoint unclear.
  synchronized (lock) {
    ECPoint P = Q.multiply(d).normalize();
    if (P.isInfinity()) {
      throw new IllegalStateException("invalid EDCH: infinity");
    }
    return P.getAffineXCoord().getEncoded();
  }
}

代码示例来源:origin: RUB-NDS/TLS-Attacker

public static ECPoint createClassicEcPoint(NamedGroup group, BigInteger privateKey) {
  if (!group.isStandardCurve()) {
    throw new IllegalArgumentException(
        "Cannot create ClassicEcPublicKey for group which is not a classic curve:" + group.name());
  }
  ECDomainParameters ecDomainParameters = generateEcParameters(group);
  ECPoint ecPoint = ecDomainParameters.getG().multiply(privateKey);
  ecPoint = ecPoint.normalize();
  return ecPoint;
}

代码示例来源:origin: com.cryptape.cita/crypto

public TransportEntity keyExchange_1() {
  rA = random(n);
  // rA=new BigInteger("83A2C9C8 B96E5AF7 0BD480B4 72409A9A 327257F1
  // EBB73F5B 073354B2 48668563".replace(" ", ""),16);
  ra = G.multiply(rA).normalize();
  return new TransportEntity(ra.getEncoded(false), null, z, keyPair.getPublicKey());
}

代码示例来源:origin: PopezLotado/SM2Java

/**
 * 密钥协商发起第一步
 * 
 * @return
 */
public TransportEntity keyExchange_1() {
  rA = random(n);
  // rA=new BigInteger("83A2C9C8 B96E5AF7 0BD480B4 72409A9A 327257F1
  // EBB73F5B 073354B2 48668563".replace(" ", ""),16);
  RA = G.multiply(rA).normalize();
  return new TransportEntity(RA.getEncoded(false), null,Z,keyPair.getPublicKey());
}

代码示例来源:origin: nuls-io/nuls

public ECPoint initEnc(SM2 sm2, ECPoint userKey) {
  AsymmetricCipherKeyPair key = sm2.ecc_key_pair_generator.generateKeyPair();
  ECPrivateKeyParameters ecpriv = (ECPrivateKeyParameters) key.getPrivate();
  ECPublicKeyParameters ecpub = (ECPublicKeyParameters) key.getPublic();
  BigInteger k = ecpriv.getD();
  ECPoint c1 = ecpub.getQ();
  this.p2 = userKey.multiply(k);
  reset();
  return c1;
}

代码示例来源:origin: NemProject/nem.core

@Override
  public PublicKey derivePublicKey(final PrivateKey privateKey) {
    final ECPoint point = SecP256K1Curve.secp256k1().getParams().getG().multiply(privateKey.getRaw());
    return new PublicKey(point.getEncoded(true));
  }
}

代码示例来源:origin: gotoworld/hsd-cipher-sm

public ECPoint Init_enc(SM2 sm2, ECPoint userKey)
{
  AsymmetricCipherKeyPair key = sm2.ecc_key_pair_generator.generateKeyPair();
  ECPrivateKeyParameters ecpriv = (ECPrivateKeyParameters) key.getPrivate();
  ECPublicKeyParameters ecpub = (ECPublicKeyParameters) key.getPublic();
  BigInteger k = ecpriv.getD();
  ECPoint c1 = ecpub.getQ();
  this.p2 = userKey.multiply(k);
  Reset();
  return c1;
}

相关文章