- Split current md_starts() and md_hmac_starts() functionality into separate md_init_ctx() for allocating the context and the existing starts() functions to initialize the message digest for use.

diff --git a/library/md.c b/library/md.c
index 9aa7b38..6348271 100644
--- a/library/md.c
+++ b/library/md.c
@@ -147,7 +147,7 @@
     }
 }
 
-int md_starts( const md_info_t *md_info, md_context_t *ctx )
+int md_init_ctx( md_context_t *ctx, const md_info_t *md_info )
 {
     if( md_info == NULL )
         return 1;
@@ -165,6 +165,27 @@
     return 0;
 }
 
+int md_free_ctx( md_context_t *ctx )
+{
+    if( ctx == NULL || ctx->md_info == NULL )
+        return 1;
+
+    ctx->md_info->ctx_free_func( ctx->md_ctx );
+    ctx->md_ctx = NULL;
+
+    return 0;
+}
+
+int md_starts( md_context_t *ctx )
+{
+    if( ctx == NULL || ctx->md_info == NULL )
+        return 1;
+
+    ctx->md_info->starts_func( ctx->md_ctx );
+
+    return 0;
+}
+
 int md_update( md_context_t *ctx, const unsigned char *input, int ilen )
 {
     if( ctx == NULL || ctx->md_info == NULL )
@@ -185,16 +206,6 @@
     return 0;
 }
 
-int md_free_ctx( md_context_t *ctx )
-{
-    if( ctx == NULL || ctx->md_info == NULL )
-        return 1;
-
-    ctx->md_info->ctx_free_func( ctx->md_ctx );
-
-    return 0;
-}
-
 int md( const md_info_t *md_info, const unsigned char *input, int ilen,
             unsigned char *output )
 {
@@ -214,21 +225,12 @@
     return md_info->file_func( path, output );
 }
 
-int md_hmac_starts( const md_info_t *md_info, md_context_t *ctx,
-                        const unsigned char *key, int keylen )
+int md_hmac_starts( md_context_t *ctx, const unsigned char *key, int keylen )
 {
-    if(md_info == NULL )
+    if( ctx == NULL || ctx->md_info == NULL )
         return 1;
 
-    if( ctx == NULL || ctx->md_ctx != NULL )
-        return 1;
-
-    if( ( ctx->md_ctx = md_info->ctx_alloc_func() ) == NULL )
-        return 1;
-
-    ctx->md_info = md_info;
-
-    md_info->hmac_starts_func( ctx->md_ctx, key, keylen);
+    ctx->md_info->hmac_starts_func( ctx->md_ctx, key, keylen);
 
     return 0;
 }