From b33ef74d442f81f1169b05c7793c0ca42e69c26c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Tue, 7 Mar 2023 00:04:16 +0100 Subject: [PATCH] Use MD_LIGHT, not sha1.h, in RSA selftest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Same note as previous commit regarding guards. Note that we could auto-enable MD_LIGHT only when SELF_TEST is defined, and even only when SHA1_C is defined too, but somewhere down the line we'll want to auto-enable it for the sake of other RSA function (not in selftest and could use any hash), so there's little point in optimizing the temporary condition, let's use the simple one upfront. Signed-off-by: Manuel Pégourié-Gonnard --- include/mbedtls/build_info.h | 5 +++-- library/rsa.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/mbedtls/build_info.h b/include/mbedtls/build_info.h index 86a3e161d..bfbf9de57 100644 --- a/include/mbedtls/build_info.h +++ b/include/mbedtls/build_info.h @@ -87,9 +87,10 @@ #define MBEDTLS_MD_LIGHT #endif -/* Auto-enable MBEDTLS_MD_LIGHT it one module needs it. +/* Auto-enable MBEDTLS_MD_LIGHT if some module needs it. */ -#if defined(MBEDTLS_PEM_PARSE_C) +#if defined(MBEDTLS_PEM_PARSE_C) || \ + defined(MBEDTLS_RSA_C) #define MBEDTLS_MD_LIGHT #endif diff --git a/library/rsa.c b/library/rsa.c index 7159588e7..584b363cb 100644 --- a/library/rsa.c +++ b/library/rsa.c @@ -2344,7 +2344,7 @@ void mbedtls_rsa_free(mbedtls_rsa_context *ctx) #if defined(MBEDTLS_SELF_TEST) -#include "mbedtls/sha1.h" +#include "mbedtls/md.h" /* * Example RSA-1024 keypair, for test purposes @@ -2508,7 +2508,8 @@ int mbedtls_rsa_self_test(int verbose) mbedtls_printf(" PKCS#1 data sign : "); } - if (mbedtls_sha1(rsa_plaintext, PT_LEN, sha1sum) != 0) { + if (mbedtls_md(mbedtls_md_info_from_type(MBEDTLS_MD_SHA1), + rsa_plaintext, PT_LEN, sha1sum) != 0) { if (verbose != 0) { mbedtls_printf("failed\n"); }