| 410 | } |
| 411 | |
| 412 | static void |
| 413 | hmac_init_pad(const struct auth_hash *axf, const char *key, int klen, |
| 414 | void *auth_ctx, uint8_t padval) |
| 415 | { |
| 416 | uint8_t hmac_key[HMAC_MAX_BLOCK_LEN]; |
| 417 | u_int i; |
| 418 | |
| 419 | KASSERT(axf->blocksize <= sizeof(hmac_key), |
| 420 | ("Invalid HMAC block size %d", axf->blocksize)); |
| 421 | |
| 422 | /* |
| 423 | * If the key is larger than the block size, use the digest of |
| 424 | * the key as the key instead. |
| 425 | */ |
| 426 | memset(hmac_key, 0, sizeof(hmac_key)); |
| 427 | if (klen > axf->blocksize) { |
| 428 | axf->Init(auth_ctx); |
| 429 | axf->Update(auth_ctx, key, klen); |
| 430 | axf->Final(hmac_key, auth_ctx); |
| 431 | klen = axf->hashsize; |
| 432 | } else |
| 433 | memcpy(hmac_key, key, klen); |
| 434 | |
| 435 | for (i = 0; i < axf->blocksize; i++) |
| 436 | hmac_key[i] ^= padval; |
| 437 | |
| 438 | axf->Init(auth_ctx); |
| 439 | axf->Update(auth_ctx, hmac_key, axf->blocksize); |
| 440 | explicit_bzero(hmac_key, sizeof(hmac_key)); |
| 441 | } |
| 442 | |
| 443 | void |
| 444 | hmac_init_ipad(const struct auth_hash *axf, const char *key, int klen, |
no test coverage detected