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)
 
 FILE_SECBOOT (PERMITTED)
 
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  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ 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 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 }
static void digest_update(struct digest_algorithm *digest, void *ctx, const void *data, size_t len)
Definition: crypto.h:224
#define hmac_context_t(digest)
HMAC context type.
Definition: hmac.h:15
static void digest_final(struct digest_algorithm *digest, void *ctx, void *out)
Definition: crypto.h:230
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static void digest_init(struct digest_algorithm *digest, void *ctx)
Definition: crypto.h:219
union @391 key
Sense key.
Definition: scsi.h:18
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 
)

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 }
static void digest_update(struct digest_algorithm *digest, void *ctx, const void *data, size_t len)
Definition: crypto.h:224
#define hmac_context_t(digest)
HMAC context type.
Definition: hmac.h:15
static void digest_final(struct digest_algorithm *digest, void *ctx, void *out)
Definition: crypto.h:230
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
static void digest_init(struct digest_algorithm *digest, void *ctx)
Definition: crypto.h:219
size_t digestsize
Digest size.
Definition: crypto.h:27
void * memset(void *dest, int character, size_t len) __nonnull

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