[crypto] Simplify internal HMAC API

Simplify the internal HMAC API so that the key is provided only at the
point of calling hmac_init(), and the (potentially reduced) key is
stored as part of the context for later use by hmac_final().

This simplifies the calling code, and avoids the need for callers such
as TLS to allocate a potentially variable length block in order to
retain a copy of the unmodified key.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2022-10-10 12:21:54 +01:00
parent 88419b608d
commit 007d3cb800
16 changed files with 142 additions and 163 deletions
+5 -6
View File
@@ -478,16 +478,15 @@ struct net80211_crypto ccmp_crypto __net80211_crypto = {
static void ccmp_kie_mic ( const void *kck, const void *msg, size_t len,
void *mic )
{
u8 sha1_ctx[SHA1_CTX_SIZE];
u8 ctx[SHA1_CTX_SIZE + SHA1_BLOCK_SIZE];
u8 kckb[16];
u8 hash[SHA1_DIGEST_SIZE];
size_t kck_len = 16;
memcpy ( kckb, kck, kck_len );
memcpy ( kckb, kck, sizeof ( kckb ) );
hmac_init ( &sha1_algorithm, sha1_ctx, kckb, &kck_len );
hmac_update ( &sha1_algorithm, sha1_ctx, msg, len );
hmac_final ( &sha1_algorithm, sha1_ctx, kckb, &kck_len, hash );
hmac_init ( &sha1_algorithm, ctx, kckb, sizeof ( kckb ) );
hmac_update ( &sha1_algorithm, ctx, msg, len );
hmac_final ( &sha1_algorithm, ctx, hash );
memcpy ( mic, hash, 16 );
}
+4 -5
View File
@@ -545,15 +545,14 @@ struct net80211_crypto tkip_crypto __net80211_crypto = {
static void tkip_kie_mic ( const void *kck, const void *msg, size_t len,
void *mic )
{
uint8_t ctx[MD5_CTX_SIZE];
uint8_t ctx[MD5_CTX_SIZE + MD5_BLOCK_SIZE];
u8 kckb[16];
size_t kck_len = 16;
memcpy ( kckb, kck, kck_len );
memcpy ( kckb, kck, sizeof ( kckb ) );
hmac_init ( &md5_algorithm, ctx, kckb, &kck_len );
hmac_init ( &md5_algorithm, ctx, kckb, sizeof ( kckb ) );
hmac_update ( &md5_algorithm, ctx, msg, len );
hmac_final ( &md5_algorithm, ctx, kckb, &kck_len, mic );
hmac_final ( &md5_algorithm, ctx, mic );
}
/**