Use MD_LIGHT, not sha1.h, in RSA selftest

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 <manuel.pegourie-gonnard@arm.com>
This commit is contained in:
Manuel Pégourié-Gonnard 2023-03-07 00:04:16 +01:00
parent 8316209c02
commit b33ef74d44
2 changed files with 6 additions and 4 deletions

View file

@ -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

View file

@ -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");
}