public void calculateAgreement(CipherParameters publicKey, byte[] buf, int off) { XDHUPublicParameters pubParams = (XDHUPublicParameters)publicKey; xAgreement.init(privParams.getEphemeralPrivateKey()); xAgreement.calculateAgreement(pubParams.getEphemeralPublicKey(), buf, off); xAgreement.init(privParams.getStaticPrivateKey()); xAgreement.calculateAgreement(pubParams.getStaticPublicKey(), buf, off + xAgreement.getAgreementSize()); } }
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; }