MD: Demonstrate config-dep'n API inlining for mbedtls_md_starts()
diff --git a/include/mbedtls/md.h b/include/mbedtls/md.h
index 120473d..b1caca8 100644
--- a/include/mbedtls/md.h
+++ b/include/mbedtls/md.h
@@ -82,6 +82,8 @@
 
 #if !defined(MBEDTLS_MD_SINGLE_HASH)
 
+#define MBEDTLS_MD_INLINABLE_API
+
 /**
  * Opaque struct defined in md.c.
  */
@@ -93,6 +95,8 @@
 
 #else /* !MBEDTLS_MD_SINGLE_HASH */
 
+#define MBEDTLS_MD_INLINABLE_API MBEDTLS_ALWAYS_INLINE static inline
+
 typedef int mbedtls_md_handle_t;
 #define MBEDTLS_MD_INVALID_HANDLE       ( (mbedtls_md_handle_t) 0 )
 #define MBEDTLS_MD_UNIQUE_VALID_HANDLE  ( (mbedtls_md_handle_t) 1 )
@@ -308,7 +312,7 @@
  * \return          #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
  *                  failure.
  */
-int mbedtls_md_starts( mbedtls_md_context_t *ctx );
+MBEDTLS_MD_INLINABLE_API int mbedtls_md_starts( mbedtls_md_context_t *ctx );
 
 /**
  * \brief           This function feeds an input buffer into an ongoing
@@ -500,6 +504,34 @@
 /* Internal use */
 int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
 
+/*
+ * Internal wrapper functions for those MD API functions which should be
+ * inlined in some but not all configurations. The actual MD API will be
+ * implemented either here or in md.c, and forward to the wrappers.
+ */
+
+MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_starts_internal(
+    mbedtls_md_context_t *ctx )
+{
+    mbedtls_md_handle_t md_info;
+    if( ctx == NULL )
+        return( MBEDTLS_ERR_MD_BAD_INPUT_DATA );
+
+    md_info = mbedtls_md_get_handle( ctx );
+    if( md_info == MBEDTLS_MD_INVALID_HANDLE )
+        return( MBEDTLS_ERR_MD_BAD_INPUT_DATA );
+
+    return( mbedtls_md_info_starts( md_info, ctx->md_ctx ) );
+}
+
+#if defined(MBEDTLS_MD_SINGLE_HASH)
+MBEDTLS_MD_INLINABLE_API int mbedtls_md_starts(
+    mbedtls_md_context_t *ctx )
+{
+    return( mbedtls_md_starts_internal( ctx ) );
+}
+#endif /* MBEDTLS_MD_SINGLE_HASH */
+
 #ifdef __cplusplus
 }
 #endif