/** * Returns public key point from the given private key. * * @param privKey the private key to derive the public key from * @return ECPoint public key */ public static ECPoint publicPointFromPrivate(BigInteger privKey) { /* * TODO: FixedPointCombMultiplier currently doesn't support scalars longer than the group * order, but that could change in future versions. */ if (privKey.bitLength() > CURVE.getN().bitLength()) { privKey = privKey.mod(CURVE.getN()); } return new FixedPointCombMultiplier().multiply(CURVE.getG(), privKey); }
/** * Returns public key point from the given private key. */ private static ECPoint publicPointFromPrivate(BigInteger privKey) { /* * TODO: FixedPointCombMultiplier currently doesn't support scalars longer than the group * order, but that could change in future versions. */ if (privKey.bitLength() > CURVE.getN().bitLength()) { privKey = privKey.mod(CURVE.getN()); } return new FixedPointCombMultiplier().multiply(CURVE.getG(), privKey); }
/** * Returns public key point from the given private key. */ private static ECPoint publicPointFromPrivate(BigInteger privKey) { /* * TODO: FixedPointCombMultiplier currently doesn't support scalars longer than the group * order, but that could change in future versions. */ if (privKey.bitLength() > CURVE.getN().bitLength()) { privKey = privKey.mod(CURVE.getN()); } return new FixedPointCombMultiplier().multiply(CURVE.getG(), privKey); }
/** * Returns public key point from the given private key. */ private static ECPoint publicPointFromPrivate(BigInteger privKey) { /* * TODO: FixedPointCombMultiplier currently doesn't support scalars longer than the group * order, but that could change in future versions. */ if (privKey.bitLength() > CURVE.getN().bitLength()) { privKey = privKey.mod(CURVE.getN()); } return new FixedPointCombMultiplier().multiply(CURVE.getG(), privKey); }
/** * Returns public key point from the given private key. */ private static ECPoint publicPointFromPrivate(BigInteger privKey) { /* * TODO: FixedPointCombMultiplier currently doesn't support scalars longer than the group * order, but that could change in future versions. */ if (privKey.bitLength() > CURVE.getN().bitLength()) { privKey = privKey.mod(CURVE.getN()); } return new FixedPointCombMultiplier().multiply(CURVE.getG(), privKey); }
/** * Returns public key point from the given private key. */ private static ECPoint publicPointFromPrivate(BigInteger privKey) { /* * TODO: FixedPointCombMultiplier currently doesn't support scalars longer than the group * order, but that could change in future versions. */ if (privKey.bitLength() > CURVE.getN().bitLength()) { privKey = privKey.mod(CURVE.getN()); } return new FixedPointCombMultiplier().multiply(CURVE.getG(), privKey); }
/** * Returns public key point from the given private key. * * @param privKey the private key to derive the public key from * @return ECPoint public key */ private static ECPoint publicPointFromPrivate(BigInteger privKey) { /* * TODO: FixedPointCombMultiplier currently doesn't support scalars longer than the group * order, but that could change in future versions. */ if (privKey.bitLength() > CURVE.getN().bitLength()) { privKey = privKey.mod(CURVE.getN()); } return new FixedPointCombMultiplier().multiply(CURVE.getG(), privKey); }
/** * Returns public key point from the given private key. * * @param privKey the private key to derive the public key from * @return ECPoint public key */ public static ECPoint publicPointFromPrivate(BigInteger privKey) { /* * TODO: FixedPointCombMultiplier currently doesn't support scalars longer than the group * order, but that could change in future versions. */ if (privKey.bitLength() > CURVE.getN().bitLength()) { privKey = privKey.mod(CURVE.getN()); } return new FixedPointCombMultiplier().multiply(CURVE.getG(), privKey); }
/** * Returns public key point from the given private key. * * @param privKey the private key as BigInteger * @return the ECPoint object representation of the public key based on the given private key */ public static ECPoint publicPointFromPrivateKey(BigInteger privKey) { /* * TODO: FixedPointCombMultiplier currently doesn't support scalars longer than the group * order, but that could change in future versions. */ if (privKey.bitLength() > NeoConstants.CURVE.getN().bitLength()) { privKey = privKey.mod(NeoConstants.CURVE.getN()); } return new FixedPointCombMultiplier().multiply(NeoConstants.CURVE.getG(), privKey).normalize(); }
public static Optional<ECCurvePoint> create(BigInteger d, String curveName) { X9ECParameters x9ECParameters = ECAssistant.x9ECParameters(curveName); ECPoint Q = new FixedPointCombMultiplier().multiply(x9ECParameters.getG(), d).normalize(); ECCurvePoint point = new ECCurvePoint(Q, curveName, x9ECParameters); return Optional.of(point); }
public static PublicKey extractPublicKey(PrivateKey privateKey) { String algorithm = privateKey.getAlgorithm(); try { if (algorithm.equals(RSA.getAlgorithmName())) { KeyFactory keyFactory = KeyFactory.getInstance(RSA.getAlgorithmName(), BouncyCastleProviderHolder.getInstance()); RSAPrivateCrtKey rsaPrivateCrtKey = (RSAPrivateCrtKey) privateKey; RSAPublicKeySpec keySpec = new RSAPublicKeySpec(rsaPrivateCrtKey.getModulus(), rsaPrivateCrtKey.getPublicExponent()); return keyFactory.generatePublic(keySpec); } else if (algorithm.equals(EC.getAlgorithmName())) { KeyFactory keyFactory = KeyFactory.getInstance(EC.getAlgorithmName(), BouncyCastleProviderHolder.getInstance()); BCECPrivateKey ecPrivateKey = (BCECPrivateKey) privateKey; ECParameterSpec ecParameterSpec = ecPrivateKey.getParameters(); ECPoint ecPoint = new FixedPointCombMultiplier().multiply(ecParameterSpec.getG(), ecPrivateKey.getD()); ECPublicKeySpec keySpec = new ECPublicKeySpec(ecPoint, ecParameterSpec); return keyFactory.generatePublic(keySpec); } else { throw new IllegalArgumentException("Unexpected key algorithm: " + algorithm); } } catch (GeneralSecurityException e) { throw new RuntimeException(e); } }
public SM2Signer(CipherParameters param) { if (param instanceof ParametersWithRandom) { ParametersWithRandom rdmParam = (ParametersWithRandom) param; ecKey = (ECKeyParameters)rdmParam.getParameters(); ecParams = ecKey.getParameters(); kCalculator.init(ecParams.getN(), rdmParam.getRandom()); } else { ecKey = (ECKeyParameters) param; ecParams = ecKey.getParameters(); kCalculator.init(ecParams.getN(), new SecureRandom()); } if (!GMUtil.isSm2primev2Curve(ecKey.getParameters().getCurve())) { throw new IllegalArgumentException("Given EC key is not of the curve sm2primev2"); } this.pubPoint = new FixedPointCombMultiplier().multiply(ecParams.getG(), ((ECPrivateKeyParameters)ecKey).getD()).normalize(); this.digest = HashAlgo.SM3.createDigest(); }