use of com.github.zhenwei.core.crypto.params.ECDomainParameters in project LinLong-Java by zhenwei1108.
the class ECElGamalEncryptor method encrypt.
/**
* Process a single EC point using the basic ElGamal algorithm.
*
* @param point the EC point to process.
* @return the result of the Elgamal process.
*/
public ECPair encrypt(ECPoint point) {
if (key == null) {
throw new IllegalStateException("ECElGamalEncryptor not initialised");
}
ECDomainParameters ec = key.getParameters();
BigInteger k = ECUtil.generateK(ec.getN(), random);
ECMultiplier basePointMultiplier = createBasePointMultiplier();
ECPoint[] gamma_phi = new ECPoint[] { basePointMultiplier.multiply(ec.getG(), k), key.getQ().multiply(k).add(ECAlgorithms.cleanPoint(ec.getCurve(), point)) };
ec.getCurve().normalizeAll(gamma_phi);
return new ECPair(gamma_phi[0], gamma_phi[1]);
}
use of com.github.zhenwei.core.crypto.params.ECDomainParameters in project LinLong-Java by zhenwei1108.
the class ECNewPublicKeyTransform method transform.
/**
* Transform an existing cipher text pair using the ElGamal algorithm. Note: the input cipherText
* will need to be preserved in order to complete the transformation to the new public key.
*
* @param cipherText the EC point to process.
* @return returns a new ECPair representing the result of the process.
*/
public ECPair transform(ECPair cipherText) {
if (key == null) {
throw new IllegalStateException("ECNewPublicKeyTransform not initialised");
}
ECDomainParameters ec = key.getParameters();
BigInteger n = ec.getN();
ECMultiplier basePointMultiplier = createBasePointMultiplier();
BigInteger k = ECUtil.generateK(n, random);
ECPoint[] gamma_phi = new ECPoint[] { basePointMultiplier.multiply(ec.getG(), k), key.getQ().multiply(k).add(ECAlgorithms.cleanPoint(ec.getCurve(), cipherText.getY())) };
ec.getCurve().normalizeAll(gamma_phi);
return new ECPair(gamma_phi[0], gamma_phi[1]);
}
use of com.github.zhenwei.core.crypto.params.ECDomainParameters in project LinLong-Java by zhenwei1108.
the class ECVKOAgreement method calculateAgreement.
public byte[] calculateAgreement(CipherParameters pubKey) {
ECPublicKeyParameters pub = (ECPublicKeyParameters) pubKey;
ECDomainParameters params = key.getParameters();
if (!params.equals(pub.getParameters())) {
throw new IllegalStateException("ECVKO public key has wrong domain parameters");
}
BigInteger hd = params.getH().multiply(ukm).multiply(key.getD()).mod(params.getN());
// Always perform calculations on the exact curve specified by our private key's parameters
ECPoint pubPoint = ECAlgorithms.cleanPoint(params.getCurve(), pub.getQ());
if (pubPoint.isInfinity()) {
throw new IllegalStateException("Infinity is not a valid public key for ECDHC");
}
ECPoint P = pubPoint.multiply(hd).normalize();
if (P.isInfinity()) {
throw new IllegalStateException("Infinity is not a valid agreement value for ECVKO");
}
return fromPoint(P);
}
use of com.github.zhenwei.core.crypto.params.ECDomainParameters in project LinLong-Java by zhenwei1108.
the class ECMQVBasicAgreement method calculateAgreement.
public BigInteger calculateAgreement(CipherParameters pubKey) {
if (Properties.isOverrideSet("org.bouncycastle.ec.disable_mqv")) {
throw new IllegalStateException("ECMQV explicitly disabled");
}
MQVPublicParameters pubParams = (MQVPublicParameters) pubKey;
ECPrivateKeyParameters staticPrivateKey = privParams.getStaticPrivateKey();
ECDomainParameters parameters = staticPrivateKey.getParameters();
if (!parameters.equals(pubParams.getStaticPublicKey().getParameters())) {
throw new IllegalStateException("ECMQV public key components have wrong domain parameters");
}
ECPoint agreement = calculateMqvAgreement(parameters, staticPrivateKey, privParams.getEphemeralPrivateKey(), privParams.getEphemeralPublicKey(), pubParams.getStaticPublicKey(), pubParams.getEphemeralPublicKey()).normalize();
if (agreement.isInfinity()) {
throw new IllegalStateException("Infinity is not a valid agreement value for MQV");
}
return agreement.getAffineXCoord().toBigInteger();
}
use of com.github.zhenwei.core.crypto.params.ECDomainParameters in project LinLong-Java by zhenwei1108.
the class DSTU4145Signer method generateSignature.
public BigInteger[] generateSignature(byte[] message) {
ECDomainParameters ec = key.getParameters();
ECCurve curve = ec.getCurve();
ECFieldElement h = hash2FieldElement(curve, message);
if (h.isZero()) {
h = curve.fromBigInteger(ONE);
}
BigInteger n = ec.getN();
BigInteger e, r, s;
ECFieldElement Fe, y;
BigInteger d = ((ECPrivateKeyParameters) key).getD();
ECMultiplier basePointMultiplier = createBasePointMultiplier();
do {
do {
do {
e = generateRandomInteger(n, random);
Fe = basePointMultiplier.multiply(ec.getG(), e).normalize().getAffineXCoord();
} while (Fe.isZero());
y = h.multiply(Fe);
r = fieldElement2Integer(n, y);
} while (r.signum() == 0);
s = r.multiply(d).add(e).mod(n);
} while (s.signum() == 0);
return new BigInteger[] { r, s };
}
Aggregations