summaryrefslogtreecommitdiff
path: root/cipher/md5.c
diff options
context:
space:
mode:
authorJussi Kivilinna <jussi.kivilinna@iki.fi>2013-09-21 13:54:38 +0300
committerJussi Kivilinna <jussi.kivilinna@iki.fi>2013-09-21 13:54:38 +0300
commit592c2ab3deeeccbb6d3b078ed7bf0e6627c8e1fb (patch)
tree067ff9ba60af04b9570da3f54c3ff6c992650a90 /cipher/md5.c
parent902ea6052c11108bd19333c31b03e084bed1fb86 (diff)
downloadlibgcrypt-592c2ab3deeeccbb6d3b078ed7bf0e6627c8e1fb.tar.gz
Use hash transform function return type for passing burn stack depth
* cipher/gostr4311-94.c (transform): Return stack burn depth. * cipher/hash-common.c (_gcry_md_block_write): Use stack burn depth returned by 'hd->bwrite'. * cipher/hash-common.h (_gcry_md_block_write_t): Change return type to 'unsigned int'. (gry_md_block_ctx_t): Remove 'stack_burn'. * cipher/md4.c (transform): Return stack burn depth. (md4_final): Use stack burn depth from transform. * cipher/md5.c (transform): Return stack burn depth. (md5_final): Use stack burn depth from transform. * cipher/rmd160.c (transform): Return stack burn depth. (rmd160_final): Use stack burn depth from transform. * cipher/sha1.c (transform): Return stack burn depth. (sha1_final): Use stack burn depth from transform. * cipher/sha256.c (transform): Return stack burn depth. (sha256_final): Use stack burn depth from transform. * cipher/sha512.c (__transform, transform): Return stack burn depth. (sha512_final): Use stack burn depth from transform. * cipher/stribog.c (transform64): Return stack burn depth. * cipher/tiger.c (transform): Return stack burn depth. (tiger_final): Use stack burn depth from transform. -- Transform function might want different depth of stack burn depending on detected CPU features (like in SHA-512 on ARM with NEON). So return stack burn depth from transform functions as a request or a hint to calling function. Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
Diffstat (limited to 'cipher/md5.c')
-rw-r--r--cipher/md5.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/cipher/md5.c b/cipher/md5.c
index 9857f2c8..88745a81 100644
--- a/cipher/md5.c
+++ b/cipher/md5.c
@@ -48,7 +48,7 @@ typedef struct {
u32 A,B,C,D; /* chaining variables */
} MD5_CONTEXT;
-static void
+static unsigned int
transform ( void *ctx, const unsigned char *data );
static void
@@ -64,7 +64,6 @@ md5_init( void *context )
ctx->bctx.nblocks = 0;
ctx->bctx.count = 0;
ctx->bctx.blocksize = 64;
- ctx->bctx.stack_burn = 80+6*sizeof(void*);
ctx->bctx.bwrite = transform;
}
@@ -82,7 +81,7 @@ md5_init( void *context )
/****************
* transform n*64 bytes
*/
-static void
+static unsigned int
transform ( void *c, const unsigned char *data )
{
MD5_CONTEXT *ctx = c;
@@ -213,6 +212,8 @@ transform ( void *c, const unsigned char *data )
ctx->B += B;
ctx->C += C;
ctx->D += D;
+
+ return /*burn_stack*/ 80+6*sizeof(void*);
}
@@ -229,6 +230,7 @@ md5_final( void *context)
MD5_CONTEXT *hd = context;
u32 t, msb, lsb;
byte *p;
+ unsigned int burn;
_gcry_md_block_write(hd, NULL, 0); /* flush */;
@@ -269,8 +271,8 @@ md5_final( void *context)
hd->bctx.buf[61] = msb >> 8;
hd->bctx.buf[62] = msb >> 16;
hd->bctx.buf[63] = msb >> 24;
- transform( hd, hd->bctx.buf );
- _gcry_burn_stack (80+6*sizeof(void*));
+ burn = transform( hd, hd->bctx.buf );
+ _gcry_burn_stack (burn);
p = hd->bctx.buf;
#ifdef WORDS_BIGENDIAN