HpkeKemEncapOutput authEncapsulate(
      byte[] recipientPublicKey, KeyPair senderEphemeralKeyPair, HpkeKemPrivateKey senderPrivateKey)
      throws GeneralSecurityException {
    ECPublicKey recipientECPublicKey =
        EllipticCurves.getEcPublicKey(curve, PointFormatType.UNCOMPRESSED, recipientPublicKey);
    ECPrivateKey privateKey =
        EllipticCurves.getEcPrivateKey(
            curve, senderPrivateKey.getSerializedPrivate().toByteArray());
    byte[] dhSharedSecret =
        Bytes.concat(
            EllipticCurves.computeSharedSecret(
                (ECPrivateKey) senderEphemeralKeyPair.getPrivate(), recipientECPublicKey),
            EllipticCurves.computeSharedSecret(privateKey, recipientECPublicKey));
    byte[] senderEphemeralPublicKey =
        EllipticCurves.pointEncode(
            curve,
            PointFormatType.UNCOMPRESSED,
            ((ECPublicKey) senderEphemeralKeyPair.getPublic()).getW());

    byte[] kemSharedSecret =
        deriveKemSharedSecret(
            dhSharedSecret,
            senderEphemeralPublicKey,
            recipientPublicKey,
            senderPrivateKey.getSerializedPublic().toByteArray());
    return new HpkeKemEncapOutput(kemSharedSecret, senderEphemeralPublicKey);
  }
Helper function factored out to facilitate unit testing.
java_src/src/main/java/com/google/crypto/tink/hybrid/internal/NistCurvesHpkeKem.java