How to set custom RNG for libcurl?

I’m trying to set a custom RNG for use by libcurl. My guess is that I need to call curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, ssl_ctx_init); and then, inside of the ssl_ctx_init function, call mbedtls_entropy_add_source(). I don’t know how to get the correct context from the mbedtls_ssl_config struct through.