Ad

How To Find The Definition Of EVP_MD, EVP_MD_CT, Etc In OpenSSL?

- 1 answer

I am using OpenSSL. I want to calculate a mac of message using HMAC algorithm. The definitions of HMAC is as following:

unsigned char *HMAC(const EVP_MD *evp_md, const void *key,
                     int key_len, const unsigned char *d, int n,
                     unsigned char *md, unsigned int *md_len);

Now, I find the first parameter of HMAC is EVP_MD. I notice that many functions return this parameter. Where can I find the content of EVP_MD in its' reference or source code.

 const EVP_MD *EVP_md_null(void);
 const EVP_MD *EVP_md2(void);
 const EVP_MD *EVP_md5(void);
 const EVP_MD *EVP_sha(void);
 const EVP_MD *EVP_sha1(void);
 const EVP_MD *EVP_dss(void);
 const EVP_MD *EVP_dss1(void);
 const EVP_MD *EVP_mdc2(void);
 const EVP_MD *EVP_ripemd160(void);

 const EVP_MD *EVP_sha224(void);
 const EVP_MD *EVP_sha256(void);
 const EVP_MD *EVP_sha384(void);
 const EVP_MD *EVP_sha512(void);

What is the relationship between EVP_MD and EVP_MD_CTX ?

Ad

Answer

An EVP_MD structure contains the description of a hashing algorithm. The functions you listed return a pointer to one of these structs for a specific hash. You would pass one of these as the first parameter to HASH.

For example, if you wanted to hash with SHA256 you would call EVP_sha256 and pass its return value to HASH.

Ad
source: stackoverflow.com
Ad