diff options
author | Niels Möller <nisse@lysator.liu.se> | 2004-01-08 13:37:13 +0100 |
---|---|---|
committer | Niels Möller <nisse@lysator.liu.se> | 2004-01-08 13:37:13 +0100 |
commit | 21ee1904b5c46f314b862eea33d3b86fcf6c7c88 (patch) | |
tree | 87460c8b18c74f6b20f94bac8e3cc1b378a6215f /bignum-random.c | |
parent | dcd5b982b7323a3834bbf43019dd8b30df7e71e4 (diff) | |
download | nettle-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 'bignum-random.c')
-rw-r--r-- | bignum-random.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/bignum-random.c b/bignum-random.c index 9b1a404b..16029216 100644 --- a/bignum-random.c +++ b/bignum-random.c @@ -32,6 +32,7 @@ #include <stdlib.h> #include "bignum.h" +#include "nettle-internal.h" void nettle_mpz_random_size(mpz_t x, @@ -39,7 +40,8 @@ nettle_mpz_random_size(mpz_t x, unsigned bits) { unsigned length = (bits + 7) / 8; - uint8_t *data = alloca(length); + TMP_DECL(data, uint8_t, NETTLE_MAX_BIGNUM_BITS / 8); + TMP_ALLOC(data, length); random(ctx, length, data); @@ -49,6 +51,7 @@ nettle_mpz_random_size(mpz_t x, mpz_fdiv_r_2exp(x, x, bits); } +/* Returns a random number x, 0 <= x < n */ void nettle_mpz_random(mpz_t x, void *ctx, nettle_random_func random, |