Introduce MD handle type
As has been previously done for ciphersuites, this commit introduces
a zero-cost abstraction layer around the type
mbedtls_md_info const *
whose valid values represent implementations of message digest algorithms.
Access to a particular digest implementation can be requested by name or
digest ID through the API mbedtls_md_info_from_xxx(), which either returns
a valid implementation or NULL, representing failure.
This commit replaces such uses of `mbedtls_md_info const *` by an abstract
type `mbedtls_md_handle_t` whose valid values represent digest implementations,
and which has a designated invalid value MBEDTLS_MD_INVALID_HANDLE.
The purpose of this abstraction layer is to pave the way for builds which
support precisely one digest algorithm. In this case, mbedtls_md_handle_t
can be implemented as a two-valued type, with one value representing the
invalid handle, and the unique valid value representing the unique enabled
digest.
diff --git a/tests/suites/test_suite_hkdf.function b/tests/suites/test_suite_hkdf.function
index 3e87207..7e83b57 100644
--- a/tests/suites/test_suite_hkdf.function
+++ b/tests/suites/test_suite_hkdf.function
@@ -25,8 +25,8 @@
*/
unsigned char okm_hex[257] = { '\0' };
- const mbedtls_md_info_t *md = mbedtls_md_info_from_type( md_alg );
- TEST_ASSERT( md != NULL );
+ mbedtls_md_handle_t md = mbedtls_md_info_from_type( md_alg );
+ TEST_ASSERT( md != MBEDTLS_MD_INVALID_HANDLE );
ikm_len = unhexify( ikm, hex_ikm_string );
salt_len = unhexify( salt, hex_salt_string );
@@ -54,8 +54,8 @@
unsigned char *output_prk = NULL;
size_t ikm_len, salt_len, prk_len, output_prk_len;
- const mbedtls_md_info_t *md = mbedtls_md_info_from_type( md_alg );
- TEST_ASSERT( md != NULL );
+ mbedtls_md_handle_t md = mbedtls_md_info_from_type( md_alg );
+ TEST_ASSERT( md != MBEDTLS_MD_INVALID_HANDLE );
output_prk_len = mbedtls_md_get_size( md );
output_prk = mbedtls_calloc( 1, output_prk_len );
@@ -90,8 +90,8 @@
unsigned char *output_okm = NULL;
size_t info_len, prk_len, okm_len;
- const mbedtls_md_info_t *md = mbedtls_md_info_from_type( md_alg );
- TEST_ASSERT( md != NULL );
+ mbedtls_md_handle_t md = mbedtls_md_info_from_type( md_alg );
+ TEST_ASSERT( md != MBEDTLS_MD_INVALID_HANDLE );
output_okm = mbedtls_calloc( OKM_LEN, 1 );