diff options
author | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2013-09-21 13:54:38 +0300 |
---|---|---|
committer | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2013-09-21 14:05:50 +0300 |
commit | 7409de7bc28ff8847c9d71d8c3e35e1968d59d60 (patch) | |
tree | dec988c7300af9380e3f442848aacbf02418f131 /cipher/gostr3411-94.c | |
parent | 592c2ab3deeeccbb6d3b078ed7bf0e6627c8e1fb (diff) | |
download | libgcrypt-7409de7bc28ff8847c9d71d8c3e35e1968d59d60.tar.gz |
gostr3411_94: set better burn stack depth estimate
* cipher/gost28147.c (_gcry_gost_enc_one): Account function stack to
burn stack depth.
* cipher/gostr3411-94.c (max): New macro.
(do_hash_step, transform): Return stack burn depth.
--
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
Diffstat (limited to 'cipher/gostr3411-94.c')
-rw-r--r-- | cipher/gostr3411-94.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/cipher/gostr3411-94.c b/cipher/gostr3411-94.c index bfd52bd8..368fc015 100644 --- a/cipher/gostr3411-94.c +++ b/cipher/gostr3411-94.c @@ -30,6 +30,8 @@ #include "gost.h" +#define max(a, b) (((a) > (b)) ? (a) : (b)) + typedef struct { gcry_md_block_ctx_t bctx; GOST28147_context hd; @@ -148,11 +150,12 @@ do_add (unsigned char *s, unsigned char *a) } } -static void +static unsigned int do_hash_step (GOST28147_context *hd, unsigned char *h, unsigned char *m) { unsigned char u[32], v[32], s[32]; unsigned char k[32]; + unsigned int burn; int i; memcpy (u, h, 32); @@ -161,7 +164,7 @@ do_hash_step (GOST28147_context *hd, unsigned char *h, unsigned char *m) for (i = 0; i < 4; i++) { do_p (k, u, v); - _gcry_gost_enc_one (hd, k, s + i*8, h + i*8); + burn = _gcry_gost_enc_one (hd, k, s + i*8, h + i*8); do_a (u); if (i == 1) @@ -198,6 +201,12 @@ do_hash_step (GOST28147_context *hd, unsigned char *h, unsigned char *m) memcpy (h, s+20, 12); memcpy (h+12, s, 20); + + return /* burn_stack */ 4 * sizeof(void*) /* func call (ret addr + args) */ + + 4 * 32 + 2 * sizeof(int) /* stack */ + + max(burn /* _gcry_gost_enc_one */, + sizeof(void*) * 2 /* do_a2 call */ + + 16 + sizeof(int) /* do_a2 stack */ ); } @@ -206,13 +215,13 @@ transform (void *ctx, const unsigned char *data) { GOSTR3411_CONTEXT *hd = ctx; byte m[32]; + unsigned int burn; memcpy (m, data, 32); - do_hash_step (&hd->hd, hd->h, m); + burn = do_hash_step (&hd->hd, hd->h, m); do_add (hd->sigma, m); -/* FIXME: Fix this arbitrary value for the stack_burn size. -wk */ - return /* stack_burn */ 200; + return /* burn_stack */ burn + 3 * sizeof(void*) + 32 + 2 * sizeof(void*); } /* |