00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00030 #ifndef _BEECRYPT_H
00031 #define _BEECRYPT_H
00032
00033 #include "beecrypt/api.h"
00034
00035 #include "beecrypt/memchunk.h"
00036 #include "beecrypt/mpnumber.h"
00037
00038
00039
00040
00041
00046 typedef int (*entropyNext)(byte*, size_t);
00047
00052 #ifdef __cplusplus
00053 struct BEECRYPTAPI entropySource
00054 #else
00055 struct _entropySource
00056 #endif
00057 {
00061 const char* name;
00065 const entropyNext next;
00066 };
00067
00068 #ifndef __cplusplus
00069 typedef struct _entropySource entropySource;
00070 #endif
00071
00072 #ifdef __cplusplus
00073 extern "C" {
00074 #endif
00075
00081 BEECRYPTAPI
00082 int entropySourceCount(void);
00083
00092 BEECRYPTAPI
00093 const entropySource* entropySourceGet(int n);
00094
00100 BEECRYPTAPI
00101 const entropySource* entropySourceFind(const char* name);
00102
00108 BEECRYPTAPI
00109 const entropySource* entropySourceDefault(void);
00110
00122 BEECRYPTAPI
00123 int entropyGatherNext(byte*, size_t);
00124
00125 #ifdef __cplusplus
00126 }
00127 #endif
00128
00129
00130
00131
00132
00133 typedef void randomGeneratorParam;
00134
00135 typedef int (*randomGeneratorSetup )(randomGeneratorParam*);
00136 typedef int (*randomGeneratorSeed )(randomGeneratorParam*, const byte*, size_t);
00137 typedef int (*randomGeneratorNext )(randomGeneratorParam*, byte*, size_t);
00138 typedef int (*randomGeneratorCleanup)(randomGeneratorParam*);
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00160 #ifdef __cplusplus
00161 struct BEECRYPTAPI randomGenerator
00162 #else
00163 struct _randomGenerator
00164 #endif
00165 {
00169 const char* name;
00175 const size_t paramsize;
00179 const randomGeneratorSetup setup;
00183 const randomGeneratorSeed seed;
00187 const randomGeneratorNext next;
00191 const randomGeneratorCleanup cleanup;
00192 };
00193
00194 #ifndef __cplusplus
00195 typedef struct _randomGenerator randomGenerator;
00196 #endif
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212 #ifdef __cplusplus
00213 extern "C" {
00214 #endif
00215
00216 BEECRYPTAPI
00217 int randomGeneratorCount(void);
00218 BEECRYPTAPI
00219 const randomGenerator* randomGeneratorGet(int);
00220 BEECRYPTAPI
00221 const randomGenerator* randomGeneratorFind(const char*);
00222 BEECRYPTAPI
00223 const randomGenerator* randomGeneratorDefault(void);
00224
00225 #ifdef __cplusplus
00226 }
00227 #endif
00228
00229
00230
00231
00232
00233
00234 #ifdef __cplusplus
00235 struct BEECRYPTAPI randomGeneratorContext
00236 #else
00237 struct _randomGeneratorContext
00238 #endif
00239 {
00240 const randomGenerator* rng;
00241 randomGeneratorParam* param;
00242
00243 #ifdef __cplusplus
00244 randomGeneratorContext();
00245 randomGeneratorContext(const randomGenerator*);
00246 ~randomGeneratorContext();
00247 #endif
00248 };
00249
00250 #ifndef __cplusplus
00251 typedef struct _randomGeneratorContext randomGeneratorContext;
00252 #endif
00253
00254
00255
00256
00257
00258
00259
00260 #ifdef __cplusplus
00261 extern "C" {
00262 #endif
00263
00264 BEECRYPTAPI
00265 int randomGeneratorContextInit(randomGeneratorContext*, const randomGenerator*);
00266 BEECRYPTAPI
00267 int randomGeneratorContextFree(randomGeneratorContext*);
00268 BEECRYPTAPI
00269 int randomGeneratorContextNext(randomGeneratorContext*, byte*, size_t);
00270 BEECRYPTAPI
00271 int randomGeneratorContextSeed(randomGeneratorContext*, const byte*, size_t);
00272
00273 #ifdef __cplusplus
00274 }
00275 #endif
00276
00277
00278
00279
00280
00284 typedef void hashFunctionParam;
00285
00286 typedef int (*hashFunctionReset )(hashFunctionParam*);
00287 typedef int (*hashFunctionUpdate)(hashFunctionParam*, const byte*, size_t);
00288 typedef int (*hashFunctionDigest)(hashFunctionParam*, byte*);
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300 #ifdef __cplusplus
00301 struct BEECRYPTAPI hashFunction
00302 #else
00303 struct _hashFunction
00304 #endif
00305 {
00306 const char* name;
00307 const size_t paramsize;
00308 const size_t blocksize;
00309 const size_t digestsize;
00310 const hashFunctionReset reset;
00311 const hashFunctionUpdate update;
00312 const hashFunctionDigest digest;
00313 };
00314
00315 #ifndef __cplusplus
00316 typedef struct _hashFunction hashFunction;
00317 #endif
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333 #ifdef __cplusplus
00334 extern "C" {
00335 #endif
00336
00337 BEECRYPTAPI
00338 int hashFunctionCount(void);
00339 BEECRYPTAPI
00340 const hashFunction* hashFunctionGet(int);
00341 BEECRYPTAPI
00342 const hashFunction* hashFunctionFind(const char*);
00343 BEECRYPTAPI
00344 const hashFunction* hashFunctionDefault(void);
00345
00346 #ifdef __cplusplus
00347 }
00348 #endif
00349
00350
00351
00352
00353
00354 #ifdef __cplusplus
00355 struct BEECRYPTAPI hashFunctionContext
00356 #else
00357 struct _hashFunctionContext
00358 #endif
00359 {
00360 const hashFunction* algo;
00361 hashFunctionParam* param;
00362
00363 #ifdef __cplusplus
00364 hashFunctionContext();
00365 hashFunctionContext(const hashFunction*);
00366 ~hashFunctionContext();
00367 #endif
00368 };
00369
00370 #ifndef __cplusplus
00371 typedef struct _hashFunctionContext hashFunctionContext;
00372 #endif
00373
00374
00375
00376
00377
00378
00379
00380 #ifdef __cplusplus
00381 extern "C" {
00382 #endif
00383
00384 BEECRYPTAPI
00385 int hashFunctionContextInit(hashFunctionContext*, const hashFunction*);
00386 BEECRYPTAPI
00387 int hashFunctionContextFree(hashFunctionContext*);
00388 BEECRYPTAPI
00389 int hashFunctionContextReset(hashFunctionContext*);
00390 BEECRYPTAPI
00391 int hashFunctionContextUpdate(hashFunctionContext*, const byte*, size_t);
00392 BEECRYPTAPI
00393 int hashFunctionContextUpdateMC(hashFunctionContext*, const memchunk*);
00394 BEECRYPTAPI
00395 int hashFunctionContextUpdateMP(hashFunctionContext*, const mpnumber*);
00396 BEECRYPTAPI
00397 int hashFunctionContextDigest(hashFunctionContext*, byte*);
00398 BEECRYPTAPI
00399 int hashFunctionContextDigestMP(hashFunctionContext*, mpnumber*);
00400 BEECRYPTAPI
00401 int hashFunctionContextDigestMatch(hashFunctionContext*, const mpnumber*);
00402
00403 #ifdef __cplusplus
00404 }
00405 #endif
00406
00407
00408
00409
00410
00414 typedef void keyedHashFunctionParam;
00415
00416 typedef int (*keyedHashFunctionSetup )(keyedHashFunctionParam*, const byte*, size_t);
00417 typedef int (*keyedHashFunctionReset )(keyedHashFunctionParam*);
00418 typedef int (*keyedHashFunctionUpdate )(keyedHashFunctionParam*, const byte*, size_t);
00419 typedef int (*keyedHashFunctionDigest )(keyedHashFunctionParam*, byte*);
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435 #ifdef __cplusplus
00436 struct BEECRYPTAPI keyedHashFunction
00437 #else
00438 struct _keyedHashFunction
00439 #endif
00440 {
00441 const char* name;
00442 const size_t paramsize;
00443 const size_t blocksize;
00444 const size_t digestsize;
00445 const size_t keybitsmin;
00446 const size_t keybitsmax;
00447 const size_t keybitsinc;
00448 const keyedHashFunctionSetup setup;
00449 const keyedHashFunctionReset reset;
00450 const keyedHashFunctionUpdate update;
00451 const keyedHashFunctionDigest digest;
00452 };
00453
00454 #ifndef __cplusplus
00455 typedef struct _keyedHashFunction keyedHashFunction;
00456 #endif
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472 #ifdef __cplusplus
00473 extern "C" {
00474 #endif
00475
00476 BEECRYPTAPI
00477 int keyedHashFunctionCount(void);
00478 BEECRYPTAPI
00479 const keyedHashFunction* keyedHashFunctionGet(int);
00480 BEECRYPTAPI
00481 const keyedHashFunction* keyedHashFunctionFind(const char*);
00482 BEECRYPTAPI
00483 const keyedHashFunction* keyedHashFunctionDefault(void);
00484
00485 #ifdef __cplusplus
00486 }
00487 #endif
00488
00489
00490
00491
00492
00493 #ifdef __cplusplus
00494 struct BEECRYPTAPI keyedHashFunctionContext
00495 #else
00496 struct _keyedHashFunctionContext
00497 #endif
00498 {
00499 const keyedHashFunction* algo;
00500 keyedHashFunctionParam* param;
00501
00502 #ifdef __cplusplus
00503 keyedHashFunctionContext();
00504 keyedHashFunctionContext(const keyedHashFunction*);
00505 ~keyedHashFunctionContext();
00506 #endif
00507 };
00508
00509 #ifndef __cplusplus
00510 typedef struct _keyedHashFunctionContext keyedHashFunctionContext;
00511 #endif
00512
00513
00514
00515
00516
00517
00518
00519 #ifdef __cplusplus
00520 extern "C" {
00521 #endif
00522
00523 BEECRYPTAPI
00524 int keyedHashFunctionContextInit(keyedHashFunctionContext*, const keyedHashFunction*);
00525 BEECRYPTAPI
00526 int keyedHashFunctionContextFree(keyedHashFunctionContext*);
00527 BEECRYPTAPI
00528 int keyedHashFunctionContextSetup(keyedHashFunctionContext*, const byte*, size_t);
00529 BEECRYPTAPI
00530 int keyedHashFunctionContextReset(keyedHashFunctionContext*);
00531 BEECRYPTAPI
00532 int keyedHashFunctionContextUpdate(keyedHashFunctionContext*, const byte*, size_t);
00533 BEECRYPTAPI
00534 int keyedHashFunctionContextUpdateMC(keyedHashFunctionContext*, const memchunk*);
00535 BEECRYPTAPI
00536 int keyedHashFunctionContextUpdateMP(keyedHashFunctionContext*, const mpnumber*);
00537 BEECRYPTAPI
00538 int keyedHashFunctionContextDigest(keyedHashFunctionContext*, byte*);
00539 BEECRYPTAPI
00540 int keyedHashFunctionContextDigestMP(keyedHashFunctionContext*, mpnumber*);
00541 BEECRYPTAPI
00542 int keyedHashFunctionContextDigestMatch(keyedHashFunctionContext*, const mpnumber*);
00543
00544 #ifdef __cplusplus
00545 }
00546 #endif
00547
00548
00549
00550
00551
00556 typedef enum
00557 {
00558 NOCRYPT,
00559 ENCRYPT,
00560 DECRYPT
00561 } cipherOperation;
00562
00568 typedef void blockCipherParam;
00569
00573 typedef int (*blockCipherSetup )(blockCipherParam*, const byte*, size_t, cipherOperation);
00574
00584 typedef int (*blockCipherSetIV )(blockCipherParam*, const byte*);
00585
00596 typedef int (*blockCipherSetCTR )(blockCipherParam*, const byte*, size_t);
00597
00598
00608 typedef int (*blockCipherRawcrypt)(blockCipherParam*, uint32_t*, const uint32_t*);
00609
00621 typedef int (*blockCipherModcrypt)(blockCipherParam*, uint32_t*, const uint32_t*, unsigned int);
00622
00623 typedef uint32_t* (*blockCipherFeedback)(blockCipherParam*);
00624
00625 typedef struct
00626 {
00627 const blockCipherRawcrypt encrypt;
00628 const blockCipherRawcrypt decrypt;
00629 } blockCipherRaw;
00630
00631 typedef struct
00632 {
00633 const blockCipherModcrypt encrypt;
00634 const blockCipherModcrypt decrypt;
00635 } blockCipherMode;
00636
00643 #ifdef __cplusplus
00644 struct BEECRYPTAPI blockCipher
00645 #else
00646 struct _blockCipher
00647 #endif
00648 {
00652 const char* name;
00656 const size_t paramsize;
00660 const size_t blocksize;
00664 const size_t keybitsmin;
00668 const size_t keybitsmax;
00673 const size_t keybitsinc;
00677 const blockCipherSetup setup;
00681 const blockCipherSetIV setiv;
00685 const blockCipherSetCTR setctr;
00689 const blockCipherFeedback getfb;
00693 const blockCipherRaw raw;
00697 const blockCipherMode ecb;
00701 const blockCipherMode cbc;
00705 const blockCipherMode ctr;
00706 };
00707
00708 #ifndef __cplusplus
00709 typedef struct _blockCipher blockCipher;
00710 #endif
00711
00712 #ifdef __cplusplus
00713 extern "C" {
00714 #endif
00715
00721 BEECRYPTAPI
00722 int blockCipherCount(void);
00723
00732 BEECRYPTAPI
00733 const blockCipher* blockCipherGet(int);
00734
00740 BEECRYPTAPI
00741 const blockCipher* blockCipherFind(const char*);
00742
00748 BEECRYPTAPI
00749 const blockCipher* blockCipherDefault(void);
00750
00751 #ifdef __cplusplus
00752 }
00753 #endif
00754
00759 #ifdef __cplusplus
00760 struct BEECRYPTAPI blockCipherContext
00761 #else
00762 struct _blockCipherContext
00763 #endif
00764 {
00768 const blockCipher* algo;
00772 blockCipherParam* param;
00775 cipherOperation op;
00776
00777 #ifdef __cplusplus
00778 blockCipherContext();
00779 blockCipherContext(const blockCipher*);
00780 ~blockCipherContext();
00781 #endif
00782 };
00783
00784 #ifndef __cplusplus
00785 typedef struct _blockCipherContext blockCipherContext;
00786 #endif
00787
00788
00789
00790
00791
00792
00793
00794 #ifdef __cplusplus
00795 extern "C" {
00796 #endif
00797
00798 BEECRYPTAPI
00799 int blockCipherContextInit(blockCipherContext*, const blockCipher*);
00800
00801 BEECRYPTAPI
00802 int blockCipherContextSetup(blockCipherContext*, const byte*, size_t, cipherOperation);
00803
00804 BEECRYPTAPI
00805 int blockCipherContextSetIV(blockCipherContext*, const byte*);
00806
00807 BEECRYPTAPI
00808 int blockCipherContextSetCTR(blockCipherContext*, const byte*, size_t);
00809
00810 BEECRYPTAPI
00811 int blockCipherContextFree(blockCipherContext*);
00812
00813 BEECRYPTAPI
00814 int blockCipherContextECB(blockCipherContext*, uint32_t*, const uint32_t*, int);
00815
00816 BEECRYPTAPI
00817 int blockCipherContextCBC(blockCipherContext*, uint32_t*, const uint32_t*, int);
00818
00819 BEECRYPTAPI
00820 int blockCipherContextCTR(blockCipherContext*, uint32_t*, const uint32_t*, int);
00821
00822 BEECRYPTAPI
00823 int blockCipherContextValidKeylen(blockCipherContext*, size_t);
00824
00825 #ifdef __cplusplus
00826 }
00827 #endif
00828
00829 #endif