use of com.github.zhenwei.core.math.ec.ECMultiplier in project LinLong-Java by zhenwei1108.
the class ECDSASigner method generateSignature.
// 5.3 pg 28
/**
* generate a signature for the given message using the key we were initialised with. For
* conventional DSA the message should be a SHA-1 hash of the message of interest.
*
* @param message the message that will be verified later.
*/
public BigInteger[] generateSignature(byte[] message) {
ECDomainParameters ec = key.getParameters();
BigInteger n = ec.getN();
BigInteger e = calculateE(n, message);
BigInteger d = ((ECPrivateKeyParameters) key).getD();
if (kCalculator.isDeterministic()) {
kCalculator.init(n, d, message);
} else {
kCalculator.init(n, random);
}
BigInteger r, s;
ECMultiplier basePointMultiplier = createBasePointMultiplier();
// 5.3.2
do // generate s
{
BigInteger k;
do // generate r
{
k = kCalculator.nextK();
ECPoint p = basePointMultiplier.multiply(ec.getG(), k).normalize();
// 5.3.3
r = p.getAffineXCoord().toBigInteger().mod(n);
} while (r.equals(ZERO));
s = BigIntegers.modOddInverse(n, k).multiply(e.add(d.multiply(r))).mod(n);
} while (s.equals(ZERO));
return new BigInteger[] { r, s };
}
use of com.github.zhenwei.core.math.ec.ECMultiplier in project LinLong-Java by zhenwei1108.
the class ECGOST3410Signer method generateSignature.
/**
* generate a signature for the given message using the key we were initialised with. For
* conventional GOST3410 the message should be a GOST3411 hash of the message of interest.
*
* @param message the message that will be verified later.
*/
public BigInteger[] generateSignature(byte[] message) {
// conversion is little-endian
byte[] mRev = Arrays.reverse(message);
BigInteger e = new BigInteger(1, mRev);
ECDomainParameters ec = key.getParameters();
BigInteger n = ec.getN();
BigInteger d = ((ECPrivateKeyParameters) key).getD();
BigInteger r, s;
ECMultiplier basePointMultiplier = createBasePointMultiplier();
do // generate s
{
BigInteger k;
do // generate r
{
do {
k = BigIntegers.createRandomBigInteger(n.bitLength(), random);
} while (k.equals(ECConstants.ZERO));
ECPoint p = basePointMultiplier.multiply(ec.getG(), k).normalize();
r = p.getAffineXCoord().toBigInteger().mod(n);
} while (r.equals(ECConstants.ZERO));
s = (k.multiply(e)).add(d.multiply(r)).mod(n);
} while (s.equals(ECConstants.ZERO));
return new BigInteger[] { r, s };
}
Aggregations