Commit dce11301ff for openssl.org
commit dce11301ff54174df95b9d593bd873e8e50f0938
Author: Billy Brumley <bbb@iki.fi>
Date: Tue Nov 17 08:31:49 2026 -0500
SSHKDF: refuse a digest that has no output to avoid infinite loop
The key derivation specified by SSH appends one digest per round until
it has enough key material. With a zero-size digest, such as the NULL
digest, it leads to an infinite loop.
Check the digest size of the supplied digest algorithm and error out
if it is non-positive.
Fixes: 8d76481b189b "Implement SSH KDF"
Assisted-by: Claude:claude-mythos-5-2
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.foundation>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
Merge-date: Tue Nov 24 16:26:39 2026
Merged-from: https://github.com/openssl/openssl/pull/33923
diff --git a/providers/implementations/kdfs/sshkdf.c b/providers/implementations/kdfs/sshkdf.c
index ee2f75a7c2..bbc7bfbd04 100644
--- a/providers/implementations/kdfs/sshkdf.c
+++ b/providers/implementations/kdfs/sshkdf.c
@@ -195,6 +195,11 @@ static int kdf_sshkdf_derive(void *vctx, unsigned char *key, size_t keylen,
ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_MESSAGE_DIGEST);
return 0;
}
+ /* each round concats a digest, so we need positive len */
+ if (EVP_MD_get_size(md) <= 0) {
+ ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DIGEST_SIZE);
+ return 0;
+ }
if (ctx->key == NULL) {
ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_KEY);
return 0;