iPXE
hmac.h File Reference

Keyed-Hashing for Message Authentication. More...

#include <ipxe/crypto.h>

Go to the source code of this file.

Macros

#define hmac_key_t(digest)
 HMAC reduced key type.
#define hmac_context_t(digest)
 HMAC context type.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
static size_t hmac_keysize (struct digest_algorithm *digest)
 Calculate HMAC reduced key size.
static size_t hmac_ctxsize (struct digest_algorithm *digest)
 Calculate HMAC context size.
static void hmac_update (struct digest_algorithm *digest, void *ctx, const void *data, size_t len)
 Update HMAC.
void hmac_key (struct digest_algorithm *digest, void *ctx, const void *secret, size_t len, void *key)
 Construct HMAC reduced key.
void hmac_init_key (struct digest_algorithm *digest, void *ctx, const void *key)
 Initialise HMAC from reduced key.
void hmac_init (struct digest_algorithm *digest, void *ctx, const void *secret, size_t len)
 Initialise HMAC.
void hmac_final (struct digest_algorithm *digest, void *ctx, void *hmac)
 Finalise HMAC.

Detailed Description

Keyed-Hashing for Message Authentication.

Definition in file hmac.h.

Macro Definition Documentation

◆ hmac_key_t

#define hmac_key_t ( digest)
Value:
struct { \
/** HMAC input/output padding */ \
uint8_t pad[ digest->blocksize ]; \
} __attribute__ (( packed ))
u32 pad[9]
Padding.
Definition ar9003_mac.h:23
unsigned char uint8_t
Definition stdint.h:10
#define __attribute__(x)
Definition compiler.h:10

HMAC reduced key type.

Definition at line 15 of file hmac.h.

15#define hmac_key_t( digest ) struct { \
16 /** HMAC input/output padding */ \
17 uint8_t pad[ digest->blocksize ]; \
18 } __attribute__ (( packed ))

Referenced by hmac_init_key(), hmac_key(), and hmac_keysize().

◆ hmac_context_t

#define hmac_context_t ( digest)
Value:
struct { \
/** Digest context */ \
uint8_t ctx[ digest->ctxsize ]; \
/** HMAC input/output padding */ \
uint8_t pad[ digest->blocksize ]; \
} __attribute__ (( packed ))
struct golan_eq_context ctx
Definition CIB_PRM.h:0

HMAC context type.

Definition at line 21 of file hmac.h.

21#define hmac_context_t( digest ) struct { \
22 /** Digest context */ \
23 uint8_t ctx[ digest->ctxsize ]; \
24 /** HMAC input/output padding */ \
25 uint8_t pad[ digest->blocksize ]; \
26 } __attribute__ (( packed ))

Referenced by hmac_ctxsize(), hmac_final(), hmac_init(), hmac_init_key(), hmac_key(), and hmac_update().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ hmac_keysize()

size_t hmac_keysize ( struct digest_algorithm * digest)
inlinestatic

Calculate HMAC reduced key size.

Parameters
digestDigest algorithm to use
Return values
lenHMAC key pad size

Definition at line 35 of file hmac.h.

35 {
36 hmac_key_t ( digest ) *hkey;
37
38 return sizeof ( hkey->pad );
39}
#define hmac_key_t(digest)
HMAC reduced key type.
Definition hmac.h:15

References hmac_key_t.

Referenced by hmac_okx(), tls_generate_resumption_master(), and tls_set_digest().

◆ hmac_ctxsize()

size_t hmac_ctxsize ( struct digest_algorithm * digest)
inlinestatic

Calculate HMAC context size.

Parameters
digestDigest algorithm to use
Return values
lenHMAC context size

Definition at line 48 of file hmac.h.

48 {
49 hmac_context_t ( digest ) *hctx;
50
51 return sizeof ( *hctx );
52}
#define hmac_context_t(digest)
HMAC context type.
Definition hmac.h:21

References hmac_context_t.

Referenced by hkdf_expand(), hkdf_extract(), hmac_drbg_update_key(), hmac_drbg_update_value(), hmac_okx(), peerdist_info_passphrase_okx(), peerdist_info_segment_hash(), tls_hmac(), tls_hmac_list(), tls_p_hash_va(), and tls_set_kdf_master().

◆ hmac_update()

void hmac_update ( struct digest_algorithm * digest,
void * ctx,
const void * data,
size_t len )
inlinestatic

Update HMAC.

Parameters
digestDigest algorithm to use
ctxHMAC context
dataData
lenLength of data

Definition at line 62 of file hmac.h.

63 {
64 hmac_context_t ( digest ) *hctx = ctx;
65
66 digest_update ( digest, hctx->ctx, data, len );
67}
ring len
Length.
Definition dwmac.h:226
uint8_t data[48]
Additional event data.
Definition ena.h:11
static void digest_update(struct digest_algorithm *digest, void *ctx, const void *data, size_t len)
Definition crypto.h:299

References ctx, data, digest_update(), hmac_context_t, and len.

Referenced by ccmp_kie_mic(), hkdf_expand(), hkdf_extract(), hmac_drbg_update_key(), hmac_drbg_update_value(), hmac_okx(), ntlm_key(), ntlm_response(), pbkdf2_sha1_f(), peerdist_info_passphrase_okx(), peerdist_info_segment_hash(), prf_sha1(), tkip_kie_mic(), tls_hmac_init(), tls_hmac_update(), tls_hmac_update_va(), and tls_p_hash_va().

◆ hmac_key()

void hmac_key ( struct digest_algorithm * digest,
void * ctx,
const void * secret,
size_t len,
void * key )
extern

Construct HMAC reduced key.

Parameters
digestDigest algorithm to use
ctxHMAC context
secretSecret key
lenLength of secret key
keyHMAC reduced key to fill in

Definition at line 59 of file hmac.c.

60 {
61 hmac_context_t ( digest ) *hctx = ctx;
62 hmac_key_t ( digest ) *hkey = key;
63
64 /* Reduce key (if applicable) and zero-pad to block size */
65 memset ( hkey->pad, 0, sizeof ( hkey->pad ) );
66 if ( len <= sizeof ( hkey->pad ) ) {
67 memcpy ( hkey->pad, secret, len );
68 } else {
69 digest_init ( digest, hctx->ctx );
70 digest_update ( digest, hctx->ctx, secret, len );
71 digest_final ( digest, hctx->ctx, hkey->pad );
72 }
73}
union @162305117151260234136356364136041353210355154177 key
static void digest_init(struct digest_algorithm *digest, void *ctx)
Definition crypto.h:294
static void digest_final(struct digest_algorithm *digest, void *ctx, void *out)
Definition crypto.h:305
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * memset(void *dest, int character, size_t len) __nonnull

References ctx, digest_final(), digest_init(), digest_update(), hmac_context_t, hmac_key_t, key, len, memcpy(), and memset().

Referenced by hmac_init(), hmac_okx(), and tls_set_kdf_master().

◆ hmac_init_key()

void hmac_init_key ( struct digest_algorithm * digest,
void * ctx,
const void * key )
extern

Initialise HMAC from reduced key.

Parameters
digestDigest algorithm
ctxHMAC context
hkeyHMAC key

Definition at line 82 of file hmac.c.

83 {
84 hmac_context_t ( digest ) *hctx = ctx;
85 const hmac_key_t ( digest ) *hkey = key;
86 unsigned int i;
87
88 /* Construct input pad */
89 for ( i = 0 ; i < sizeof ( hkey->pad ) ; i++ ) {
90 hctx->pad[i] = ( hkey->pad[i] ^ 0x36 );
91 }
92
93 /* Start inner hash */
94 digest_init ( digest, hctx->ctx );
95 digest_update ( digest, hctx->ctx, hctx->pad, sizeof ( hctx->pad ) );
96}

References ctx, digest_init(), digest_update(), hmac_context_t, hmac_key_t, and key.

Referenced by hmac_init(), hmac_okx(), and tls_p_hash_va().

◆ hmac_init()

void hmac_init ( struct digest_algorithm * digest,
void * ctx,
const void * secret,
size_t len )
extern

Initialise HMAC.

Parameters
digestDigest algorithm to use
ctxHMAC context
secretSecret key
lenLength of secret key

Definition at line 106 of file hmac.c.

107 {
108 hmac_context_t ( digest ) *hctx = ctx;
109
110 /* Construct reduced key (in input pad) */
111 hmac_key ( digest, hctx->ctx, secret, len, hctx->pad );
112
113 /* Initialise HMAC */
114 hmac_init_key ( digest, hctx->ctx, hctx->pad );
115}
void hmac_key(struct digest_algorithm *digest, void *ctx, const void *secret, size_t len, void *key)
Construct HMAC reduced key.
Definition hmac.c:59
void hmac_init_key(struct digest_algorithm *digest, void *ctx, const void *key)
Initialise HMAC from reduced key.
Definition hmac.c:82

References ctx, hmac_context_t, hmac_init_key(), hmac_key(), and len.

Referenced by ccmp_kie_mic(), hkdf_expand(), hkdf_extract(), hmac_drbg_update_key(), hmac_drbg_update_value(), hmac_okx(), ntlm_key(), ntlm_response(), pbkdf2_sha1_f(), peerdist_info_passphrase_okx(), peerdist_info_segment_hash(), prf_sha1(), tkip_kie_mic(), and tls_hmac_init().

◆ hmac_final()

void hmac_final ( struct digest_algorithm * digest,
void * ctx,
void * hmac )
extern

Finalise HMAC.

Parameters
digestDigest algorithm to use
ctxHMAC context
hmacHMAC digest to fill in

Definition at line 124 of file hmac.c.

124 {
125 hmac_context_t ( digest ) *hctx = ctx;
126 unsigned int i;
127
128 /* Construct output pad from input pad */
129 for ( i = 0 ; i < sizeof ( hctx->pad ) ; i++ ) {
130 hctx->pad[i] ^= 0x6a;
131 }
132
133 /* Finish inner hash */
134 digest_final ( digest, hctx->ctx, hmac );
135
136 /* Perform outer hash */
137 digest_init ( digest, hctx->ctx );
138 digest_update ( digest, hctx->ctx, hctx->pad, sizeof ( hctx->pad ) );
139 digest_update ( digest, hctx->ctx, hmac, digest->digestsize );
140 digest_final ( digest, hctx->ctx, hmac );
141
142 /* Erase output pad (from which the key may be derivable) */
143 memset ( hctx->pad, 0, sizeof ( hctx->pad ) );
144}
size_t digestsize
Digest size.
Definition crypto.h:27

References ctx, digest_final(), digest_init(), digest_update(), digest_algorithm::digestsize, hmac_context_t, and memset().

Referenced by ccmp_kie_mic(), hkdf_expand(), hkdf_extract(), hmac_drbg_update_key(), hmac_drbg_update_value(), hmac_okx(), ntlm_key(), ntlm_response(), pbkdf2_sha1_f(), peerdist_info_passphrase_okx(), peerdist_info_segment_hash(), prf_sha1(), tkip_kie_mic(), tls_hmac_final(), and tls_p_hash_va().