hmac.c File Reference

Keyed-Hashing for Message Authentication. More...

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

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
static void hmac_reduce_key (struct digest_algorithm *digest, void *key, size_t *key_len)
 Reduce HMAC key length.
void hmac_init (struct digest_algorithm *digest, void *digest_ctx, void *key, size_t *key_len)
 Initialise HMAC.
void hmac_final (struct digest_algorithm *digest, void *digest_ctx, void *key, size_t *key_len, void *hmac)
 Finalise HMAC.


Detailed Description

Keyed-Hashing for Message Authentication.

Definition in file hmac.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER   ) 

static void hmac_reduce_key ( struct digest_algorithm digest,
void *  key,
size_t key_len 
) [static]

Reduce HMAC key length.

Parameters:
digest Digest algorithm to use
digest_ctx Digest context
key Key
key_len Length of key

Definition at line 40 of file hmac.c.

References digest_algorithm::ctxsize, digest_final(), digest_init(), digest_update(), and digest_algorithm::digestsize.

Referenced by hmac_final(), and hmac_init().

00041                                                            {
00042         uint8_t digest_ctx[digest->ctxsize];
00043 
00044         digest_init ( digest, digest_ctx );
00045         digest_update ( digest, digest_ctx, key, *key_len );
00046         digest_final ( digest, digest_ctx, key );
00047         *key_len = digest->digestsize;
00048 }

void hmac_init ( struct digest_algorithm digest,
void *  digest_ctx,
void *  key,
size_t key_len 
)

Initialise HMAC.

Parameters:
digest Digest algorithm to use
digest_ctx Digest context
key Key
key_len Length of key
The length of the key should be less than the block size of the digest algorithm being used. (If the key length is greater, it will be replaced with its own digest, and key_len will be updated accordingly).

Definition at line 63 of file hmac.c.

References digest_algorithm::blocksize, digest_init(), digest_update(), hmac_reduce_key(), memcpy, and memset().

Referenced by ccmp_kie_mic(), pbkdf2_sha1_f(), prf_sha1(), tkip_kie_mic(), tls_hmac(), tls_p_hash_va(), and wpa_check_pmkid().

00064                                               {
00065         unsigned char k_ipad[digest->blocksize];
00066         unsigned int i;
00067 
00068         /* Reduce key if necessary */
00069         if ( *key_len > sizeof ( k_ipad ) )
00070                 hmac_reduce_key ( digest, key, key_len );
00071 
00072         /* Construct input pad */
00073         memset ( k_ipad, 0, sizeof ( k_ipad ) );
00074         memcpy ( k_ipad, key, *key_len );
00075         for ( i = 0 ; i < sizeof ( k_ipad ) ; i++ ) {
00076                 k_ipad[i] ^= 0x36;
00077         }
00078         
00079         /* Start inner hash */
00080         digest_init ( digest, digest_ctx );
00081         digest_update ( digest, digest_ctx, k_ipad, sizeof ( k_ipad ) );
00082 }

void hmac_final ( struct digest_algorithm digest,
void *  digest_ctx,
void *  key,
size_t key_len,
void *  hmac 
)

Finalise HMAC.

Parameters:
digest Digest algorithm to use
digest_ctx Digest context
key Key
key_len Length of key
hmac HMAC digest to fill in
The length of the key should be less than the block size of the digest algorithm being used. (If the key length is greater, it will be replaced with its own digest, and key_len will be updated accordingly).

Definition at line 98 of file hmac.c.

References digest_algorithm::blocksize, digest_final(), digest_init(), digest_update(), digest_algorithm::digestsize, hmac_reduce_key(), memcpy, and memset().

Referenced by ccmp_kie_mic(), pbkdf2_sha1_f(), prf_sha1(), tkip_kie_mic(), tls_hmac(), tls_p_hash_va(), and wpa_check_pmkid().

00099                                                            {
00100         unsigned char k_opad[digest->blocksize];
00101         unsigned int i;
00102 
00103         /* Reduce key if necessary */
00104         if ( *key_len > sizeof ( k_opad ) )
00105                 hmac_reduce_key ( digest, key, key_len );
00106 
00107         /* Construct output pad */
00108         memset ( k_opad, 0, sizeof ( k_opad ) );
00109         memcpy ( k_opad, key, *key_len );
00110         for ( i = 0 ; i < sizeof ( k_opad ) ; i++ ) {
00111                 k_opad[i] ^= 0x5c;
00112         }
00113         
00114         /* Finish inner hash */
00115         digest_final ( digest, digest_ctx, hmac );
00116 
00117         /* Perform outer hash */
00118         digest_init ( digest, digest_ctx );
00119         digest_update ( digest, digest_ctx, k_opad, sizeof ( k_opad ) );
00120         digest_update ( digest, digest_ctx, hmac, digest->digestsize );
00121         digest_final ( digest, digest_ctx, hmac );
00122 }


Generated on Tue Apr 6 20:01:15 2010 for gPXE by  doxygen 1.5.7.1