HpkeKemEncapOutput authEncapsulate(
      byte[] recipientPublicKey,
      byte[] senderEphemeralPrivateKey,
      HpkeKemPrivateKey senderPrivateKey)
      throws GeneralSecurityException {
    byte[] dhSharedSecret =
        Bytes.concat(
            X25519.computeSharedSecret(senderEphemeralPrivateKey, recipientPublicKey),
            X25519.computeSharedSecret(
                senderPrivateKey.getSerializedPrivate().toByteArray(), recipientPublicKey));
    byte[] senderEphemeralPublicKey = X25519.publicFromPrivate(senderEphemeralPrivateKey);
    byte[] senderPublicKey =
        X25519.publicFromPrivate(senderPrivateKey.getSerializedPrivate().toByteArray());
    byte[] kemSharedSecret =
        deriveKemSharedSecret(
            dhSharedSecret, senderEphemeralPublicKey, recipientPublicKey, senderPublicKey);
    return new HpkeKemEncapOutput(kemSharedSecret, senderEphemeralPublicKey);
  }
Helper function factored out to facilitate unit testing.
java_src/src/main/java/com/google/crypto/tink/hybrid/internal/X25519HpkeKem.java