Duplicate EVP_MD structure when necessary

Many openssl APIs return const EVP_MD pointers (e.g., EVP_sha256), and sometimes you need to resolve following errors:

error: cast discards 'const' qualifier from pointer target type [-Werror=cast-qual]

You can either suppress the warning like this or duplicate EVP_MD:

EVP_MD *md = EVP_MD_meth_dup(EVP_sha256());
......
EVP_MD_meth_free(md);

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.