Changed use of EVP_PKEY_CTX_md() and more specific error codes