Skip to content

Commit

Permalink
Avoid divide-by-zero in kmac_prov.c's bytepad()
Browse files Browse the repository at this point in the history
This would happen if EVP_MD_get_block_size() returned 0
so we return an error instead.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #21698)
  • Loading branch information
Klavishnik authored and t8m committed Oct 9, 2023
1 parent 581c87b commit 91895e3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions providers/implementations/macs/kmac_prov.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ static int kmac_setkey(struct kmac_data_st *kctx, const unsigned char *key,
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH);
return 0;
}
if (w < 0) {
if (w <= 0) {
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DIGEST_LENGTH);
return 0;
}
Expand Down Expand Up @@ -289,7 +289,7 @@ static int kmac_init(void *vmacctx, const unsigned char *key,
return 0;

t = EVP_MD_get_block_size(ossl_prov_digest_md(&kctx->digest));
if (t < 0) {
if (t <= 0) {
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DIGEST_LENGTH);
return 0;
}
Expand Down

0 comments on commit 91895e3

Please sign in to comment.