diff options
author | Niels Möller <nisse@lysator.liu.se> | 2004-01-08 13:34:57 +0100 |
---|---|---|
committer | Niels Möller <nisse@lysator.liu.se> | 2004-01-08 13:34:57 +0100 |
commit | dcd5b982b7323a3834bbf43019dd8b30df7e71e4 (patch) | |
tree | bb192ee6147c8c3080c309a838719d4e9030c90f /nettle-internal.h | |
parent | d1573de9cae8497e185c48ecf070746619a39197 (diff) | |
download | nettle-dcd5b982b7323a3834bbf43019dd8b30df7e71e4.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.
Rev: src/nettle/nettle-internal.h:1.4
Diffstat (limited to 'nettle-internal.h')
-rw-r--r-- | nettle-internal.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/nettle-internal.h b/nettle-internal.h index 670d4373..a814ed70 100644 --- a/nettle-internal.h +++ b/nettle-internal.h @@ -29,6 +29,29 @@ #include "nettle-meta.h" +/* Temporary allocation, for systems that don't support alloca. Note + * that the allocation requests should always be reasonably small, so + * that they can fit on the stack. For non-alloca systems, we use a + * fix maximum size, and abort if we ever need anything larger. */ + +#if HAVE_ALLOCA +# define TMP_DECL(name, type, max) \ +type *name +# define TMP_ALLOC(name, size) \ +(name = alloca(sizeof (*name) * size)) +#else /* !HAVE_ALLOCA */ +# define TMP_DECL(name, type, max) \ +type name[max] +# define TMP_ALLOC(name, size) \ +do { if (size > (sizeof(name) / sizeof(name[0]))) abort(); } while (0) +#endif + +/* Arbitrary limits which apply to systems that don't have alloca */ +#define NETTLE_MAX_BIGNUM_BITS 10000 +#define NETTLE_MAX_HASH_BLOCK_SIZE 64 +#define NETTLE_MAX_HASH_DIGEST_SIZE 32 +#define NETTLE_MAX_SEXP_ASSOC 17 + /* Doesn't quite fit with the other algorithms, because of the weak * keys. Weak keys are not reported, the functions will simply crash * if you try to use a weak key. */ |