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_context_t(digest)
 HMAC context type.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
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_init (struct digest_algorithm *digest, void *ctx, const void *key, size_t key_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_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
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 context type.

Definition at line 15 of file hmac.h.

15#define hmac_context_t( digest ) struct { \
16 /** Digest context */ \
17 uint8_t ctx[ digest->ctxsize ]; \
18 /** HMAC input/output padding */ \
19 uint8_t pad[ digest->blocksize ]; \
20 } __attribute__ (( packed ))

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

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ 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 29 of file hmac.h.

29 {
30 hmac_context_t ( digest ) *hctx;
31
32 return sizeof ( *hctx );
33}
#define hmac_context_t(digest)
HMAC context type.
Definition hmac.h:15

References hmac_context_t.

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

◆ 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 43 of file hmac.h.

44 {
45 hmac_context_t ( digest ) *hctx = ctx;
46
47 digest_update ( digest, hctx->ctx, data, len );
48}
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:224

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

Referenced by ccmp_kie_mic(), 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_init()

void hmac_init ( struct digest_algorithm * digest,
void * ctx,
const void * key,
size_t key_len )
extern

Initialise HMAC.

Parameters
digestDigest algorithm to use
ctxHMAC context
keyKey
key_lenLength of key

Definition at line 58 of file hmac.c.

59 {
60 hmac_context_t ( digest ) *hctx = ctx;
61 unsigned int i;
62
63 /* Construct input pad */
64 memset ( hctx->pad, 0, sizeof ( hctx->pad ) );
65 if ( key_len <= sizeof ( hctx->pad ) ) {
66 memcpy ( hctx->pad, key, key_len );
67 } else {
68 digest_init ( digest, hctx->ctx );
69 digest_update ( digest, hctx->ctx, key, key_len );
70 digest_final ( digest, hctx->ctx, hctx->pad );
71 }
72 for ( i = 0 ; i < sizeof ( hctx->pad ) ; i++ ) {
73 hctx->pad[i] ^= 0x36;
74 }
75
76 /* Start inner hash */
77 digest_init ( digest, hctx->ctx );
78 digest_update ( digest, hctx->ctx, hctx->pad, sizeof ( hctx->pad ) );
79}
union @162305117151260234136356364136041353210355154177 key
Sense key.
Definition scsi.h:3
static void digest_init(struct digest_algorithm *digest, void *ctx)
Definition crypto.h:219
static void digest_final(struct digest_algorithm *digest, void *ctx, void *out)
Definition crypto.h:230
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, key, memcpy(), and memset().

Referenced by ccmp_kie_mic(), 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(), and tls_p_hash_va().

◆ 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 88 of file hmac.c.

88 {
89 hmac_context_t ( digest ) *hctx = ctx;
90 unsigned int i;
91
92 /* Construct output pad from input pad */
93 for ( i = 0 ; i < sizeof ( hctx->pad ) ; i++ ) {
94 hctx->pad[i] ^= 0x6a;
95 }
96
97 /* Finish inner hash */
98 digest_final ( digest, hctx->ctx, hmac );
99
100 /* Perform outer hash */
101 digest_init ( digest, hctx->ctx );
102 digest_update ( digest, hctx->ctx, hctx->pad, sizeof ( hctx->pad ) );
103 digest_update ( digest, hctx->ctx, hmac, digest->digestsize );
104 digest_final ( digest, hctx->ctx, hmac );
105
106 /* Erase output pad (from which the key may be derivable) */
107 memset ( hctx->pad, 0, sizeof ( hctx->pad ) );
108}
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(), 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().