EVP_MAC_init - specify the hash algorithm

Ken Goldman kgoldman at us.ibm.com
Tue Jul 13 20:44:07 UTC 2021

On 7/13/2021 2:50 PM, Matt Caswell wrote:
> 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.

It's not.  It's the usual init/update/final pattern.

More information about the openssl-users mailing list