Skip to content

Investigate use of EVP_MD_CTX_init after EVP_MD_CTX_new #1139

@farshadasl

Description

@farshadasl

There are several cases in the native code that call EVP_MD_CTX_init after EVP_MD_CTX_new

However, based on the OpenSSL documentation:

EVP_MD_CTX_new(): This function allocates, initializes, and returns a new EVP_MD_CTX structure. It is ready for immediate use.

EVP_MD_CTX_new already performs the necessary allocation and internal initialization.
Calling EVP_MD_CTX_init immediately after is redundant and, in some library versions, could lead to a minor memory leak if new had already allocated internal sub-structures.

Recommendation: Use EVP_MD_CTX_new() to allocate and EVP_MD_CTX_free() to clean up.

https://man.openbsd.org/OpenBSD-6.4/EVP_DigestInit.3#EVP_MD_CTX_init

EVP_MD_CTX_init() is a deprecated function to clear a digest context on the stack before use. Do not use it on a digest context returned from EVP_MD_CTX_new() or one one that was already used.

@jasonkatonica

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions