dlopen-test: Use libnettle.dylib on MacOS.
[gd/nettle] / nettle-internal.h
1 /* nettle-internal.h
2
3    Things that are used only by the testsuite and benchmark, and
4    not included in the library.
5
6    Copyright (C) 2002, 2014 Niels Möller
7
8    This file is part of GNU Nettle.
9
10    GNU Nettle is free software: you can redistribute it and/or
11    modify it under the terms of either:
12
13      * the GNU Lesser General Public License as published by the Free
14        Software Foundation; either version 3 of the License, or (at your
15        option) any later version.
16
17    or
18
19      * the GNU General Public License as published by the Free
20        Software Foundation; either version 2 of the License, or (at your
21        option) any later version.
22
23    or both in parallel, as here.
24
25    GNU Nettle is distributed in the hope that it will be useful,
26    but WITHOUT ANY WARRANTY; without even the implied warranty of
27    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
28    General Public License for more details.
29
30    You should have received copies of the GNU General Public License and
31    the GNU Lesser General Public License along with this program.  If
32    not, see http://www.gnu.org/licenses/.
33 */
34
35 #ifndef NETTLE_INTERNAL_H_INCLUDED
36 #define NETTLE_INTERNAL_H_INCLUDED
37
38 #include <assert.h>
39
40 #include "nettle-meta.h"
41
42 /* For definition of NETTLE_MAX_HASH_CONTEXT_SIZE. */
43 #include "sha3.h"
44
45 /* Temporary allocation, for systems that don't support alloca. Note
46  * that the allocation requests should always be reasonably small, so
47  * that they can fit on the stack. For non-alloca systems, we use a
48  * fix maximum size + an assert.
49  *
50  * TMP_DECL and TMP_ALLOC allocate an array of the given type, and
51  * take the array size (not byte size) as argument.
52  *
53  * TMP_DECL_ALIGN and TMP_ALLOC_ALIGN are intended for context
54  * structs, which need proper alignment. They take the size in bytes,
55  * and produce a void *. On systems without alloca, implemented as an
56  * array of uint64_t, to ensure alignment. Since it is used as void *
57  * argument, no type casts are needed.
58  */
59
60 #if HAVE_ALLOCA
61 # define TMP_DECL(name, type, max) type *name
62 # define TMP_ALLOC(name, size) (name = alloca(sizeof (*name) * (size)))
63 # define TMP_DECL_ALIGN(name, max) void *name
64 # define TMP_ALLOC_ALIGN(name, size) (name = alloca(size))
65 #else /* !HAVE_ALLOCA */
66 # define TMP_DECL(name, type, max) type name[max]
67 # define TMP_ALLOC(name, size) \
68   do { assert((size_t)(size) <= (sizeof(name) / sizeof(name[0]))); } while (0)
69 # define TMP_DECL_ALIGN(name, max) \
70   uint64_t name[((max) + (sizeof(uint64_t) - 1))/ sizeof(uint64_t)]
71 # define TMP_ALLOC_ALIGN(name, size) \
72   do { assert((size_t)(size) <= (sizeof(name))); } while (0)
73 #endif 
74
75 /* Arbitrary limits which apply to systems that don't have alloca */
76 #define NETTLE_MAX_HASH_BLOCK_SIZE 128
77 #define NETTLE_MAX_HASH_DIGEST_SIZE 64
78 #define NETTLE_MAX_HASH_CONTEXT_SIZE (sizeof(struct sha3_224_ctx))
79 #define NETTLE_MAX_SEXP_ASSOC 17
80 #define NETTLE_MAX_CIPHER_BLOCK_SIZE 32
81
82 /* Doesn't quite fit with the other algorithms, because of the weak
83  * keys. Weak keys are not reported, the functions will simply crash
84  * if you try to use a weak key. */
85
86 extern const struct nettle_cipher nettle_des;
87 extern const struct nettle_cipher nettle_des3;
88
89 extern const struct nettle_cipher nettle_blowfish128;
90
91 extern const struct nettle_cipher nettle_unified_aes128;
92 extern const struct nettle_cipher nettle_unified_aes192;
93 extern const struct nettle_cipher nettle_unified_aes256;
94
95 /* Stream ciphers treated as aead algorithms with no authentication. */
96 extern const struct nettle_aead nettle_arcfour128;
97 extern const struct nettle_aead nettle_chacha;
98 extern const struct nettle_aead nettle_salsa20;
99 extern const struct nettle_aead nettle_salsa20r12;
100 extern const struct nettle_aead nettle_openssl_gcm_aes128;
101 extern const struct nettle_aead nettle_openssl_gcm_aes192;
102 extern const struct nettle_aead nettle_openssl_gcm_aes256;
103
104 /* Glue to openssl, for comparative benchmarking. Code in
105  * examples/nettle-openssl.c. */
106 extern void nettle_openssl_init(void);
107 extern const struct nettle_cipher nettle_openssl_aes128;
108 extern const struct nettle_cipher nettle_openssl_aes192;
109 extern const struct nettle_cipher nettle_openssl_aes256;
110 extern const struct nettle_cipher nettle_openssl_blowfish128;
111 extern const struct nettle_cipher nettle_openssl_des;
112 extern const struct nettle_cipher nettle_openssl_cast128;
113 extern const struct nettle_aead nettle_openssl_arcfour128;
114
115 extern const struct nettle_hash nettle_openssl_md5;
116 extern const struct nettle_hash nettle_openssl_sha1;
117
118 extern const struct nettle_hash * const _nettle_hashes[];
119
120 #endif /* NETTLE_INTERNAL_H_INCLUDED */