protected Key engineDoPhase(Key key, boolean lastPhase) throws InvalidKeyException, IllegalStateException { if (agreement == null) { throw new IllegalStateException(kaAlgorithm + " not initialised."); } if (!lastPhase) { throw new IllegalStateException(kaAlgorithm + " can only be between two parties."); } if (!(key instanceof BCXDHPublicKey)) { throw new InvalidKeyException("cannot identify XDH private key"); } AsymmetricKeyParameter pub = ((BCXDHPublicKey)key).engineGetKeyParameters(); result = new byte[agreement.getAgreementSize()]; if (dhuSpec != null) { agreement.calculateAgreement(new XDHUPublicParameters(pub, ((BCXDHPublicKey)dhuSpec.getOtherPartyEphemeralKey()).engineGetKeyParameters()), result, 0); } else { agreement.calculateAgreement(pub, result, 0); } return null; }