/** * 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) { DSAParameters params = key.getParameters(); BigInteger q = params.getQ(); BigInteger m = calculateE(q, message); BigInteger x = ((DSAPrivateKeyParameters)key).getX(); if (kCalculator.isDeterministic()) { kCalculator.init(q, x, message); } else { kCalculator.init(q, random); } BigInteger k = kCalculator.nextK(); // the randomizer is to conceal timing information related to k and x. BigInteger r = params.getG().modPow(k.add(getRandomizer(q, random)), params.getP()).mod(q); k = k.modInverse(q).multiply(m.add(x.multiply(r))); BigInteger s = k.mod(q); return new BigInteger[]{ r, s }; }