Define "light" subset of MD
See docs/architecture/psa-migration/md-cipher-dispatch.md
Regarding testing, the no_md component was never very useful, as that's
not something people are likely to want to do: it was mostly useful as
executable documentation of what depends on MD. It's going to be even
less useful when more and more modules auto-enable MD_LIGHT or even
MD_C. So, recycle it to test the build with only MD_LIGHT, which is
something that might happen in practice, and is necessary to ensure that
the division is consistent.
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
diff --git a/library/md.c b/library/md.c
index dd5553a..8aecd39 100644
--- a/library/md.c
+++ b/library/md.c
@@ -23,7 +23,7 @@
#include "common.h"
-#if defined(MBEDTLS_MD_C)
+#if defined(MBEDTLS_MD_LIGHT)
#include "mbedtls/md.h"
#include "md_wrap.h"
@@ -110,6 +110,7 @@
/*
* Reminder: update profiles in x509_crt.c when adding a new hash!
*/
+#if defined(MBEDTLS_MD_C)
static const int supported_digests[] = {
#if defined(MBEDTLS_SHA512_C)
@@ -191,6 +192,7 @@
#endif
return NULL;
}
+#endif /* MBEDTLS_MD_C */
const mbedtls_md_info_t *mbedtls_md_info_from_type(mbedtls_md_type_t md_type)
{
@@ -228,6 +230,7 @@
}
}
+#if defined(MBEDTLS_MD_C)
const mbedtls_md_info_t *mbedtls_md_info_from_ctx(
const mbedtls_md_context_t *ctx)
{
@@ -237,6 +240,7 @@
return ctx->MBEDTLS_PRIVATE(md_info);
}
+#endif /* MBEDTLS_MD_C */
void mbedtls_md_init(mbedtls_md_context_t *ctx)
{
@@ -586,7 +590,7 @@
}
}
-#if defined(MBEDTLS_FS_IO)
+#if defined(MBEDTLS_FS_IO) && defined(MBEDTLS_MD_C)
int mbedtls_md_file(const mbedtls_md_info_t *md_info, const char *path, unsigned char *output)
{
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
@@ -635,8 +639,9 @@
return ret;
}
-#endif /* MBEDTLS_FS_IO */
+#endif /* MBEDTLS_FS_IO && MBEDTLS_MD_C */
+#if defined(MBEDTLS_MD_C)
int mbedtls_md_hmac_starts(mbedtls_md_context_t *ctx, const unsigned char *key, size_t keylen)
{
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
@@ -773,6 +778,7 @@
return ret;
}
+#endif /* MBEDTLS_MD_C */
unsigned char mbedtls_md_get_size(const mbedtls_md_info_t *md_info)
{
@@ -792,6 +798,7 @@
return md_info->type;
}
+#if defined(MBEDTLS_MD_C)
const char *mbedtls_md_get_name(const mbedtls_md_info_t *md_info)
{
if (md_info == NULL) {
@@ -800,5 +807,6 @@
return md_info->name;
}
-
#endif /* MBEDTLS_MD_C */
+
+#endif /* MBEDTLS_MD_LIGHT */