iPXE
Macros | Functions
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. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static __attribute__ ((always_inline)) size_t hmac_ctxsize(struct digest_algorithm *digest)
 Calculate HMAC context size. More...
 
static void hmac_update (struct digest_algorithm *digest, void *ctx, const void *data, size_t len)
 Update HMAC. More...
 
void hmac_init (struct digest_algorithm *digest, void *ctx, const void *key, size_t key_len)
 Initialise HMAC. More...
 
void hmac_final (struct digest_algorithm *digest, void *ctx, void *hmac)
 Finalise HMAC. More...
 

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 ))
static __attribute__((always_inline)) size_t hmac_ctxsize(struct digest_algorithm *digest)
Calculate HMAC context size.
Definition: hmac.h:27
u32 pad[9]
Padding.
Definition: ar9003_mac.h:90
size_t blocksize
Block size.
Definition: crypto.h:23
static void struct digest_algorithm * digest
HMAC-MD5 digest.
Definition: crypto.h:308
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
size_t ctxsize
Context size.
Definition: crypto.h:21

HMAC context type.

Definition at line 14 of file hmac.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ __attribute__()

static __attribute__ ( (always_inline)  )
inlinestatic

Calculate HMAC context size.

Parameters
digestDigest algorithm to use
Return values
lenHMAC context size

Definition at line 27 of file hmac.h.

28  {
29  hmac_context_t ( digest ) *hctx;
30 
31  return sizeof ( *hctx );
32 }
#define hmac_context_t(digest)
HMAC context type.
Definition: hmac.h:14
static void struct digest_algorithm * digest
HMAC-MD5 digest.
Definition: crypto.h:308

References digest, and hmac_context_t.

◆ hmac_update()

static 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 42 of file hmac.h.

43  {
44  hmac_context_t ( digest ) *hctx = ctx;
45 
46  digest_update ( digest, hctx->ctx, data, len );
47 }
#define hmac_context_t(digest)
HMAC context type.
Definition: hmac.h:14
static void struct digest_algorithm * digest
HMAC-MD5 digest.
Definition: crypto.h:308
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22

References ctx, data, digest, 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 
)

Initialise HMAC.

Parameters
digestDigest algorithm to use
ctxHMAC context
keyKey
key_lenLength of key

Definition at line 57 of file hmac.c.

58  {
59  hmac_context_t ( digest ) *hctx = ctx;
60  unsigned int i;
61 
62  /* Construct input pad */
63  memset ( hctx->pad, 0, sizeof ( hctx->pad ) );
64  if ( key_len <= sizeof ( hctx->pad ) ) {
65  memcpy ( hctx->pad, key, key_len );
66  } else {
67  digest_init ( digest, hctx->ctx );
68  digest_update ( digest, hctx->ctx, key, key_len );
69  digest_final ( digest, hctx->ctx, hctx->pad );
70  }
71  for ( i = 0 ; i < sizeof ( hctx->pad ) ; i++ ) {
72  hctx->pad[i] ^= 0x36;
73  }
74 
75  /* Start inner hash */
76  digest_init ( digest, hctx->ctx );
77  digest_update ( digest, hctx->ctx, hctx->pad, sizeof ( hctx->pad ) );
78 }
#define hmac_context_t(digest)
HMAC context type.
Definition: hmac.h:14
static void const void size_t key_len
Definition: crypto.h:285
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static void struct digest_algorithm * digest
HMAC-MD5 digest.
Definition: crypto.h:308
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
union @382 key
Sense key.
Definition: crypto.h:284
void * memset(void *dest, int character, size_t len) __nonnull

References ctx, digest, hmac_context_t, key, key_len, 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 
)

Finalise HMAC.

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

Definition at line 87 of file hmac.c.

87  {
88  hmac_context_t ( digest ) *hctx = ctx;
89  unsigned int i;
90 
91  /* Construct output pad from input pad */
92  for ( i = 0 ; i < sizeof ( hctx->pad ) ; i++ ) {
93  hctx->pad[i] ^= 0x6a;
94  }
95 
96  /* Finish inner hash */
97  digest_final ( digest, hctx->ctx, hmac );
98 
99  /* Perform outer hash */
100  digest_init ( digest, hctx->ctx );
101  digest_update ( digest, hctx->ctx, hctx->pad, sizeof ( hctx->pad ) );
102  digest_update ( digest, hctx->ctx, hmac, digest->digestsize );
103  digest_final ( digest, hctx->ctx, hmac );
104 
105  /* Erase output pad (from which the key may be derivable) */
106  memset ( hctx->pad, 0, sizeof ( hctx->pad ) );
107 }
#define hmac_context_t(digest)
HMAC context type.
Definition: hmac.h:14
static void struct digest_algorithm * digest
HMAC-MD5 digest.
Definition: crypto.h:308
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
size_t digestsize
Digest size.
Definition: crypto.h:25
void * memset(void *dest, int character, size_t len) __nonnull

References ctx, digest, 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().