I've been trying to implement ECDH with Curve25519 and have been running into some problems. The attached code demonstrates that given valid input the libgcrypt function gcry_mpi_ec_mul produces a segfault. I tried ec_add and got an "Addition not supported for Montgomery curves" fatal error message.
I'm wondering what the best course of action is in trying to implement ECDH efficiently using the libgcrypt library. If the necessary operations are not supported for Curve25519, could you recommend a fully-functional curve in the library that would good for ECDH? Any advice would be much appreciated.