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