Skip to content

Commit

Permalink
Cleanse the right amount of bytes in HMAC. (#1613)
Browse files Browse the repository at this point in the history
EVP_MAX_MD_BLOCK_SIZE is the block size in bytes. 

This commit partially reverts "Zeroize data immediately after use for FIPS
(#911)", commit c7a9fd0. 
Prior to it, EVP_MAX_MD_BLOCK_SIZE was divided by 8
in a 64-bit word array initialisation in hmac.c
  • Loading branch information
nebeid authored May 31, 2024
1 parent ffbf2da commit 3324473
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
1 change: 0 additions & 1 deletion crypto/fipsmodule/digest/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
extern "C" {
#endif

#define EVP_MAX_MD_BLOCK_SIZE_BYTES (EVP_MAX_MD_BLOCK_SIZE / 8)

struct env_md_st {
// type contains a NID identifing the digest function. (For example,
Expand Down
8 changes: 4 additions & 4 deletions crypto/fipsmodule/hmac/hmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, size_t key_len,
FIPS_service_indicator_lock_state();
int result = 0;

uint64_t pad[EVP_MAX_MD_BLOCK_SIZE_BYTES] = {0};
uint64_t key_block[EVP_MAX_MD_BLOCK_SIZE_BYTES] = {0};
uint64_t pad[EVP_MAX_MD_BLOCK_SIZE / sizeof(uint64_t)] = {0};
uint64_t key_block[EVP_MAX_MD_BLOCK_SIZE / sizeof(uint64_t)] = {0};
if (block_size < key_len) {
// Long keys are hashed.
if (!methods->init(&ctx->md_ctx) ||
Expand Down Expand Up @@ -322,8 +322,8 @@ int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, size_t key_len,

result = 1;
end:
OPENSSL_cleanse(pad, EVP_MAX_MD_BLOCK_SIZE_BYTES);
OPENSSL_cleanse(key_block, EVP_MAX_MD_BLOCK_SIZE_BYTES);
OPENSSL_cleanse(pad, EVP_MAX_MD_BLOCK_SIZE);
OPENSSL_cleanse(key_block, EVP_MAX_MD_BLOCK_SIZE);
FIPS_service_indicator_unlock_state();
if (result != 1) {
// We're in some error state, so return our context to a known and well defined zero state.
Expand Down

0 comments on commit 3324473

Please sign in to comment.