BeeCrypt
4.2.1
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
include
beecrypt
beecrypt.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 1999, 2000, 2001, 2002 X-Way Rights BV
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
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
46
typedef
int (*
entropyNext
)(
byte
*, size_t);
47
52
#ifdef __cplusplus
53
struct
BEECRYPTAPI
entropySource
54
#else
55
struct _entropySource
56
#endif
57
{
61
const
char
*
name
;
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
81
BEECRYPTAPI
82
int
entropySourceCount
(
void
);
83
92
BEECRYPTAPI
93
const
entropySource
*
entropySourceGet
(
int
n);
94
100
BEECRYPTAPI
101
const
entropySource
*
entropySourceFind
(
const
char
* name);
102
108
BEECRYPTAPI
109
const
entropySource
*
entropySourceDefault
(
void
);
110
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
160
#ifdef __cplusplus
161
struct
BEECRYPTAPI
randomGenerator
162
#else
163
struct _randomGenerator
164
#endif
165
{
169
const
char
*
name
;
175
const
size_t
paramsize
;
179
const
randomGeneratorSetup
setup
;
183
const
randomGeneratorSeed
seed
;
187
const
randomGeneratorNext
next
;
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
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
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
556
typedef
enum
557
{
558
NOCRYPT
,
559
ENCRYPT
,
560
DECRYPT
561
}
cipherOperation
;
562
568
typedef
void
blockCipherParam
;
569
573
typedef
int (*
blockCipherSetup
)(
blockCipherParam
*,
const
byte
*, size_t,
cipherOperation
);
574
584
typedef
int (*
blockCipherSetIV
)(
blockCipherParam
*,
const
byte
*);
585
596
typedef
int (*
blockCipherSetCTR
)(
blockCipherParam
*,
const
byte
*, size_t);
597
598
608
typedef
int (*
blockCipherRawcrypt
)(
blockCipherParam
*, uint32_t*,
const
uint32_t*);
609
621
typedef
int (*
blockCipherModcrypt
)(
blockCipherParam
*, uint32_t*,
const
uint32_t*,
unsigned
int);
622
623
typedef
uint32_t* (*blockCipherFeedback)(
blockCipherParam
*);
624
625
typedef
struct
626
{
627
const
blockCipherRawcrypt
encrypt
;
628
const
blockCipherRawcrypt
decrypt
;
629
}
blockCipherRaw
;
630
631
typedef
struct
632
{
633
const
blockCipherModcrypt
encrypt
;
634
const
blockCipherModcrypt
decrypt
;
635
}
blockCipherMode
;
636
643
#ifdef __cplusplus
644
struct
BEECRYPTAPI
blockCipher
645
#else
646
struct _blockCipher
647
#endif
648
{
652
const
char
*
name
;
656
const
size_t
paramsize
;
660
const
size_t
blocksize
;
664
const
size_t
keybitsmin
;
668
const
size_t
keybitsmax
;
673
const
size_t
keybitsinc
;
677
const
blockCipherSetup
setup
;
681
const
blockCipherSetIV
setiv
;
685
const
blockCipherSetCTR
setctr
;
689
const
blockCipherFeedback
getfb
;
693
const
blockCipherRaw
raw
;
697
const
blockCipherMode
ecb
;
701
const
blockCipherMode
cbc
;
705
const
blockCipherMode
ctr
;
706
};
707
708
#ifndef __cplusplus
709
typedef
struct
_blockCipher
blockCipher
;
710
#endif
711
712
#ifdef __cplusplus
713
extern
"C"
{
714
#endif
715
721
BEECRYPTAPI
722
int
blockCipherCount
(
void
);
723
732
BEECRYPTAPI
733
const
blockCipher
*
blockCipherGet
(
int
);
734
740
BEECRYPTAPI
741
const
blockCipher
*
blockCipherFind
(
const
char
*);
742
748
BEECRYPTAPI
749
const
blockCipher
*
blockCipherDefault
(
void
);
750
751
#ifdef __cplusplus
752
}
753
#endif
754
759
#ifdef __cplusplus
760
struct
BEECRYPTAPI
blockCipherContext
761
#else
762
struct _blockCipherContext
763
#endif
764
{
768
const
blockCipher
*
algo
;
772
blockCipherParam
*
param
;
775
cipherOperation
op
;
776
777
#ifdef __cplusplus
778
blockCipherContext
();
779
blockCipherContext
(
const
blockCipher
*);
780
~
blockCipherContext
();
781
#endif
782
};
783
784
#ifndef __cplusplus
785
typedef
struct
_blockCipherContext
blockCipherContext
;
786
#endif
787
788
/*
789
* The following functions can be used to initialize and free a
790
* blockCipherContext. Initializing will allocate a buffer of the size
791
* required by the blockCipher, freeing will deallocate that buffer.
792
*/
793
794
#ifdef __cplusplus
795
extern
"C"
{
796
#endif
797
798
BEECRYPTAPI
799
int
blockCipherContextInit
(
blockCipherContext
*,
const
blockCipher
*);
800
801
BEECRYPTAPI
802
int
blockCipherContextSetup
(
blockCipherContext
*,
const
byte
*,
size_t
,
cipherOperation
);
803
804
BEECRYPTAPI
805
int
blockCipherContextSetIV
(
blockCipherContext
*,
const
byte
*);
806
807
BEECRYPTAPI
808
int
blockCipherContextSetCTR
(
blockCipherContext
*,
const
byte
*,
size_t
);
809
810
BEECRYPTAPI
811
int
blockCipherContextFree
(
blockCipherContext
*);
812
813
BEECRYPTAPI
814
int
blockCipherContextECB
(
blockCipherContext
*, uint32_t*,
const
uint32_t*,
int
);
815
816
BEECRYPTAPI
817
int
blockCipherContextCBC
(
blockCipherContext
*, uint32_t*,
const
uint32_t*,
int
);
818
819
BEECRYPTAPI
820
int
blockCipherContextCTR
(
blockCipherContext
*, uint32_t*,
const
uint32_t*,
int
);
821
822
BEECRYPTAPI
823
int
blockCipherContextValidKeylen
(
blockCipherContext
*,
size_t
);
824
825
#ifdef __cplusplus
826
}
827
#endif
828
829
#endif
Generated by
1.8.4