Merge branch 'delete-nettle-stdint-h' into master
[gd/nettle] / nettle-meta.h
1 /* nettle-meta.h
2
3    Information about algorithms.
4
5    Copyright (C) 2002, 2014 Niels Möller
6
7    This file is part of GNU Nettle.
8
9    GNU Nettle is free software: you can redistribute it and/or
10    modify it under the terms of either:
11
12      * the GNU Lesser General Public License as published by the Free
13        Software Foundation; either version 3 of the License, or (at your
14        option) any later version.
15
16    or
17
18      * the GNU General Public License as published by the Free
19        Software Foundation; either version 2 of the License, or (at your
20        option) any later version.
21
22    or both in parallel, as here.
23
24    GNU Nettle is distributed in the hope that it will be useful,
25    but WITHOUT ANY WARRANTY; without even the implied warranty of
26    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
27    General Public License for more details.
28
29    You should have received copies of the GNU General Public License and
30    the GNU Lesser General Public License along with this program.  If
31    not, see http://www.gnu.org/licenses/.
32 */
33
34 #ifndef NETTLE_META_H_INCLUDED
35 #define NETTLE_META_H_INCLUDED
36
37 #include "nettle-types.h"
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43
44 struct nettle_cipher
45 {
46   const char *name;
47   
48   unsigned context_size;
49   
50   /* Zero for stream ciphers */
51   unsigned block_size;
52
53   /* Suggested key size; other sizes are sometimes possible. */
54   unsigned key_size;
55
56   nettle_set_key_func *set_encrypt_key;
57   nettle_set_key_func *set_decrypt_key;
58
59   nettle_cipher_func *encrypt;
60   nettle_cipher_func *decrypt;
61 };
62
63 /* null-terminated list of ciphers implemented by this version of nettle */
64 const struct nettle_cipher * const * _NETTLE_ATTRIBUTE_PURE
65 nettle_get_ciphers (void);
66
67 #define nettle_ciphers (nettle_get_ciphers())
68
69 extern const struct nettle_cipher nettle_aes128;
70 extern const struct nettle_cipher nettle_aes192;
71 extern const struct nettle_cipher nettle_aes256;
72
73 extern const struct nettle_cipher nettle_camellia128;
74 extern const struct nettle_cipher nettle_camellia192;
75 extern const struct nettle_cipher nettle_camellia256;
76
77 extern const struct nettle_cipher nettle_cast128;
78
79 extern const struct nettle_cipher nettle_serpent128;
80 extern const struct nettle_cipher nettle_serpent192;
81 extern const struct nettle_cipher nettle_serpent256;
82
83 extern const struct nettle_cipher nettle_twofish128;
84 extern const struct nettle_cipher nettle_twofish192;
85 extern const struct nettle_cipher nettle_twofish256;
86
87 extern const struct nettle_cipher nettle_arctwo40;
88 extern const struct nettle_cipher nettle_arctwo64;
89 extern const struct nettle_cipher nettle_arctwo128;
90 extern const struct nettle_cipher nettle_arctwo_gutmann128;
91
92 struct nettle_hash
93 {
94   const char *name;
95
96   /* Size of the context struct */
97   unsigned context_size;
98
99   /* Size of digests */
100   unsigned digest_size;
101   
102   /* Internal block size */
103   unsigned block_size;
104
105   nettle_hash_init_func *init;
106   nettle_hash_update_func *update;
107   nettle_hash_digest_func *digest;
108 };
109
110 #define _NETTLE_HASH(name, NAME) {              \
111  #name,                                         \
112  sizeof(struct name##_ctx),                     \
113  NAME##_DIGEST_SIZE,                            \
114  NAME##_BLOCK_SIZE,                             \
115  (nettle_hash_init_func *) name##_init,         \
116  (nettle_hash_update_func *) name##_update,     \
117  (nettle_hash_digest_func *) name##_digest      \
118
119
120 /* null-terminated list of digests implemented by this version of nettle */
121 const struct nettle_hash * const * _NETTLE_ATTRIBUTE_PURE
122 nettle_get_hashes (void);
123
124 #define nettle_hashes (nettle_get_hashes())
125
126 const struct nettle_hash *
127 nettle_lookup_hash (const char *name);
128
129 extern const struct nettle_hash nettle_md2;
130 extern const struct nettle_hash nettle_md4;
131 extern const struct nettle_hash nettle_md5;
132 extern const struct nettle_hash nettle_gosthash94;
133 extern const struct nettle_hash nettle_ripemd160;
134 extern const struct nettle_hash nettle_sha1;
135 extern const struct nettle_hash nettle_sha224;
136 extern const struct nettle_hash nettle_sha256;
137 extern const struct nettle_hash nettle_sha384;
138 extern const struct nettle_hash nettle_sha512;
139 extern const struct nettle_hash nettle_sha512_224;
140 extern const struct nettle_hash nettle_sha512_256;
141 extern const struct nettle_hash nettle_sha3_224;
142 extern const struct nettle_hash nettle_sha3_256;
143 extern const struct nettle_hash nettle_sha3_384;
144 extern const struct nettle_hash nettle_sha3_512;
145
146 struct nettle_aead
147 {
148   const char *name;
149   
150   unsigned context_size;
151   /* Block size for encrypt and decrypt. */
152   unsigned block_size;
153   unsigned key_size;
154   unsigned nonce_size;
155   unsigned digest_size;
156
157   nettle_set_key_func *set_encrypt_key;
158   nettle_set_key_func *set_decrypt_key;
159   nettle_set_key_func *set_nonce;
160   nettle_hash_update_func *update;
161   nettle_crypt_func *encrypt;
162   nettle_crypt_func *decrypt;
163   /* FIXME: Drop length argument? */
164   nettle_hash_digest_func *digest;
165 };
166
167 /* null-terminated list of aead constructions implemented by this
168    version of nettle */
169 const struct nettle_aead * const * _NETTLE_ATTRIBUTE_PURE
170 nettle_get_aeads (void);
171
172 #define nettle_aeads (nettle_get_aeads())
173
174 extern const struct nettle_aead nettle_gcm_aes128;
175 extern const struct nettle_aead nettle_gcm_aes192;
176 extern const struct nettle_aead nettle_gcm_aes256;
177 extern const struct nettle_aead nettle_gcm_camellia128;
178 extern const struct nettle_aead nettle_gcm_camellia256;
179 extern const struct nettle_aead nettle_eax_aes128;
180 extern const struct nettle_aead nettle_chacha_poly1305;
181
182 struct nettle_armor
183 {
184   const char *name;
185   unsigned encode_context_size;
186   unsigned decode_context_size;
187
188   unsigned encode_final_length;
189
190   nettle_armor_init_func *encode_init;
191   nettle_armor_length_func *encode_length;
192   nettle_armor_encode_update_func *encode_update;
193   nettle_armor_encode_final_func *encode_final;
194   
195   nettle_armor_init_func *decode_init;
196   nettle_armor_length_func *decode_length;
197   nettle_armor_decode_update_func *decode_update;
198   nettle_armor_decode_final_func *decode_final;
199 };
200
201 #define _NETTLE_ARMOR(name, NAME) {                             \
202   #name,                                                        \
203   sizeof(struct name##_encode_ctx),                             \
204   sizeof(struct name##_decode_ctx),                             \
205   NAME##_ENCODE_FINAL_LENGTH,                                   \
206   (nettle_armor_init_func *) name##_encode_init,                \
207   (nettle_armor_length_func *) name##_encode_length,            \
208   (nettle_armor_encode_update_func *) name##_encode_update,     \
209   (nettle_armor_encode_final_func *) name##_encode_final,       \
210   (nettle_armor_init_func *) name##_decode_init,                \
211   (nettle_armor_length_func *) name##_decode_length,            \
212   (nettle_armor_decode_update_func *) name##_decode_update,     \
213   (nettle_armor_decode_final_func *) name##_decode_final,       \
214 }
215
216 #define _NETTLE_ARMOR_0(name, NAME) {                           \
217   #name,                                                        \
218   0,                                                            \
219   sizeof(struct name##_decode_ctx),                             \
220   NAME##_ENCODE_FINAL_LENGTH,                                   \
221   (nettle_armor_init_func *) name##_encode_init,                \
222   (nettle_armor_length_func *) name##_encode_length,            \
223   (nettle_armor_encode_update_func *) name##_encode_update,     \
224   (nettle_armor_encode_final_func *) name##_encode_final,       \
225   (nettle_armor_init_func *) name##_decode_init,                \
226   (nettle_armor_length_func *) name##_decode_length,            \
227   (nettle_armor_decode_update_func *) name##_decode_update,     \
228   (nettle_armor_decode_final_func *) name##_decode_final,       \
229 }
230
231 /* null-terminated list of armor schemes implemented by this version of nettle */
232 const struct nettle_armor * const * _NETTLE_ATTRIBUTE_PURE
233 nettle_get_armors (void);
234
235 #define nettle_armors (nettle_get_armors())
236
237 extern const struct nettle_armor nettle_base64;
238 extern const struct nettle_armor nettle_base64url;
239 extern const struct nettle_armor nettle_base16;
240
241 #ifdef __cplusplus
242 }
243 #endif
244
245 #endif /* NETTLE_META_H_INCLUDED */