Skip to content

Commit

Permalink
cleanse stack variable in blake2[b|s] finalization
Browse files Browse the repository at this point in the history
If the output of a blake2[b|s] digest isn't a multipl of 8, then a stack
buffer is used to compute the final output, which is left un-zeroed
prior to return, allowing the potential leak of key data.  Ensure that,
if the stack variable is used, it gets cleared prior to return.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #23173)

(cherry picked from commit 8b9cf1b)
  • Loading branch information
nhorman committed Jan 3, 2024
1 parent 0b36386 commit 5801393
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion providers/implementations/digests/blake2b_prov.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,10 @@ int ossl_blake2b_final(unsigned char *md, BLAKE2B_CTX *c)
for (i = 0; i < iter; ++i)
store64(target + sizeof(c->h[i]) * i, c->h[i]);

if (target != md)
if (target != md) {
memcpy(md, target, c->outlen);
OPENSSL_cleanse(target, sizeof(outbuffer));
}

OPENSSL_cleanse(c, sizeof(BLAKE2B_CTX));
return 1;
Expand Down
4 changes: 3 additions & 1 deletion providers/implementations/digests/blake2s_prov.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,10 @@ int ossl_blake2s_final(unsigned char *md, BLAKE2S_CTX *c)
for (i = 0; i < iter; ++i)
store32(target + sizeof(c->h[i]) * i, c->h[i]);

if (target != md)
if (target != md) {
memcpy(md, target, c->outlen);
OPENSSL_cleanse(target, sizeof(outbuffer));
}

OPENSSL_cleanse(c, sizeof(BLAKE2S_CTX));
return 1;
Expand Down

0 comments on commit 5801393

Please sign in to comment.