summaryrefslogtreecommitdiff
path: root/cipher/sha256.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/sha256.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/sha256.c')
-rw-r--r--cipher/sha256.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/cipher/sha256.c b/cipher/sha256.c
index 17856994..cf23f2f4 100644
--- a/cipher/sha256.c
+++ b/cipher/sha256.c
@@ -50,9 +50,10 @@ typedef struct {
u32 h0,h1,h2,h3,h4,h5,h6,h7;
} SHA256_CONTEXT;
-static void
+static unsigned int
transform (void *c, const unsigned char *data);
+
static void
sha256_init (void *context)
{
@@ -70,7 +71,6 @@ sha256_init (void *context)
hd->bctx.nblocks = 0;
hd->bctx.count = 0;
hd->bctx.blocksize = 64;
- hd->bctx.stack_burn = 74*4+32;
hd->bctx.bwrite = transform;
}
@@ -92,7 +92,6 @@ sha224_init (void *context)
hd->bctx.nblocks = 0;
hd->bctx.count = 0;
hd->bctx.blocksize = 64;
- hd->bctx.stack_burn = 74*4+32;
hd->bctx.bwrite = transform;
}
@@ -145,7 +144,7 @@ Sum1 (u32 x)
}
-static void
+static unsigned int
transform (void *ctx, const unsigned char *data)
{
SHA256_CONTEXT *hd = ctx;
@@ -261,6 +260,8 @@ transform (void *ctx, const unsigned char *data)
hd->h5 += f;
hd->h6 += g;
hd->h7 += h;
+
+ return /*burn_stack*/ 74*4+32;
}
#undef S0
#undef S1
@@ -278,6 +279,7 @@ sha256_final(void *context)
SHA256_CONTEXT *hd = context;
u32 t, msb, lsb;
byte *p;
+ unsigned int burn;
_gcry_md_block_write (hd, NULL, 0); /* flush */;
@@ -318,8 +320,8 @@ sha256_final(void *context)
hd->bctx.buf[61] = lsb >> 16;
hd->bctx.buf[62] = lsb >> 8;
hd->bctx.buf[63] = lsb;
- transform (hd, hd->bctx.buf);
- _gcry_burn_stack (74*4+32);
+ burn = transform (hd, hd->bctx.buf);
+ _gcry_burn_stack (burn);
p = hd->bctx.buf;
#ifdef WORDS_BIGENDIAN