diff options
author | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2008-07-11 15:50:46 +0000 |
---|---|---|
committer | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2008-07-11 15:50:46 +0000 |
commit | 14c7f45cdae826f88dc539c8c38dd95caf305731 (patch) | |
tree | 832da054b7cfb2dc6fd63339af736625f31d21aa /utils/zenutils/libraries/beecrypt-4.1.2/beecrypt/beecrypt.h | |
parent | 7c84ede3781c27db73403bd6302f320c76a58c8c (diff) | |
download | rockbox-14c7f45cdae826f88dc539c8c38dd95caf305731.tar.gz rockbox-14c7f45cdae826f88dc539c8c38dd95caf305731.zip |
Add zook's ZenUtils to SVN
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18010 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/zenutils/libraries/beecrypt-4.1.2/beecrypt/beecrypt.h')
-rwxr-xr-x | utils/zenutils/libraries/beecrypt-4.1.2/beecrypt/beecrypt.h | 799 |
1 files changed, 799 insertions, 0 deletions
diff --git a/utils/zenutils/libraries/beecrypt-4.1.2/beecrypt/beecrypt.h b/utils/zenutils/libraries/beecrypt-4.1.2/beecrypt/beecrypt.h new file mode 100755 index 0000000000..a4c8780d03 --- /dev/null +++ b/utils/zenutils/libraries/beecrypt-4.1.2/beecrypt/beecrypt.h | |||
@@ -0,0 +1,799 @@ | |||
1 | /* | ||
2 | * Copyright (c) 1999, 2000, 2001, 2002 Virtual Unlimited B.V. | ||
3 | * | ||
4 | * This library is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) any later version. | ||
8 | * | ||
9 | * This library is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | * Lesser General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU Lesser General Public | ||
15 | * License along with this library; if not, write to the Free Software | ||
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
17 | * | ||
18 | */ | ||
19 | |||
20 | /*!\file beecrypt.h | ||
21 | * \brief BeeCrypt API, headers. | ||
22 | * | ||
23 | * These API functions provide an abstract way for using most of | ||
24 | * the various algorithms implemented by the library. | ||
25 | * | ||
26 | * \author Bob Deblier <bob.deblier@pandora.be> | ||
27 | * \ingroup ES_m PRNG_m HASH_m HMAC_m BC_m | ||
28 | */ | ||
29 | |||
30 | #ifndef _BEECRYPT_H | ||
31 | #define _BEECRYPT_H | ||
32 | |||
33 | #include "beecrypt/api.h" | ||
34 | |||
35 | #include "beecrypt/memchunk.h" | ||
36 | #include "beecrypt/mpnumber.h" | ||
37 | |||
38 | /* | ||
39 | * Entropy Sources | ||
40 | */ | ||
41 | |||
42 | /*!\typedef entropyNext | ||
43 | * \brief Prototype definition for an entropy-generating function. | ||
44 | * \ingroup ES_m | ||
45 | */ | ||
46 | typedef int (*entropyNext)(byte*, size_t); | ||
47 | |||
48 | /*!\brief This struct holds information and pointers to code specific to each | ||
49 | * source of entropy. | ||
50 | * \ingroup ES_m | ||
51 | */ | ||
52 | #ifdef __cplusplus | ||
53 | struct BEECRYPTAPI entropySource | ||
54 | #else | ||
55 | struct _entropySource | ||
56 | #endif | ||
57 | { | ||
58 | /*!\var name | ||
59 | * \brief The entropy source's name. | ||
60 | */ | ||
61 | const char* name; | ||
62 | /*!\var next | ||
63 | * \brief Points to the function which produces the entropy. | ||
64 | */ | ||
65 | const entropyNext next; | ||
66 | }; | ||
67 | |||
68 | #ifndef __cplusplus | ||
69 | typedef struct _entropySource entropySource; | ||
70 | #endif | ||
71 | |||
72 | #ifdef __cplusplus | ||
73 | extern "C" { | ||
74 | #endif | ||
75 | |||
76 | /*!\fn int entropySourceCount() | ||
77 | * \brief This function returns the number of entropy sources implemented by | ||
78 | * the library. | ||
79 | * \return The number of implemented entropy sources. | ||
80 | */ | ||
81 | BEECRYPTAPI | ||
82 | int entropySourceCount(void); | ||
83 | |||
84 | /*!\fn const entropySource* entropySourceGet(int n) | ||
85 | * \brief This function returns the \a n -th entropy source implemented by | ||
86 | * the library. | ||
87 | * \param n Index of the requested entropy source; legal values are 0 | ||
88 | * through entropySourceCount() - 1. | ||
89 | * \return A pointer to an entropy source or null, if the index was out of | ||
90 | * range. | ||
91 | */ | ||
92 | BEECRYPTAPI | ||
93 | const entropySource* entropySourceGet(int n); | ||
94 | |||
95 | /*!\fn const entropySource* entropySourceFind(const char* name) | ||
96 | * \brief This function returns the entropy source specified by the given name. | ||
97 | * \param name Name of the requested entropy source. | ||
98 | * \return A pointer to an entropy source or null, if the name wasn't found. | ||
99 | */ | ||
100 | BEECRYPTAPI | ||
101 | const entropySource* entropySourceFind(const char* name); | ||
102 | |||
103 | /*!\fn const entropySource* entropySourceDefault() | ||
104 | * \brief This functions returns the default entropy source; the default value | ||
105 | * can be specified by setting environment variable BEECRYPT_ENTROPY. | ||
106 | * \return A pointer to an entropy source or null, in case an error occured. | ||
107 | */ | ||
108 | BEECRYPTAPI | ||
109 | const entropySource* entropySourceDefault(void); | ||
110 | |||
111 | /*!\fn int entropyGatherNext(byte* data, size_t size) | ||
112 | * \brief This function gathers \a size bytes of entropy into \a data. | ||
113 | * | ||
114 | * Unless environment variable BEECRYPT_ENTROPY is set, this function will | ||
115 | * try each successive entropy source to gather up the requested amount. | ||
116 | * | ||
117 | * \param data Points to where the entropy should be stored. | ||
118 | * \param size Indicates how many bytes of entropy should be gathered. | ||
119 | * \retval 0 On success. | ||
120 | * \retval -1 On failure. | ||
121 | */ | ||
122 | BEECRYPTAPI | ||
123 | int entropyGatherNext(byte*, size_t); | ||
124 | |||
125 | #ifdef __cplusplus | ||
126 | } | ||
127 | #endif | ||
128 | |||
129 | /* | ||
130 | * Pseudo-random Number Generators | ||
131 | */ | ||
132 | |||
133 | typedef void randomGeneratorParam; | ||
134 | |||
135 | typedef int (*randomGeneratorSetup )(randomGeneratorParam*); | ||
136 | typedef int (*randomGeneratorSeed )(randomGeneratorParam*, const byte*, size_t); | ||
137 | typedef int (*randomGeneratorNext )(randomGeneratorParam*, byte*, size_t); | ||
138 | typedef int (*randomGeneratorCleanup)(randomGeneratorParam*); | ||
139 | |||
140 | /* | ||
141 | * The struct 'randomGenerator' holds information and pointers to code specific | ||
142 | * to each random generator. Each specific random generator MUST be written to | ||
143 | * be multithread safe. | ||
144 | * | ||
145 | * WARNING: each randomGenerator, when used in cryptographic applications, MUST | ||
146 | * be guaranteed to be of suitable quality and strength (i.e. don't use the | ||
147 | * random() function found in most UN*X-es). | ||
148 | * | ||
149 | * Multiple instances of each randomGenerator can be used (even concurrently), | ||
150 | * provided they each use their own randomGeneratorParam parameters, a chunk | ||
151 | * of memory which must be at least as large as indicated by the paramsize | ||
152 | * field. | ||
153 | * | ||
154 | */ | ||
155 | |||
156 | /*!\brief This struct holds information and pointers to code specific to each | ||
157 | * pseudo-random number generator. | ||
158 | * \ingroup PRNG_m | ||
159 | */ | ||
160 | #ifdef __cplusplus | ||
161 | struct BEECRYPTAPI randomGenerator | ||
162 | #else | ||
163 | struct _randomGenerator | ||
164 | #endif | ||
165 | { | ||
166 | /*!\var name | ||
167 | * \brief The random generator's name. | ||
168 | */ | ||
169 | const char* name; | ||
170 | /*!\var paramsize | ||
171 | * \brief The size of the random generator's parameters. | ||
172 | * \note The implementor should set this by using sizeof(<struct holding | ||
173 | * random generator's parameters>). | ||
174 | */ | ||
175 | const size_t paramsize; | ||
176 | /*!\var setup | ||
177 | * \brief Points to the setup function. | ||
178 | */ | ||
179 | const randomGeneratorSetup setup; | ||
180 | /*!\var seed | ||
181 | * \brief Points to the seeding function. | ||
182 | */ | ||
183 | const randomGeneratorSeed seed; | ||
184 | /*!\var seed | ||
185 | * \brief Points to the function which generates the random data. | ||
186 | */ | ||
187 | const randomGeneratorNext next; | ||
188 | /*!\var seed | ||
189 | * \brief Points to the cleanup function. | ||
190 | */ | ||
191 | const randomGeneratorCleanup cleanup; | ||
192 | }; | ||
193 | |||
194 | #ifndef __cplusplus | ||
195 | typedef struct _randomGenerator randomGenerator; | ||
196 | #endif | ||
197 | |||
198 | /* | ||
199 | * You can use the following functions to find random generators implemented by | ||
200 | * the library: | ||
201 | * | ||
202 | * randomGeneratorCount returns the number of generators available. | ||
203 | * | ||
204 | * randomGeneratorGet returns the random generator with a given index (starting | ||
205 | * at zero, up to randomGeneratorCount() - 1), or NULL if the index was out of | ||
206 | * bounds. | ||
207 | * | ||
208 | * randomGeneratorFind returns the random generator with the given name, or | ||
209 | * NULL if no random generator exists with that name. | ||
210 | */ | ||
211 | |||
212 | #ifdef __cplusplus | ||
213 | extern "C" { | ||
214 | #endif | ||
215 | |||
216 | BEECRYPTAPI | ||
217 | int randomGeneratorCount(void); | ||
218 | BEECRYPTAPI | ||
219 | const randomGenerator* randomGeneratorGet(int); | ||
220 | BEECRYPTAPI | ||
221 | const randomGenerator* randomGeneratorFind(const char*); | ||
222 | BEECRYPTAPI | ||
223 | const randomGenerator* randomGeneratorDefault(void); | ||
224 | |||
225 | #ifdef __cplusplus | ||
226 | } | ||
227 | #endif | ||
228 | |||
229 | /* | ||
230 | * The struct 'randomGeneratorContext' is used to contain both the functional | ||
231 | * part (the randomGenerator), and its parameters. | ||
232 | */ | ||
233 | |||
234 | #ifdef __cplusplus | ||
235 | struct BEECRYPTAPI randomGeneratorContext | ||
236 | #else | ||
237 | struct _randomGeneratorContext | ||
238 | #endif | ||
239 | { | ||
240 | const randomGenerator* rng; | ||
241 | randomGeneratorParam* param; | ||
242 | |||
243 | #ifdef __cplusplus | ||
244 | randomGeneratorContext(); | ||
245 | randomGeneratorContext(const randomGenerator*); | ||
246 | ~randomGeneratorContext(); | ||
247 | #endif | ||
248 | }; | ||
249 | |||
250 | #ifndef __cplusplus | ||
251 | typedef struct _randomGeneratorContext randomGeneratorContext; | ||
252 | #endif | ||
253 | |||
254 | /* | ||
255 | * The following functions can be used to initialize and free a | ||
256 | * randomGeneratorContext. Initializing will allocate a buffer of the size | ||
257 | * required by the randomGenerator, freeing will deallocate that buffer. | ||
258 | */ | ||
259 | |||
260 | #ifdef __cplusplus | ||
261 | extern "C" { | ||
262 | #endif | ||
263 | |||
264 | BEECRYPTAPI | ||
265 | int randomGeneratorContextInit(randomGeneratorContext*, const randomGenerator*); | ||
266 | BEECRYPTAPI | ||
267 | int randomGeneratorContextFree(randomGeneratorContext*); | ||
268 | BEECRYPTAPI | ||
269 | int randomGeneratorContextNext(randomGeneratorContext*, byte*, size_t); | ||
270 | BEECRYPTAPI | ||
271 | int randomGeneratorContextSeed(randomGeneratorContext*, const byte*, size_t); | ||
272 | |||
273 | #ifdef __cplusplus | ||
274 | } | ||
275 | #endif | ||
276 | |||
277 | /* | ||
278 | * Hash Functions | ||
279 | */ | ||
280 | |||
281 | /*!typedef void hashFunctionParam | ||
282 | * \ingroup HASH_m | ||
283 | */ | ||
284 | typedef void hashFunctionParam; | ||
285 | |||
286 | typedef int (*hashFunctionReset )(hashFunctionParam*); | ||
287 | typedef int (*hashFunctionUpdate)(hashFunctionParam*, const byte*, size_t); | ||
288 | typedef int (*hashFunctionDigest)(hashFunctionParam*, byte*); | ||
289 | |||
290 | /* | ||
291 | * The struct 'hashFunction' holds information and pointers to code specific | ||
292 | * to each hash function. Specific hash functions MAY be written to be | ||
293 | * multithread-safe. | ||
294 | * | ||
295 | * NOTE: data MUST have a size (in bytes) of at least 'digestsize' as described | ||
296 | * in the hashFunction struct. | ||
297 | * NOTE: for safety reasons, after calling digest, each specific implementation | ||
298 | * MUST reset itself so that previous values in the parameters are erased. | ||
299 | */ | ||
300 | #ifdef __cplusplus | ||
301 | struct BEECRYPTAPI hashFunction | ||
302 | #else | ||
303 | struct _hashFunction | ||
304 | #endif | ||
305 | { | ||
306 | const char* name; | ||
307 | const size_t paramsize; /* in bytes */ | ||
308 | const size_t blocksize; /* in bytes */ | ||
309 | const size_t digestsize; /* in bytes */ | ||
310 | const hashFunctionReset reset; | ||
311 | const hashFunctionUpdate update; | ||
312 | const hashFunctionDigest digest; | ||
313 | }; | ||
314 | |||
315 | #ifndef __cplusplus | ||
316 | typedef struct _hashFunction hashFunction; | ||
317 | #endif | ||
318 | |||
319 | /* | ||
320 | * You can use the following functions to find hash functions implemented by | ||
321 | * the library: | ||
322 | * | ||
323 | * hashFunctionCount returns the number of hash functions available. | ||
324 | * | ||
325 | * hashFunctionGet returns the hash function with a given index (starting | ||
326 | * at zero, up to hashFunctionCount() - 1), or NULL if the index was out of | ||
327 | * bounds. | ||
328 | * | ||
329 | * hashFunctionFind returns the hash function with the given name, or | ||
330 | * NULL if no hash function exists with that name. | ||
331 | */ | ||
332 | |||
333 | #ifdef __cplusplus | ||
334 | extern "C" { | ||
335 | #endif | ||
336 | |||
337 | BEECRYPTAPI | ||
338 | int hashFunctionCount(void); | ||
339 | BEECRYPTAPI | ||
340 | const hashFunction* hashFunctionGet(int); | ||
341 | BEECRYPTAPI | ||
342 | const hashFunction* hashFunctionFind(const char*); | ||
343 | BEECRYPTAPI | ||
344 | const hashFunction* hashFunctionDefault(void); | ||
345 | |||
346 | #ifdef __cplusplus | ||
347 | } | ||
348 | #endif | ||
349 | |||
350 | /* | ||
351 | * The struct 'hashFunctionContext' is used to contain both the functional | ||
352 | * part (the hashFunction), and its parameters. | ||
353 | */ | ||
354 | #ifdef __cplusplus | ||
355 | struct BEECRYPTAPI hashFunctionContext | ||
356 | #else | ||
357 | struct _hashFunctionContext | ||
358 | #endif | ||
359 | { | ||
360 | const hashFunction* algo; | ||
361 | hashFunctionParam* param; | ||
362 | |||
363 | #ifdef __cplusplus | ||
364 | hashFunctionContext(); | ||
365 | hashFunctionContext(const hashFunction*); | ||
366 | ~hashFunctionContext(); | ||
367 | #endif | ||
368 | }; | ||
369 | |||
370 | #ifndef __cplusplus | ||
371 | typedef struct _hashFunctionContext hashFunctionContext; | ||
372 | #endif | ||
373 | |||
374 | /* | ||
375 | * The following functions can be used to initialize and free a | ||
376 | * hashFunctionContext. Initializing will allocate a buffer of the size | ||
377 | * required by the hashFunction, freeing will deallocate that buffer. | ||
378 | */ | ||
379 | |||
380 | #ifdef __cplusplus | ||
381 | extern "C" { | ||
382 | #endif | ||
383 | |||
384 | BEECRYPTAPI | ||
385 | int hashFunctionContextInit(hashFunctionContext*, const hashFunction*); | ||
386 | BEECRYPTAPI | ||
387 | int hashFunctionContextFree(hashFunctionContext*); | ||
388 | BEECRYPTAPI | ||
389 | int hashFunctionContextReset(hashFunctionContext*); | ||
390 | BEECRYPTAPI | ||
391 | int hashFunctionContextUpdate(hashFunctionContext*, const byte*, size_t); | ||
392 | BEECRYPTAPI | ||
393 | int hashFunctionContextUpdateMC(hashFunctionContext*, const memchunk*); | ||
394 | BEECRYPTAPI | ||
395 | int hashFunctionContextUpdateMP(hashFunctionContext*, const mpnumber*); | ||
396 | BEECRYPTAPI | ||
397 | int hashFunctionContextDigest(hashFunctionContext*, byte*); | ||
398 | BEECRYPTAPI | ||
399 | int hashFunctionContextDigestMP(hashFunctionContext*, mpnumber*); | ||
400 | BEECRYPTAPI | ||
401 | int hashFunctionContextDigestMatch(hashFunctionContext*, const mpnumber*); | ||
402 | |||
403 | #ifdef __cplusplus | ||
404 | } | ||
405 | #endif | ||
406 | |||
407 | /* | ||
408 | * Keyed Hash Functions, a.k.a. Message Authentication Codes | ||
409 | */ | ||
410 | |||
411 | /*!\typedef void keyedHashFunctionParam | ||
412 | * \ingroup HMAC_m | ||
413 | */ | ||
414 | typedef void keyedHashFunctionParam; | ||
415 | |||
416 | typedef int (*keyedHashFunctionSetup )(keyedHashFunctionParam*, const byte*, size_t); | ||
417 | typedef int (*keyedHashFunctionReset )(keyedHashFunctionParam*); | ||
418 | typedef int (*keyedHashFunctionUpdate )(keyedHashFunctionParam*, const byte*, size_t); | ||
419 | typedef int (*keyedHashFunctionDigest )(keyedHashFunctionParam*, byte*); | ||
420 | |||
421 | /* | ||
422 | * The struct 'keyedHashFunction' holds information and pointers to code | ||
423 | * specific to each keyed hash function. Specific keyed hash functions MAY be | ||
424 | * written to be multithread-safe. | ||
425 | * | ||
426 | * The struct field 'keybitsmin' contains the minimum number of bits a key | ||
427 | * must contains, 'keybitsmax' the maximum number of bits a key may contain, | ||
428 | * 'keybitsinc', the increment in bits that may be used between min and max. | ||
429 | * | ||
430 | * NOTE: data must be at least have a bytesize of 'digestsize' as described | ||
431 | * in the keyedHashFunction struct. | ||
432 | * NOTE: for safety reasons, after calling digest, each specific implementation | ||
433 | * MUST reset itself so that previous values in the parameters are erased. | ||
434 | */ | ||
435 | #ifdef __cplusplus | ||
436 | struct BEECRYPTAPI keyedHashFunction | ||
437 | #else | ||
438 | struct _keyedHashFunction | ||
439 | #endif | ||
440 | { | ||
441 | const char* name; | ||
442 | const size_t paramsize; /* in bytes */ | ||
443 | const size_t blocksize; /* in bytes */ | ||
444 | const size_t digestsize; /* in bytes */ | ||
445 | const size_t keybitsmin; /* in bits */ | ||
446 | const size_t keybitsmax; /* in bits */ | ||
447 | const size_t keybitsinc; /* in bits */ | ||
448 | const keyedHashFunctionSetup setup; | ||
449 | const keyedHashFunctionReset reset; | ||
450 | const keyedHashFunctionUpdate update; | ||
451 | const keyedHashFunctionDigest digest; | ||
452 | }; | ||
453 | |||
454 | #ifndef __cplusplus | ||
455 | typedef struct _keyedHashFunction keyedHashFunction; | ||
456 | #endif | ||
457 | |||
458 | /* | ||
459 | * You can use the following functions to find keyed hash functions implemented | ||
460 | * by the library: | ||
461 | * | ||
462 | * keyedHashFunctionCount returns the number of keyed hash functions available. | ||
463 | * | ||
464 | * keyedHashFunctionGet returns the keyed hash function with a given index | ||
465 | * (starting at zero, up to keyedHashFunctionCount() - 1), or NULL if the index | ||
466 | * was out of bounds. | ||
467 | * | ||
468 | * keyedHashFunctionFind returns the keyed hash function with the given name, | ||
469 | * or NULL if no keyed hash function exists with that name. | ||
470 | */ | ||
471 | |||
472 | #ifdef __cplusplus | ||
473 | extern "C" { | ||
474 | #endif | ||
475 | |||
476 | BEECRYPTAPI | ||
477 | int keyedHashFunctionCount(void); | ||
478 | BEECRYPTAPI | ||
479 | const keyedHashFunction* keyedHashFunctionGet(int); | ||
480 | BEECRYPTAPI | ||
481 | const keyedHashFunction* keyedHashFunctionFind(const char*); | ||
482 | BEECRYPTAPI | ||
483 | const keyedHashFunction* keyedHashFunctionDefault(void); | ||
484 | |||
485 | #ifdef __cplusplus | ||
486 | } | ||
487 | #endif | ||
488 | |||
489 | /* | ||
490 | * The struct 'keyedHashFunctionContext' is used to contain both the functional | ||
491 | * part (the keyedHashFunction), and its parameters. | ||
492 | */ | ||
493 | #ifdef __cplusplus | ||
494 | struct BEECRYPTAPI keyedHashFunctionContext | ||
495 | #else | ||
496 | struct _keyedHashFunctionContext | ||
497 | #endif | ||
498 | { | ||
499 | const keyedHashFunction* algo; | ||
500 | keyedHashFunctionParam* param; | ||
501 | |||
502 | #ifdef __cplusplus | ||
503 | keyedHashFunctionContext(); | ||
504 | keyedHashFunctionContext(const keyedHashFunction*); | ||
505 | ~keyedHashFunctionContext(); | ||
506 | #endif | ||
507 | }; | ||
508 | |||
509 | #ifndef __cplusplus | ||
510 | typedef struct _keyedHashFunctionContext keyedHashFunctionContext; | ||
511 | #endif | ||
512 | |||
513 | /* | ||
514 | * The following functions can be used to initialize and free a | ||
515 | * keyedHashFunctionContext. Initializing will allocate a buffer of the size | ||
516 | * required by the keyedHashFunction, freeing will deallocate that buffer. | ||
517 | */ | ||
518 | |||
519 | #ifdef __cplusplus | ||
520 | extern "C" { | ||
521 | #endif | ||
522 | |||
523 | BEECRYPTAPI | ||
524 | int keyedHashFunctionContextInit(keyedHashFunctionContext*, const keyedHashFunction*); | ||
525 | BEECRYPTAPI | ||
526 | int keyedHashFunctionContextFree(keyedHashFunctionContext*); | ||
527 | BEECRYPTAPI | ||
528 | int keyedHashFunctionContextSetup(keyedHashFunctionContext*, const byte*, size_t); | ||
529 | BEECRYPTAPI | ||
530 | int keyedHashFunctionContextReset(keyedHashFunctionContext*); | ||
531 | BEECRYPTAPI | ||
532 | int keyedHashFunctionContextUpdate(keyedHashFunctionContext*, const byte*, size_t); | ||
533 | BEECRYPTAPI | ||
534 | int keyedHashFunctionContextUpdateMC(keyedHashFunctionContext*, const memchunk*); | ||
535 | BEECRYPTAPI | ||
536 | int keyedHashFunctionContextUpdateMP(keyedHashFunctionContext*, const mpnumber*); | ||
537 | BEECRYPTAPI | ||
538 | int keyedHashFunctionContextDigest(keyedHashFunctionContext*, byte*); | ||
539 | BEECRYPTAPI | ||
540 | int keyedHashFunctionContextDigestMP(keyedHashFunctionContext*, mpnumber*); | ||
541 | BEECRYPTAPI | ||
542 | int keyedHashFunctionContextDigestMatch(keyedHashFunctionContext*, const mpnumber*); | ||
543 | |||
544 | #ifdef __cplusplus | ||
545 | } | ||
546 | #endif | ||
547 | |||
548 | /* | ||
549 | * Block ciphers | ||
550 | */ | ||
551 | |||
552 | /*!\enum cipherOperation | ||
553 | * \brief Specifies whether to perform encryption or decryption. | ||
554 | * \ingroup BC_m | ||
555 | */ | ||
556 | typedef enum | ||
557 | { | ||
558 | NOCRYPT, | ||
559 | ENCRYPT, | ||
560 | DECRYPT | ||
561 | } cipherOperation; | ||
562 | |||
563 | /*!\typedef void blockCipherParam | ||
564 | * \brief Placeholder type definition for blockcipher parameters. | ||
565 | * \sa aesParam, blowfishParam. | ||
566 | * \ingroup BC_m | ||
567 | */ | ||
568 | typedef void blockCipherParam; | ||
569 | |||
570 | /*!\brief Prototype definition for a setup function. | ||
571 | * \ingroup BC_m | ||
572 | */ | ||
573 | typedef int (*blockCipherSetup )(blockCipherParam*, const byte*, size_t, cipherOperation); | ||
574 | |||
575 | /*!\typedef int (*blockCipherSetIV)(blockCipherParam* bp, const byte* iv) | ||
576 | * \brief Prototype definition for an initialization vector setup function. | ||
577 | * \param bp The blockcipher's parameters. | ||
578 | * \param iv The blockciphers' IV value. | ||
579 | * \note iv length must be equal to the cipher's block size. | ||
580 | * \retval 0 on success. | ||
581 | * \retval -1 on failure. | ||
582 | * \ingroup BC_m | ||
583 | */ | ||
584 | typedef int (*blockCipherSetIV )(blockCipherParam*, const byte*); | ||
585 | |||
586 | /*!\typedef int (*blockCipherRawcrypt)(blockCipherParam* bp, uint32_t* dst, const uint32_t* src) | ||
587 | * \brief Prototype for a \e raw encryption or decryption function. | ||
588 | * \param bp The blockcipher's parameters. | ||
589 | * \param dst The ciphertext address; must be aligned on 32-bit boundary. | ||
590 | * \param src The cleartext address; must be aligned on 32-bit boundary. | ||
591 | * \retval 0 on success. | ||
592 | * \retval -1 on failure. | ||
593 | * \ingroup BC_m | ||
594 | */ | ||
595 | typedef int (*blockCipherRawcrypt)(blockCipherParam*, uint32_t*, const uint32_t*); | ||
596 | |||
597 | /*!\typedef int (*blockCipherModcrypt)(blockCipherParam* bp, uint32_t* dst, const uint32_t* src, unsigned int nblocks) | ||
598 | * \brief Prototype for a \e encryption or decryption function which operates | ||
599 | * on multiple blocks in a certain mode. | ||
600 | * \param bp The blockcipher's parameters. | ||
601 | * \param dst The ciphertext address; must be aligned on 32-bit boundary. | ||
602 | * \param src The cleartext address; must be aligned on 32-bit boundary. | ||
603 | * \param nblocks The number of blocks to process. | ||
604 | * \retval 0 on success. | ||
605 | * \retval -1 on failure. | ||
606 | * \ingroup BC_m | ||
607 | */ | ||
608 | typedef int (*blockCipherModcrypt)(blockCipherParam*, uint32_t*, const uint32_t*, unsigned int); | ||
609 | |||
610 | typedef uint32_t* (*blockCipherFeedback)(blockCipherParam*); | ||
611 | |||
612 | typedef struct | ||
613 | { | ||
614 | const blockCipherRawcrypt encrypt; | ||
615 | const blockCipherRawcrypt decrypt; | ||
616 | } blockCipherRaw; | ||
617 | |||
618 | typedef struct | ||
619 | { | ||
620 | const blockCipherModcrypt encrypt; | ||
621 | const blockCipherModcrypt decrypt; | ||
622 | } blockCipherMode; | ||
623 | |||
624 | /*!\brief Holds information and pointers to code specific to each cipher. | ||
625 | * | ||
626 | * Specific block ciphers \e may be written to be multithread-safe. | ||
627 | * | ||
628 | * \ingroup BC_m | ||
629 | */ | ||
630 | #ifdef __cplusplus | ||
631 | struct BEECRYPTAPI blockCipher | ||
632 | #else | ||
633 | struct _blockCipher | ||
634 | #endif | ||
635 | { | ||
636 | /*!\var name | ||
637 | * \brief The blockcipher's name. | ||
638 | */ | ||
639 | const char* name; | ||
640 | /*!\var paramsize | ||
641 | * \brief The size of the parameters required by this cipher, in bytes. | ||
642 | */ | ||
643 | const size_t paramsize; | ||
644 | /*!\var blocksize | ||
645 | * \brief The size of one block of data, in bytes. | ||
646 | */ | ||
647 | const size_t blocksize; | ||
648 | /*!\var keybitsmin | ||
649 | * \brief The minimum number of key bits. | ||
650 | */ | ||
651 | const size_t keybitsmin; | ||
652 | /*!\var keybitsmax | ||
653 | * \brief The maximum number of key bits. | ||
654 | */ | ||
655 | const size_t keybitsmax; | ||
656 | /*!\var keybitsinc | ||
657 | * \brief The allowed increment in key bits between min and max. | ||
658 | * \see keybitsmin and keybitsmax. | ||
659 | */ | ||
660 | const size_t keybitsinc; | ||
661 | /*!\var setup | ||
662 | * \brief Pointer to the cipher's setup function. | ||
663 | */ | ||
664 | const blockCipherSetup setup; | ||
665 | /*!\var setiv | ||
666 | * \brief Pointer to the cipher's initialization vector setup function. | ||
667 | */ | ||
668 | const blockCipherSetIV setiv; | ||
669 | /*!\var raw | ||
670 | * \brief The cipher's raw functions. | ||
671 | */ | ||
672 | const blockCipherRaw raw; | ||
673 | /*!\var ecb | ||
674 | * \brief The cipher's ECB functions. | ||
675 | */ | ||
676 | const blockCipherMode ecb; | ||
677 | const blockCipherMode cbc; | ||
678 | /*!\var getfb | ||
679 | * \brief Pointer to the cipher's feedback-returning function. | ||
680 | */ | ||
681 | const blockCipherFeedback getfb; | ||
682 | }; | ||
683 | |||
684 | #ifndef __cplusplus | ||
685 | typedef struct _blockCipher blockCipher; | ||
686 | #endif | ||
687 | |||
688 | #ifdef __cplusplus | ||
689 | extern "C" { | ||
690 | #endif | ||
691 | |||
692 | /*!\fn int blockCipherCount() | ||
693 | * \brief This function returns the number of blockciphers implemented | ||
694 | * by the library. | ||
695 | * \return The number of implemented blockciphers. | ||
696 | */ | ||
697 | BEECRYPTAPI | ||
698 | int blockCipherCount(void); | ||
699 | |||
700 | /*!\fn const blockCipher* blockCipherGet(int n) | ||
701 | * \brief This function returns the \a n -th blockcipher implemented by | ||
702 | * the library. | ||
703 | * \param n Index of the requested blockcipher; legal values are 0 | ||
704 | * through blockCipherCount() - 1. | ||
705 | * \return A pointer to a blockcipher or null, if the index was out of | ||
706 | * range. | ||
707 | */ | ||
708 | BEECRYPTAPI | ||
709 | const blockCipher* blockCipherGet(int); | ||
710 | |||
711 | /*!\fn const blockCipher* blockCipherFind(const char* name) | ||
712 | * \brief This function returns the blockcipher specified by the given name. | ||
713 | * \param name Name of the requested blockcipher. | ||
714 | * \return A pointer to a blockcipher or null, if the name wasn't found. | ||
715 | */ | ||
716 | BEECRYPTAPI | ||
717 | const blockCipher* blockCipherFind(const char*); | ||
718 | |||
719 | /*!\fn const blockCipher* blockCipherDefault() | ||
720 | * \brief This functions returns the default blockcipher; the default value | ||
721 | * can be specified by setting environment variable BEECRYPT_CIPHER. | ||
722 | * \return A pointer to a blockcipher or null, in case an error occured. | ||
723 | */ | ||
724 | BEECRYPTAPI | ||
725 | const blockCipher* blockCipherDefault(void); | ||
726 | |||
727 | #ifdef __cplusplus | ||
728 | } | ||
729 | #endif | ||
730 | |||
731 | /*!\brief Holds a pointer to a blockcipher as well as its parameters. | ||
732 | * \warning A context can be used by only one thread at the same time. | ||
733 | * \ingroup BC_m | ||
734 | */ | ||
735 | #ifdef __cplusplus | ||
736 | struct BEECRYPTAPI blockCipherContext | ||
737 | #else | ||
738 | struct _blockCipherContext | ||
739 | #endif | ||
740 | { | ||
741 | /*!\var algo | ||
742 | * \brief Pointer to a blockCipher. | ||
743 | */ | ||
744 | const blockCipher* algo; | ||
745 | /*!\var param | ||
746 | * \brief Pointer to the parameters used by algo. | ||
747 | */ | ||
748 | blockCipherParam* param; | ||
749 | /*!\var op | ||
750 | */ | ||
751 | cipherOperation op; | ||
752 | |||
753 | #ifdef __cplusplus | ||
754 | blockCipherContext(); | ||
755 | blockCipherContext(const blockCipher*); | ||
756 | ~blockCipherContext(); | ||
757 | #endif | ||
758 | }; | ||
759 | |||
760 | #ifndef __cplusplus | ||
761 | typedef struct _blockCipherContext blockCipherContext; | ||
762 | #endif | ||
763 | |||
764 | /* | ||
765 | * The following functions can be used to initialize and free a | ||
766 | * blockCipherContext. Initializing will allocate a buffer of the size | ||
767 | * required by the blockCipher, freeing will deallocate that buffer. | ||
768 | */ | ||
769 | |||
770 | #ifdef __cplusplus | ||
771 | extern "C" { | ||
772 | #endif | ||
773 | |||
774 | BEECRYPTAPI | ||
775 | int blockCipherContextInit(blockCipherContext*, const blockCipher*); | ||
776 | |||
777 | BEECRYPTAPI | ||
778 | int blockCipherContextSetup(blockCipherContext*, const byte*, size_t, cipherOperation); | ||
779 | |||
780 | BEECRYPTAPI | ||
781 | int blockCipherContextSetIV(blockCipherContext*, const byte*); | ||
782 | |||
783 | BEECRYPTAPI | ||
784 | int blockCipherContextFree(blockCipherContext*); | ||
785 | |||
786 | BEECRYPTAPI | ||
787 | int blockCipherContextECB(blockCipherContext*, uint32_t*, const uint32_t*, int); | ||
788 | |||
789 | BEECRYPTAPI | ||
790 | int blockCipherContextCBC(blockCipherContext*, uint32_t*, const uint32_t*, int); | ||
791 | |||
792 | BEECRYPTAPI | ||
793 | int blockCipherContextValidKeylen(blockCipherContext*, size_t); | ||
794 | |||
795 | #ifdef __cplusplus | ||
796 | } | ||
797 | #endif | ||
798 | |||
799 | #endif | ||