- 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/include/polarssl/md.h b/include/polarssl/md.h
index 05f6eb0..76c480c 100644
--- a/include/polarssl/md.h
+++ b/include/polarssl/md.h
@@ -31,7 +31,8 @@
#define POLARSSL_MD_H
typedef enum {
- POLARSSL_MD_MD2=0,
+ POLARSSL_MD_NONE=0,
+ POLARSSL_MD_MD2,
POLARSSL_MD_MD4,
POLARSSL_MD_MD5,
POLARSSL_MD_SHA1,
@@ -149,6 +150,31 @@
const md_info_t *md_info_from_type( md_type_t md_type );
/**
+ * \brief Initialises and fills the message digest context structure with
+ * the appropriate values.
+ *
+ * \param ctx context to initialise. May not be NULL. The
+ * digest-specific context (ctx->md_ctx) must be NULL. It will
+ * be allocated, and must be freed using md_free_ctx() later.
+ * \param md_info message digest to use.
+ *
+ * \returns \c 0 on success, \c 1 on parameter failure, \c 2 if
+ * allocation of the cipher-specific context failed.
+ */
+int md_init_ctx( md_context_t *ctx, const md_info_t *md_info );
+
+/**
+ * \brief Free the message-specific context of ctx. Freeing ctx itself
+ * remains the responsibility of the caller.
+ *
+ * \param ctx Free the -specific context
+ * \param output Generic message digest checksum result
+ *
+ * \returns 0 on success, 1 if parameter verification fails.
+ */
+int md_free_ctx( md_context_t *ctx );
+
+/**
* \brief Returns the size of the message digest output.
*
* \param md_info message digest info
@@ -185,16 +211,13 @@
}
/**
- * \brief Generic message digest context setup.
+ * \brief Set-up the given context for a new message digest
*
- * \param md_info message digest info
- * \param ctx generic message digest context. May not be NULL. The
- * digest-specific context (ctx->md_ctx) must be NULL. It will
- * be allocated, and must be freed using md_free() later.
+ * \param ctx generic message digest context.
*
* \returns 0 on success, 1 if parameter verification fails.
*/
-int md_starts( const md_info_t *md_info, md_context_t *ctx );
+int md_starts( md_context_t *ctx );
/**
* \brief Generic message digest process buffer
@@ -218,17 +241,6 @@
int md_finish( md_context_t *ctx, unsigned char *output );
/**
- * \brief Free the message-specific context of ctx. Freeing ctx itself
- * remains the responsibility of the caller.
- *
- * \param ctx Free the -specific context
- * \param output Generic message digest checksum result
- *
- * \returns 0 on success, 1 if parameter verification fails.
- */
-int md_free_ctx( md_context_t *ctx );
-
-/**
* \brief Output = message_digest( input buffer )
*
* \param md_info message digest info
@@ -256,15 +268,13 @@
/**
* \brief Generic HMAC context setup
*
- * \param md_info message digest info
* \param ctx HMAC context to be initialized
* \param key HMAC secret key
* \param keylen length of the HMAC key
*
* \returns 0 on success, 1 if parameter verification fails.
*/
-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 );
/**
* \brief Generic HMAC process buffer