throw new IllegalStateException
("Key agreement has not been completed yet");
}
if (sharedSecret == null) {
throw new ShortBufferException
("No buffer provided for shared secret");
}
BigInteger modulus = init_p;
byte[] secret = this.y.modPow(this.x, modulus).toByteArray();
// BigInteger.toByteArray will sometimes put a sign byte up front,
// but we NEVER want one.
if ((secret.length << 3) != modulus.bitLength()) {
if ((sharedSecret.length - offset) < (secret.length - 1)) {
throw new ShortBufferException
("Buffer too short for shared secret");
}
System.arraycopy(secret, 1, sharedSecret, offset,
secret.length - 1);
// Reset the key agreement here (not earlier!), so that people
// can recover from ShortBufferException above without losing
// internal state
generateSecret = false;
return secret.length - 1;
} else {
if ((sharedSecret.length - offset) < secret.length) {
throw new ShortBufferException
("Buffer too short to hold shared secret");
}
System.arraycopy(secret, 0, sharedSecret, offset, secret.length);
// Reset the key agreement here (not earlier!), so that people