]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Avoid divide-by-zero in kmac_prov.c's bytepad()
authorKlavishnik <evg.shtanov@gmail.com>
Wed, 9 Aug 2023 14:05:03 +0000 (17:05 +0300)
committerTomas Mraz <tomas@openssl.org>
Mon, 9 Oct 2023 10:05:10 +0000 (12:05 +0200)
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 https://github.com/openssl/openssl/pull/21698)

(cherry picked from commit 91895e39b10033178e662fc7427a09d7562cf8e1)

providers/implementations/macs/kmac_prov.c

index b93975b57903aa8e307a33a9404b2dd60c1411e6..48bdef9ef84a1dda90bd4d8a87a00854025aca40 100644 (file)
@@ -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;
     }
@@ -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;
     }