iPXE
Functions
hmac.c File Reference

Keyed-Hashing for Message Authentication. More...

#include <string.h>
#include <assert.h>
#include <ipxe/crypto.h>
#include <ipxe/hmac.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
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.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ 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().