Dibbler - a portable DHCPv6  1.0.2RC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
nettle-meta.h
Go to the documentation of this file.
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., 59 Temple Place - Suite 330, Boston,
23  * MA 02111-1307, USA.
24  */
25 
26 #ifndef NETTLE_META_H_INCLUDED
27 #define NETTLE_META_H_INCLUDED
28 
29 #include "nettle-types.h"
30 
31 /* For nettle_crypt_func */
32 #include "cbc.h"
33 
34 /* Randomness. Used by key generation and dsa signature creation. */
35 typedef void (*nettle_random_func)(void *ctx,
36  unsigned length, uint8_t *dst);
37 
38 /* Progress report function, mainly for key generation. */
39 typedef void (*nettle_progress_func)(void *ctx,
40  int c);
41 
42 /* Ciphers */
43 typedef void (*nettle_set_key_func)(void *ctx,
44  unsigned length,
45  const uint8_t *key);
46 
47 
49 {
50  const char *name;
51 
52  unsigned context_size;
53 
54  /* Zero for stream ciphers */
55  unsigned block_size;
56 
57  /* Suggested key size; other sizes are sometimes possible. */
58  unsigned key_size;
59 
62 
65 };
66 
67 #define _NETTLE_CIPHER(name, NAME, keysize) { \
68  #name #keysize, \
69  sizeof(struct name##_ctx), \
70  NAME##_BLOCK_SIZE, \
71  keysize / 8, \
72  (nettle_set_key_func) name##_set_key, \
73  (nettle_set_key_func) name##_set_key, \
74  (nettle_crypt_func) name##_encrypt, \
75  (nettle_crypt_func) name##_decrypt, \
76 }
77 
78 #define _NETTLE_CIPHER_SEP(name, NAME, keysize) { \
79  #name #keysize, \
80  sizeof(struct name##_ctx), \
81  NAME##_BLOCK_SIZE, \
82  keysize / 8, \
83  (nettle_set_key_func) name##_set_encrypt_key, \
84  (nettle_set_key_func) name##_set_decrypt_key, \
85  (nettle_crypt_func) name##_encrypt, \
86  (nettle_crypt_func) name##_decrypt, \
87 }
88 
89 #define _NETTLE_CIPHER_FIX(name, NAME, keysize) { \
90  #name, \
91  sizeof(struct name##_ctx), \
92  NAME##_BLOCK_SIZE, \
93  keysize / 8, \
94  (nettle_set_key_func) name##_set_key, \
95  (nettle_set_key_func) name##_set_key, \
96  (nettle_crypt_func) name##_encrypt, \
97  (nettle_crypt_func) name##_decrypt, \
98 }
99 
100 extern const struct nettle_cipher nettle_aes128;
101 extern const struct nettle_cipher nettle_aes192;
102 extern const struct nettle_cipher nettle_aes256;
103 
104 extern const struct nettle_cipher nettle_arcfour128;
105 extern const struct nettle_cipher nettle_cast128;
106 
107 extern const struct nettle_cipher nettle_serpent128;
108 extern const struct nettle_cipher nettle_serpent192;
109 extern const struct nettle_cipher nettle_serpent256;
110 
111 extern const struct nettle_cipher nettle_twofish128;
112 extern const struct nettle_cipher nettle_twofish192;
113 extern const struct nettle_cipher nettle_twofish256;
114 
115 extern const struct nettle_cipher nettle_arctwo40;
116 extern const struct nettle_cipher nettle_arctwo64;
117 extern const struct nettle_cipher nettle_arctwo128;
118 extern const struct nettle_cipher nettle_arctwo_gutmann128;
119 
120 
121 /* Hash algorithms */
122 typedef void (*nettle_hash_init_func)(void *ctx);
123 typedef void (*nettle_hash_update_func)(void *ctx,
124  unsigned length,
125  const uint8_t *src);
126 typedef void (*nettle_hash_digest_func)(void *ctx,
127  unsigned length, uint8_t *dst);
128 
130 {
131  const char *name;
132 
133  /* Size of the context struct */
134  unsigned context_size;
135 
136  /* Size of digests */
137  unsigned digest_size;
138 
139  /* Internal block size */
140  unsigned block_size;
141 
145 };
146 
147 #define _NETTLE_HASH(name, NAME) { \
148  #name, \
149  sizeof(struct name##_ctx), \
150  NAME##_DIGEST_SIZE, \
151  NAME##_DATA_SIZE, \
152  (nettle_hash_init_func) name##_init, \
153  (nettle_hash_update_func) name##_update, \
154  (nettle_hash_digest_func) name##_digest \
155 }
156 
157 extern const struct nettle_hash nettle_md2;
158 extern const struct nettle_hash nettle_md4;
159 extern const struct nettle_hash nettle_md5;
160 extern const struct nettle_hash nettle_sha1;
161 extern const struct nettle_hash nettle_sha256;
162 
163 
164 /* ASCII armor codecs. NOTE: Experimental and subject to change. */
165 
166 typedef unsigned (*nettle_armor_length_func)(unsigned length);
167 typedef void (*nettle_armor_init_func)(void *ctx);
168 
169 typedef unsigned (*nettle_armor_encode_update_func)(void *ctx,
170  uint8_t *dst,
171  unsigned src_length,
172  const uint8_t *src);
173 
174 typedef unsigned (*nettle_armor_encode_final_func)(void *ctx, uint8_t *dst);
175 
176 typedef int (*nettle_armor_decode_update_func)(void *ctx,
177  unsigned *dst_length,
178  uint8_t *dst,
179  unsigned src_length,
180  const uint8_t *src);
181 
182 typedef int (*nettle_armor_decode_final_func)(void *ctx);
183 
185 {
186  const char *name;
189 
191 
196 
201 };
202 
203 #define _NETTLE_ARMOR(name, NAME) { \
204  #name, \
205  sizeof(struct name##_encode_ctx), \
206  sizeof(struct name##_decode_ctx), \
207  NAME##_ENCODE_FINAL_LENGTH, \
208  (nettle_armor_init_func) name##_encode_init, \
209  (nettle_armor_length_func) name##_encode_length, \
210  (nettle_armor_encode_update_func) name##_encode_update, \
211  (nettle_armor_encode_final_func) name##_encode_final, \
212  (nettle_armor_init_func) name##_decode_init, \
213  (nettle_armor_length_func) name##_decode_length, \
214  (nettle_armor_decode_update_func) name##_decode_update, \
215  (nettle_armor_decode_final_func) name##_decode_final, \
216 }
217 
218 #define _NETTLE_ARMOR_0(name, NAME) { \
219  #name, \
220  0, \
221  sizeof(struct name##_decode_ctx), \
222  NAME##_ENCODE_FINAL_LENGTH, \
223  (nettle_armor_init_func) name##_encode_init, \
224  (nettle_armor_length_func) name##_encode_length, \
225  (nettle_armor_encode_update_func) name##_encode_update, \
226  (nettle_armor_encode_final_func) name##_encode_final, \
227  (nettle_armor_init_func) name##_decode_init, \
228  (nettle_armor_length_func) name##_decode_length, \
229  (nettle_armor_decode_update_func) name##_decode_update, \
230  (nettle_armor_decode_final_func) name##_decode_final, \
231 }
232 
233 
234 extern const struct nettle_armor nettle_base64;
235 extern const struct nettle_armor nettle_base16;
236 
237 #endif /* NETTLE_META_H_INCLUDED */
238