- Added reset functionality for HMAC context. Speed-up for some use-cases.
diff --git a/library/md2.c b/library/md2.c
index 061ebbe..3a0d1f5 100644
--- a/library/md2.c
+++ b/library/md2.c
@@ -261,6 +261,15 @@
}
/*
+ * MD2 HMAC context reset
+ */
+void md2_hmac_reset( md2_context *ctx )
+{
+ md2_starts( ctx );
+ md2_update( ctx, ctx->ipad, 64 );
+}
+
+/*
* output = HMAC-MD2( hmac key, input buffer )
*/
void md2_hmac( const unsigned char *key, int keylen,
diff --git a/library/md4.c b/library/md4.c
index 251e63f..564a7f9 100644
--- a/library/md4.c
+++ b/library/md4.c
@@ -357,6 +357,15 @@
}
/*
+ * MD4 HMAC context reset
+ */
+void md4_hmac_reset( md4_context *ctx )
+{
+ md4_starts( ctx );
+ md4_update( ctx, ctx->ipad, 64 );
+}
+
+/*
* output = HMAC-MD4( hmac key, input buffer )
*/
void md4_hmac( const unsigned char *key, int keylen,
diff --git a/library/md5.c b/library/md5.c
index ca994b9..5ab3383 100644
--- a/library/md5.c
+++ b/library/md5.c
@@ -376,6 +376,15 @@
}
/*
+ * MD5 HMAC context reset
+ */
+void md5_hmac_reset( md5_context *ctx )
+{
+ md5_starts( ctx );
+ md5_update( ctx, ctx->ipad, 64 );
+}
+
+/*
* output = HMAC-MD5( hmac key, input buffer )
*/
void md5_hmac( const unsigned char *key, int keylen,
diff --git a/library/sha1.c b/library/sha1.c
index f811131..7f8ec63 100644
--- a/library/sha1.c
+++ b/library/sha1.c
@@ -411,6 +411,15 @@
}
/*
+ * SHA1 HMAC context reset
+ */
+void sha1_hmac_reset( sha1_context *ctx )
+{
+ sha1_starts( ctx );
+ sha1_update( ctx, ctx->ipad, 64 );
+}
+
+/*
* output = HMAC-SHA-1( hmac key, input buffer )
*/
void sha1_hmac( const unsigned char *key, int keylen,
diff --git a/library/sha2.c b/library/sha2.c
index 87f02ea..8f920ce 100644
--- a/library/sha2.c
+++ b/library/sha2.c
@@ -418,6 +418,15 @@
}
/*
+ * SHA-256 HMAC context reset
+ */
+void sha2_hmac_reset( sha2_context *ctx )
+{
+ sha2_starts( ctx, ctx->is224 );
+ sha2_update( ctx, ctx->ipad, 64 );
+}
+
+/*
* output = HMAC-SHA-256( hmac key, input buffer )
*/
void sha2_hmac( const unsigned char *key, int keylen,
diff --git a/library/sha4.c b/library/sha4.c
index c214543..699cca7 100644
--- a/library/sha4.c
+++ b/library/sha4.c
@@ -417,6 +417,15 @@
}
/*
+ * SHA-512 HMAC context reset
+ */
+void sha4_hmac_reset( sha4_context *ctx )
+{
+ sha4_starts( ctx, ctx->is384 );
+ sha4_update( ctx, ctx->ipad, 128 );
+}
+
+/*
* output = HMAC-SHA-512( hmac key, input buffer )
*/
void sha4_hmac( const unsigned char *key, int keylen,