Allow defining MD information structs through macros
In builds enabling only a single MD digest, we want to be able to
implement the MD info getter functions by returning compile-time
constants matching the fields of the MD info structures used so far.
To avoid information duplication hardening maintainability, this
commit introduces the possibility of providing the various aspects
of a particular digest implementation by defining macros
MBEDTLS_MD_INFO_DIGEST_FIELD (e.g. MBEDTLS_MD_INFO_SHA256_SIZE)
and to generate the corresponding mbedtls_md_info instance from
this set of macros, via the new macro MBEDTLS_MD_INFO().
This way, we'll be able to switch between MD info based builds
and single-digest builds without information duplication.
diff --git a/library/md_wrap.c b/library/md_wrap.c
index 0f8132f..f974ba0 100644
--- a/library/md_wrap.c
+++ b/library/md_wrap.c
@@ -475,20 +475,8 @@
return( mbedtls_sha256_ret( input, ilen, output, 0 ) );
}
-const mbedtls_md_info_t mbedtls_sha256_info = {
- MBEDTLS_MD_SHA256,
- "SHA256",
- 32,
- 64,
- sha256_starts_wrap,
- sha224_update_wrap,
- sha224_finish_wrap,
- sha256_wrap,
- sha224_ctx_alloc,
- sha224_ctx_free,
- sha224_clone_wrap,
- sha224_process_wrap,
-};
+const mbedtls_md_info_t mbedtls_sha256_info =
+ MBEDTLS_MD_INFO( MBEDTLS_MD_INFO_SHA256 );
#endif /* MBEDTLS_SHA256_C */