summaryrefslogtreecommitdiff
path: root/hmac.c
diff options
context:
space:
mode:
authorNiels Möller <nisse@lysator.liu.se>2004-01-08 13:37:13 +0100
committerNiels Möller <nisse@lysator.liu.se>2004-01-08 13:37:13 +0100
commit21ee1904b5c46f314b862eea33d3b86fcf6c7c88 (patch)
tree87460c8b18c74f6b20f94bac8e3cc1b378a6215f /hmac.c
parentdcd5b982b7323a3834bbf43019dd8b30df7e71e4 (diff)
downloadnettle-21ee1904b5c46f314b862eea33d3b86fcf6c7c88.tar.gz
(TMP_DECL, TMP_ALLOC): New macros. When alloca is unavailable, they
work by allocating a fix amount of stack and imposing a hard limit on what can be allocated. Updated all users of alloca. Rev: src/nettle/bignum-random.c:1.4 Rev: src/nettle/cbc.c:1.8 Rev: src/nettle/dsa-keygen.c:1.7 Rev: src/nettle/hmac.c:1.6 Rev: src/nettle/pkcs1-rsa-md5.c:1.3 Rev: src/nettle/pkcs1-rsa-sha1.c:1.3 Rev: src/nettle/rsa-decrypt.c:1.5 Rev: src/nettle/rsa-encrypt.c:1.8 Rev: src/nettle/sexp.c:1.15
Diffstat (limited to 'hmac.c')
-rw-r--r--hmac.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/hmac.c b/hmac.c
index 5ffae38b..2534fc14 100644
--- a/hmac.c
+++ b/hmac.c
@@ -33,6 +33,7 @@
#include "hmac.h"
#include "memxor.h"
+#include "nettle-internal.h"
#define IPAD 0x36
#define OPAD 0x5c
@@ -42,7 +43,8 @@ hmac_set_key(void *outer, void *inner, void *state,
const struct nettle_hash *hash,
unsigned key_length, const uint8_t *key)
{
- uint8_t *pad = alloca(hash->block_size);
+ TMP_DECL(pad, uint8_t, NETTLE_MAX_HASH_BLOCK_SIZE);
+ TMP_ALLOC(pad, hash->block_size);
hash->init(outer);
hash->init(inner);
@@ -52,7 +54,8 @@ hmac_set_key(void *outer, void *inner, void *state,
/* Reduce key to the algorithm's hash size. Use the area pointed
* to by state for the temporary state. */
- uint8_t *digest = alloca(hash->digest_size);
+ TMP_DECL(digest, uint8_t, NETTLE_MAX_HASH_DIGEST_SIZE);
+ TMP_ALLOC(digest, hash->digest_size);
hash->init(state);
hash->update(state, key_length, key);
@@ -90,7 +93,8 @@ hmac_digest(const void *outer, const void *inner, void *state,
const struct nettle_hash *hash,
unsigned length, uint8_t *dst)
{
- uint8_t *digest = alloca(hash->digest_size);
+ TMP_DECL(digest, uint8_t, NETTLE_MAX_HASH_DIGEST_SIZE);
+ TMP_ALLOC(digest, hash->digest_size);
hash->digest(state, hash->digest_size, digest);