[openssl-dev] [HMAC] reusing the session objects

Catalin Vasile cata.vasile at nxp.com
Thu Jun 16 14:06:04 UTC 2016


Hi,

I am trying to make a user space app with the following behaviour:
1. alocate and initialize hmac (precompute key's hash, i_key_pad[1] and o_key_pad[1])
2. generate hmac for an input
3. generate hmac for another input, without having to redo the precomputations
4. generate hmac for another input, without having to redo the precomputations
5. generate hmac for another input, without having to redo the precomputations
6. generate hmac for another input, without having to redo the precomputations
...
$(N-1). generate hmac for another input, without having to redo the precomputations
$N. cleanup state objects.

I would like the same effect like calling:
2. digest0 = HMAC(EVP_some_hash_function(), key, key_len, data0, data0_size, NULL, NULL);
3. digest1 = HMAC(EVP_some_hash_function(), key, key_len, data1, data1_size, NULL, NULL);
4. digest2 = HMAC(EVP_some_hash_function(), key, key_len, data2, data2_size, NULL, NULL);
5. digest3 = HMAC(EVP_some_hash_function(), key, key_len, data3, data3_size, NULL, NULL);
6. digest4 = HMAC(EVP_some_hash_function(), key, key_len, data4, data4_size, NULL, NULL);
...
$(N-1). digest5 = HMAC(EVP_some_hash_function(), key, key_len, data5, data5_size, NULL, NULL);
But without making the app recompute the key's hash, i_key_pad[1] and o_key_pad[1] every time.

Does calling a series of HMAC_Init_ex(), HMAC_Update(), HMAC_Final(), with the "key" and "md" parameters for HMAC_Init_ex() set to NULL achieve the same result as above?
The series would look like this:
1. Allocate_state_objects(); HMAC_Init_ex(..., key, ..., md, ...);
2. HMAC_Init_ex(..., NULL, ..., NULL, ...), HMAC_Update(..., data0, ...), HMAC_Final(..., digest0, ...)
3. HMAC_Init_ex(..., NULL, ..., NULL, ..., HMAC_Update(..., data1, ...), HMAC_Final(..., digest1, ...)
4. HMAC_Init_ex(..., NULL, ..., NULL, ...), HMAC_Update(..., data2, ...), HMAC_Final(..., digest2, ...)
5. HMAC_Init_ex(..., NULL, ..., NULL, ...), HMAC_Update(..., data3, ...), HMAC_Final(..., digest3, ...)
6. HMAC_Init_ex(..., NULL, ..., NULL, ...), HMAC_Update(..., data4, ...), HMAC_Final(..., digest4, ...)
...
$(N-1). HMAC_Init_ex(..., NULL, ..., NULL, ...), HMAC_Update(..., data5, ...), HMAC_Final(..., digest5, ...)
$N. Release_state_objects();

Catalin Vasile

[1] https://en.wikipedia.org/wiki/Hash-based_message_authentication_code#Implementation


More information about the openssl-dev mailing list