14b5e48ed0c166c1fa30059f5c1235c69127c4d4
[platform/upstream/nettle.git] / 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 extern const struct nettle_cipher * const nettle_ciphers[];
65
66 extern const struct nettle_cipher nettle_aes128;
67 extern const struct nettle_cipher nettle_aes192;
68 extern const struct nettle_cipher nettle_aes256;
69
70 extern const struct nettle_cipher nettle_camellia128;
71 extern const struct nettle_cipher nettle_camellia192;
72 extern const struct nettle_cipher nettle_camellia256;
73
74 extern const struct nettle_cipher nettle_cast128;
75
76 extern const struct nettle_cipher nettle_serpent128;
77 extern const struct nettle_cipher nettle_serpent192;
78 extern const struct nettle_cipher nettle_serpent256;
79
80 extern const struct nettle_cipher nettle_twofish128;
81 extern const struct nettle_cipher nettle_twofish192;
82 extern const struct nettle_cipher nettle_twofish256;
83
84 extern const struct nettle_cipher nettle_arctwo40;
85 extern const struct nettle_cipher nettle_arctwo64;
86 extern const struct nettle_cipher nettle_arctwo128;
87 extern const struct nettle_cipher nettle_arctwo_gutmann128;
88
89 struct nettle_hash
90 {
91   const char *name;
92
93   /* Size of the context struct */
94   unsigned context_size;
95
96   /* Size of digests */
97   unsigned digest_size;
98   
99   /* Internal block size */
100   unsigned block_size;
101
102   nettle_hash_init_func *init;
103   nettle_hash_update_func *update;
104   nettle_hash_digest_func *digest;
105 };
106
107 #define _NETTLE_HASH(name, NAME) {              \
108  #name,                                         \
109  sizeof(struct name##_ctx),                     \
110  NAME##_DIGEST_SIZE,                            \
111  NAME##_BLOCK_SIZE,                             \
112  (nettle_hash_init_func *) name##_init,         \
113  (nettle_hash_update_func *) name##_update,     \
114  (nettle_hash_digest_func *) name##_digest      \
115
116
117 /* null-terminated list of digests implemented by this version of nettle */
118 extern const struct nettle_hash * const nettle_hashes[];
119
120 extern const struct nettle_hash nettle_md2;
121 extern const struct nettle_hash nettle_md4;
122 extern const struct nettle_hash nettle_md5;
123 extern const struct nettle_hash nettle_gosthash94;
124 extern const struct nettle_hash nettle_ripemd160;
125 extern const struct nettle_hash nettle_sha1;
126 extern const struct nettle_hash nettle_sha224;
127 extern const struct nettle_hash nettle_sha256;
128 extern const struct nettle_hash nettle_sha384;
129 extern const struct nettle_hash nettle_sha512;
130 extern const struct nettle_hash nettle_sha512_224;
131 extern const struct nettle_hash nettle_sha512_256;
132 extern const struct nettle_hash nettle_sha3_224;
133 extern const struct nettle_hash nettle_sha3_256;
134 extern const struct nettle_hash nettle_sha3_384;
135 extern const struct nettle_hash nettle_sha3_512;
136
137 struct nettle_aead
138 {
139   const char *name;
140   
141   unsigned context_size;
142   /* Block size for encrypt and decrypt. */
143   unsigned block_size;
144   unsigned key_size;
145   unsigned nonce_size;
146   unsigned digest_size;
147
148   nettle_set_key_func *set_encrypt_key;
149   nettle_set_key_func *set_decrypt_key;
150   nettle_set_key_func *set_nonce;
151   nettle_hash_update_func *update;
152   nettle_crypt_func *encrypt;
153   nettle_crypt_func *decrypt;
154   /* FIXME: Drop length argument? */
155   nettle_hash_digest_func *digest;
156 };
157
158 /* null-terminated list of aead constructions implemented by this
159    version of nettle */
160 extern const struct nettle_aead * const nettle_aeads[];
161
162 extern const struct nettle_aead nettle_gcm_aes128;
163 extern const struct nettle_aead nettle_gcm_aes192;
164 extern const struct nettle_aead nettle_gcm_aes256;
165 extern const struct nettle_aead nettle_gcm_camellia128;
166 extern const struct nettle_aead nettle_gcm_camellia256;
167 extern const struct nettle_aead nettle_eax_aes128;
168 extern const struct nettle_aead nettle_chacha_poly1305;
169
170 struct nettle_armor
171 {
172   const char *name;
173   unsigned encode_context_size;
174   unsigned decode_context_size;
175
176   unsigned encode_final_length;
177
178   nettle_armor_init_func *encode_init;
179   nettle_armor_length_func *encode_length;
180   nettle_armor_encode_update_func *encode_update;
181   nettle_armor_encode_final_func *encode_final;
182   
183   nettle_armor_init_func *decode_init;
184   nettle_armor_length_func *decode_length;
185   nettle_armor_decode_update_func *decode_update;
186   nettle_armor_decode_final_func *decode_final;
187 };
188
189 #define _NETTLE_ARMOR(name, NAME) {                             \
190   #name,                                                        \
191   sizeof(struct name##_encode_ctx),                             \
192   sizeof(struct name##_decode_ctx),                             \
193   NAME##_ENCODE_FINAL_LENGTH,                                   \
194   (nettle_armor_init_func *) name##_encode_init,                \
195   (nettle_armor_length_func *) name##_encode_length,            \
196   (nettle_armor_encode_update_func *) name##_encode_update,     \
197   (nettle_armor_encode_final_func *) name##_encode_final,       \
198   (nettle_armor_init_func *) name##_decode_init,                \
199   (nettle_armor_length_func *) name##_decode_length,            \
200   (nettle_armor_decode_update_func *) name##_decode_update,     \
201   (nettle_armor_decode_final_func *) name##_decode_final,       \
202 }
203
204 #define _NETTLE_ARMOR_0(name, NAME) {                           \
205   #name,                                                        \
206   0,                                                            \
207   sizeof(struct name##_decode_ctx),                             \
208   NAME##_ENCODE_FINAL_LENGTH,                                   \
209   (nettle_armor_init_func *) name##_encode_init,                \
210   (nettle_armor_length_func *) name##_encode_length,            \
211   (nettle_armor_encode_update_func *) name##_encode_update,     \
212   (nettle_armor_encode_final_func *) name##_encode_final,       \
213   (nettle_armor_init_func *) name##_decode_init,                \
214   (nettle_armor_length_func *) name##_decode_length,            \
215   (nettle_armor_decode_update_func *) name##_decode_update,     \
216   (nettle_armor_decode_final_func *) name##_decode_final,       \
217 }
218
219 /* null-terminated list of armor schemes implemented by this version of nettle */
220 extern const struct nettle_armor * const nettle_armors[];
221
222 extern const struct nettle_armor nettle_base64;
223 extern const struct nettle_armor nettle_base64url;
224 extern const struct nettle_armor nettle_base16;
225
226 #ifdef __cplusplus
227 }
228 #endif
229
230 #endif /* NETTLE_META_H_INCLUDED */