Fix.
[shishi.git] / crypto / nettle-meta.h
blobebffd1cb9c83041126f8b908137617b44ff79429
1 /* nettle-meta.h
3 * Information about algorithms.
4 */
6 /* nettle, low-level cryptographics library
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.
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.
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., 59 Temple Place - Suite 330, Boston,
23 * MA 02111-1307, USA.
26 #ifndef NETTLE_META_H_INCLUDED
27 #define NETTLE_META_H_INCLUDED
29 #include <inttypes.h>
31 /* Randomness. Used by key generation and dsa signature creation. */
32 typedef void (*nettle_random_func)(void *ctx,
33 unsigned length, uint8_t *dst);
35 /* Progress report function, mainly for key generation. */
36 typedef void (*nettle_progress_func)(void *ctx,
37 int c);
39 /* Ciphers */
40 typedef void (*nettle_crypt_func)(void *ctx,
41 unsigned length, uint8_t *dst,
42 const uint8_t *src);
44 typedef void (*nettle_set_key_func)(void *ctx,
45 unsigned length,
46 const uint8_t *key);
49 struct nettle_cipher
51 const char *name;
53 unsigned context_size;
55 /* Zero for stream ciphers */
56 unsigned block_size;
58 /* Suggested key size; other sizes are sometimes possible. */
59 unsigned key_size;
61 nettle_set_key_func set_encrypt_key;
62 nettle_set_key_func set_decrypt_key;
64 nettle_crypt_func encrypt;
65 nettle_crypt_func decrypt;
68 #define _NETTLE_CIPHER(name, NAME, keysize) { \
69 #name #keysize, \
70 sizeof(struct name##_ctx), \
71 NAME##_BLOCK_SIZE, \
72 keysize / 8, \
73 (nettle_set_key_func) name##_set_key, \
74 (nettle_set_key_func) name##_set_key, \
75 (nettle_crypt_func) name##_encrypt, \
76 (nettle_crypt_func) name##_decrypt, \
79 #define _NETTLE_CIPHER_SEP(name, NAME, keysize) { \
80 #name #keysize, \
81 sizeof(struct name##_ctx), \
82 NAME##_BLOCK_SIZE, \
83 keysize / 8, \
84 (nettle_set_key_func) name##_set_encrypt_key, \
85 (nettle_set_key_func) name##_set_decrypt_key, \
86 (nettle_crypt_func) name##_encrypt, \
87 (nettle_crypt_func) name##_decrypt, \
90 #define _NETTLE_CIPHER_FIX(name, NAME, keysize) { \
91 #name, \
92 sizeof(struct name##_ctx), \
93 NAME##_BLOCK_SIZE, \
94 keysize / 8, \
95 (nettle_set_key_func) name##_set_key, \
96 (nettle_set_key_func) name##_set_key, \
97 (nettle_crypt_func) name##_encrypt, \
98 (nettle_crypt_func) name##_decrypt, \
101 extern const struct nettle_cipher nettle_aes128;
102 extern const struct nettle_cipher nettle_aes192;
103 extern const struct nettle_cipher nettle_aes256;
105 extern const struct nettle_cipher nettle_arcfour128;
106 extern const struct nettle_cipher nettle_cast128;
108 extern const struct nettle_cipher nettle_serpent128;
109 extern const struct nettle_cipher nettle_serpent192;
110 extern const struct nettle_cipher nettle_serpent256;
112 extern const struct nettle_cipher nettle_twofish128;
113 extern const struct nettle_cipher nettle_twofish192;
114 extern const struct nettle_cipher nettle_twofish256;
117 /* Hash algorithms */
118 typedef void (*nettle_hash_init_func)(void *ctx);
119 typedef void (*nettle_hash_update_func)(void *ctx,
120 unsigned length,
121 const uint8_t *src);
122 typedef void (*nettle_hash_digest_func)(void *ctx,
123 unsigned length, uint8_t *dst);
125 struct nettle_hash
127 const char *name;
129 /* Size of the context struct */
130 unsigned context_size;
132 /* Size of digests */
133 unsigned digest_size;
135 /* Internal block size */
136 unsigned block_size;
138 nettle_hash_init_func init;
139 nettle_hash_update_func update;
140 nettle_hash_digest_func digest;
143 #define _NETTLE_HASH(name, NAME) { \
144 #name, \
145 sizeof(struct name##_ctx), \
146 NAME##_DIGEST_SIZE, \
147 NAME##_DATA_SIZE, \
148 (nettle_hash_init_func) name##_init, \
149 (nettle_hash_update_func) name##_update, \
150 (nettle_hash_digest_func) name##_digest \
153 extern const struct nettle_hash nettle_md2;
154 extern const struct nettle_hash nettle_md4;
155 extern const struct nettle_hash nettle_md5;
156 extern const struct nettle_hash nettle_sha1;
157 extern const struct nettle_hash nettle_sha256;
160 /* ASCII armor codecs. NOTE: Experimental and subject to change. */
162 typedef unsigned (*nettle_armor_length_func)(unsigned length);
163 typedef void (*nettle_armor_init_func)(void *ctx);
165 typedef unsigned (*nettle_armor_encode_update_func)(void *ctx,
166 uint8_t *dst,
167 unsigned src_length,
168 const uint8_t *src);
170 typedef unsigned (*nettle_armor_encode_final_func)(void *ctx, uint8_t *dst);
172 typedef int (*nettle_armor_decode_update_func)(void *ctx,
173 unsigned *dst_length,
174 uint8_t *dst,
175 unsigned src_length,
176 const uint8_t *src);
178 typedef int (*nettle_armor_decode_final_func)(void *ctx);
180 struct nettle_armor
182 const char *name;
183 unsigned encode_context_size;
184 unsigned decode_context_size;
186 unsigned encode_final_length;
188 nettle_armor_init_func encode_init;
189 nettle_armor_length_func encode_length;
190 nettle_armor_encode_update_func encode_update;
191 nettle_armor_encode_final_func encode_final;
193 nettle_armor_init_func decode_init;
194 nettle_armor_length_func decode_length;
195 nettle_armor_decode_update_func decode_update;
196 nettle_armor_decode_final_func decode_final;
199 #define _NETTLE_ARMOR(name, NAME) { \
200 #name, \
201 sizeof(struct name##_encode_ctx), \
202 sizeof(struct name##_decode_ctx), \
203 NAME##_ENCODE_FINAL_LENGTH, \
204 (nettle_armor_init_func) name##_encode_init, \
205 (nettle_armor_length_func) name##_encode_length, \
206 (nettle_armor_encode_update_func) name##_encode_update, \
207 (nettle_armor_encode_final_func) name##_encode_final, \
208 (nettle_armor_init_func) name##_decode_init, \
209 (nettle_armor_length_func) name##_decode_length, \
210 (nettle_armor_decode_update_func) name##_decode_update, \
211 (nettle_armor_decode_final_func) name##_decode_final, \
214 #define _NETTLE_ARMOR_0(name, NAME) { \
215 #name, \
216 0, \
217 sizeof(struct name##_decode_ctx), \
218 NAME##_ENCODE_FINAL_LENGTH, \
219 (nettle_armor_init_func) name##_encode_init, \
220 (nettle_armor_length_func) name##_encode_length, \
221 (nettle_armor_encode_update_func) name##_encode_update, \
222 (nettle_armor_encode_final_func) name##_encode_final, \
223 (nettle_armor_init_func) name##_decode_init, \
224 (nettle_armor_length_func) name##_decode_length, \
225 (nettle_armor_decode_update_func) name##_decode_update, \
226 (nettle_armor_decode_final_func) name##_decode_final, \
230 extern const struct nettle_armor nettle_base64;
231 extern const struct nettle_armor nettle_base16;
233 #endif /* NETTLE_META_H_INCLUDED */