Finish removing HMAC from MD-light
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
diff --git a/include/mbedtls/md.h b/include/mbedtls/md.h
index 5ab0967..85d5c65 100644
--- a/include/mbedtls/md.h
+++ b/include/mbedtls/md.h
@@ -205,8 +205,10 @@
/** The digest-specific context (legacy) or the PSA operation. */
void *MBEDTLS_PRIVATE(md_ctx);
+#if defined(MBEDTLS_MD_C)
/** The HMAC part of the context. */
void *MBEDTLS_PRIVATE(hmac_ctx);
+#endif
} mbedtls_md_context_t;
/**
diff --git a/library/md.c b/library/md.c
index 0862fb0..bffedb3 100644
--- a/library/md.c
+++ b/library/md.c
@@ -287,11 +287,13 @@
mbedtls_free(ctx->md_ctx);
}
+#if defined(MBEDTLS_MD_C)
if (ctx->hmac_ctx != NULL) {
mbedtls_platform_zeroize(ctx->hmac_ctx,
2 * ctx->md_info->block_size);
mbedtls_free(ctx->hmac_ctx);
}
+#endif
mbedtls_platform_zeroize(ctx, sizeof(mbedtls_md_context_t));
}
@@ -380,7 +382,13 @@
ctx->md_info = md_info;
ctx->md_ctx = NULL;
+#if defined(MBEDTLS_MD_C)
ctx->hmac_ctx = NULL;
+#else
+ if (hmac != 0) {
+ return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
+ }
+#endif
#if defined(MBEDTLS_MD_SOME_PSA)
if (md_uses_psa(ctx->md_info)) {
@@ -431,6 +439,7 @@
return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
}
+#if defined(MBEDTLS_MD_C)
if (hmac != 0) {
ctx->hmac_ctx = mbedtls_calloc(2, md_info->block_size);
if (ctx->hmac_ctx == NULL) {
@@ -438,6 +447,7 @@
return MBEDTLS_ERR_MD_ALLOC_FAILED;
}
}
+#endif
return 0;
}