diff --git a/hmactest.c b/hmactest.c index 2ffe35e..fe9b4c2 100644 --- a/hmactest.c +++ b/hmactest.c @@ -44,8 +44,8 @@ int main(void) { hmac_sha256_compute(hmac_sha256_context, msg, sizeof(msg)-1); printf("HMAC-SHA256: "); - for (int i = 0; i < sizeof(hmac_sha256_context->u[0].ctx.hash); i++) { - printf("%02x", hmac_sha256_context->u[0].ctx.hash[i]); + for (int i = 0; i < sizeof(hmac_sha256_result(hmac_sha256_context)); i++) { + printf("%02x", hmac_sha256_result(hmac_sha256_context)[i]); } printf("\n"); @@ -54,8 +54,8 @@ int main(void) { hmac_sha1_compute(hmac_sha1_context, msg, sizeof(msg)-1); printf("HMAC-SHA1: "); - for (int i = 0; i < sizeof(hmac_sha1_context->u[0].ctx.hash); i++) { - printf("%02x", hmac_sha1_context->u[0].ctx.hash[i]); + for (int i = 0; i < sizeof(hmac_sha1_result(hmac_sha1_context)); i++) { + printf("%02x", hmac_sha1_result(hmac_sha1_context)[i]); } printf("\n"); @@ -64,8 +64,8 @@ int main(void) { hmac_md5_compute(hmac_md5_context, msg, sizeof(msg)-1); printf("HMAC-MD5: "); - for (int i = 0; i < sizeof(hmac_md5_context->u[0].ctx.hash); i++) { - printf("%02x", hmac_md5_context->u[0].ctx.hash[i]); + for (int i = 0; i < sizeof(hmac_md5_result(hmac_md5_context)); i++) { + printf("%02x", hmac_md5_result(hmac_md5_context)[i]); } printf("\n"); @@ -75,8 +75,8 @@ int main(void) { hmac_md4_compute(hmac_md4_context, msg, sizeof(msg)-1); printf("HMAC-MD4: "); - for (int i = 0; i < sizeof(hmac_md4_context->u[0].ctx.hash); i++) { - printf("%02x", hmac_md4_context->u[0].ctx.hash[i]); + for (int i = 0; i < sizeof(hmac_md4_result(hmac_md4_context)); i++) { + printf("%02x", hmac_md4_result(hmac_md4_context)[i]); } printf("\n"); @@ -86,8 +86,8 @@ int main(void) { hmac_sha256_finalize(hmac_sha256_context); printf("HMAC-SHA256 (incremental calculation): "); - for (int i = 0; i < sizeof(hmac_sha256_context->u[0].ctx.hash); i++) { - printf("%02x", hmac_sha256_context->u[0].ctx.hash[i]); + for (int i = 0; i < sizeof(hmac_sha256_result(hmac_sha256_context)); i++) { + printf("%02x", hmac_sha256_result(hmac_sha256_context)[i]); } printf("\n"); @@ -97,8 +97,8 @@ int main(void) { hmac_sha1_finalize(hmac_sha1_context); printf("HMAC-SHA1 (incremental calculation): "); - for (int i = 0; i < sizeof(hmac_sha1_context->u[0].ctx.hash); i++) { - printf("%02x", hmac_sha1_context->u[0].ctx.hash[i]); + for (int i = 0; i < sizeof(hmac_sha1_result(hmac_sha1_context)); i++) { + printf("%02x", hmac_sha1_result(hmac_sha1_context)[i]); } printf("\n"); @@ -108,8 +108,8 @@ int main(void) { hmac_md5_finalize(hmac_md5_context); printf("HMAC-MD5 (incremental calculation): "); - for (int i = 0; i < sizeof(hmac_md5_context->u[0].ctx.hash); i++) { - printf("%02x", hmac_md5_context->u[0].ctx.hash[i]); + for (int i = 0; i < sizeof(hmac_md5_result(hmac_md5_context)); i++) { + printf("%02x", hmac_md5_result(hmac_md5_context)[i]); } printf("\n"); @@ -119,8 +119,8 @@ int main(void) { hmac_md4_finalize(hmac_md4_context); printf("HMAC-MD4 (incremental calculation): "); - for (int i = 0; i < sizeof(hmac_md4_context->u[0].ctx.hash); i++) { - printf("%02x", hmac_md4_context->u[0].ctx.hash[i]); + for (int i = 0; i < sizeof(hmac_md4_result(hmac_md4_context)); i++) { + printf("%02x", hmac_md4_result(hmac_md4_context)[i]); } printf("\n"); } diff --git a/md4.h b/md4.h index 2909e53..31a5867 100644 --- a/md4.h +++ b/md4.h @@ -77,15 +77,19 @@ void hmac_md4_update(struct hmac_md4_context *context, /* * Finish HMAC-MD4 processing and generate the final HMAC. - * The result will be in context->u[0].ctx.hash. */ void hmac_md4_finalize(struct hmac_md4_context *context); /* * Compute the HMAC-MD4 of a message as a single operation. - * The result will be in context->u[0].ctx.hash. * The context can be reused for multiple hmac_md4_compute operations. */ void hmac_md4_compute(struct hmac_md4_context *context, const unsigned char *message, unsigned long message_length); + +/* + * Get the result of an HMAC-MD4 computation following hmac_md4_finalize + * or hmac_md4_compute. + */ +#define hmac_md4_result(context) ((context)->u[0].ctx.hash) diff --git a/md5.h b/md5.h index 282184d..3e3db53 100644 --- a/md5.h +++ b/md5.h @@ -77,15 +77,19 @@ void hmac_md5_update(struct hmac_md5_context *context, /* * Finish HMAC-MD5 processing and generate the final HMAC. - * The result will be in context->u[0].ctx.hash. */ void hmac_md5_finalize(struct hmac_md5_context *context); /* * Compute the HMAC-MD5 of a message as a single operation. - * The result will be in context->u[0].ctx.hash. * The context can be reused for multiple hmac_md5_compute operations. */ void hmac_md5_compute(struct hmac_md5_context *context, const unsigned char *message, unsigned long message_length); + +/* + * Get the result of an HMAC-MD5 computation following hmac_md5_finalize + * or hmac_md5_compute. + */ +#define hmac_md5_result(context) ((context)->u[0].ctx.hash) diff --git a/sha1.h b/sha1.h index d21668a..2cb7f22 100644 --- a/sha1.h +++ b/sha1.h @@ -77,15 +77,19 @@ void hmac_sha1_update(struct hmac_sha1_context *context, /* * Finish HMAC-SHA1 processing and generate the final HMAC. - * The result will be in context->u[0].ctx.hash. */ void hmac_sha1_finalize(struct hmac_sha1_context *context); /* * Compute the HMAC-SHA1 of a message as a single operation. - * The result will be in context->u[0].ctx.hash. * The context can be reused for multiple hmac_sha1_compute operations. */ void hmac_sha1_compute(struct hmac_sha1_context *context, const unsigned char *message, unsigned long message_length); + +/* + * Get the result of an HMAC-SHA1 computation following hmac_sha1_finalize + * or hmac_sha1_compute. + */ +#define hmac_sha1_result(context) ((context)->u[0].ctx.hash) diff --git a/sha256.h b/sha256.h index af87673..226d852 100644 --- a/sha256.h +++ b/sha256.h @@ -85,15 +85,19 @@ void hmac_sha256_update(struct hmac_sha256_context *context, /* * Finish HMAC-SHA256 processing and generate the final HMAC. - * The result will be in context->u[0].ctx.hash. */ void hmac_sha256_finalize(struct hmac_sha256_context *context); /* * Compute the HMAC-SHA256 of a message as a single operation. - * The result will be in context->u[0].ctx.hash. * The context can be reused for multiple hmac_sha256_compute operations. */ void hmac_sha256_compute(struct hmac_sha256_context *context, const unsigned char *message, unsigned long message_length); + +/* + * Get the result of an HMAC-SHA256 computation following hmac_sha256_finalize + * or hmac_sha256_compute. + */ +#define hmac_sha256_result(context) ((context)->u[0].ctx.hash)