EVP_MAC_init - specify the hash algorithm

Matt Caswell matt at openssl.org
Tue Jul 13 18:50:41 UTC 2021



On 13/07/2021 19:02, Ken Goldman wrote:
> Porting to 3.0 ... HMAC_Init_ex() had a place for
> the hash algorithm.  EVP_MAC_init() does not,
> unless it's embedded in the 'params' parameter.
> 
> Any advice?  Or a sample for doing an
> HMAC with 3.0?
> 

If its just a straight forward HMAC you want you can do it very simply 
with the one-shot EVP_Q_mac function:

unsigned char *EVP_Q_mac(OSSL_LIB_CTX *libctx, const char *name, const 
char *propq,
                          const char *subalg, const OSSL_PARAM *params,
                          const void *key, size_t keylen,
                          const unsigned char *data, size_t datalen,
                          unsigned char *out, size_t outsize, size_t 
*outlen);

Supply "HMAC" for the name param and "SHA256" (or whatever) for the subalg.

Matt


More information about the openssl-users mailing list