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 "memchunk.h"
00036 #include "mpnumber.h"
00037
00038
00039
00040
00041
00046 typedef int (*entropyNext)(byte*, size_t);
00047
00052 typedef struct
00053 {
00057 const char* name;
00061 const entropyNext next;
00062 } entropySource;
00063
00064 #ifdef __cplusplus
00065 extern "C" {
00066 #endif
00067
00073 BEECRYPTAPI
00074 int entropySourceCount(void);
00075
00084 BEECRYPTAPI
00085 const entropySource* entropySourceGet(int n);
00086
00092 BEECRYPTAPI
00093 const entropySource* entropySourceFind(const char* name);
00094
00100 BEECRYPTAPI
00101 const entropySource* entropySourceDefault(void);
00102
00114 BEECRYPTAPI
00115 int entropyGatherNext(byte*, size_t);
00116
00117 #ifdef __cplusplus
00118 }
00119 #endif
00120
00121
00122
00123
00124
00125 typedef void randomGeneratorParam;
00126
00127 typedef int (*randomGeneratorSetup )(randomGeneratorParam*);
00128 typedef int (*randomGeneratorSeed )(randomGeneratorParam*, const byte*, size_t);
00129 typedef int (*randomGeneratorNext )(randomGeneratorParam*, byte*, size_t);
00130 typedef int (*randomGeneratorCleanup)(randomGeneratorParam*);
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00152 typedef struct
00153 {
00157 const char* name;
00163 const size_t paramsize;
00167 const randomGeneratorSetup setup;
00171 const randomGeneratorSeed seed;
00175 const randomGeneratorNext next;
00179 const randomGeneratorCleanup cleanup;
00180 } randomGenerator;
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196 #ifdef __cplusplus
00197 extern "C" {
00198 #endif
00199
00200 BEECRYPTAPI
00201 int randomGeneratorCount(void);
00202 BEECRYPTAPI
00203 const randomGenerator* randomGeneratorGet(int);
00204 BEECRYPTAPI
00205 const randomGenerator* randomGeneratorFind(const char*);
00206 BEECRYPTAPI
00207 const randomGenerator* randomGeneratorDefault(void);
00208
00209 #ifdef __cplusplus
00210 }
00211 #endif
00212
00213
00214
00215
00216
00217
00218 typedef struct
00219 {
00220 const randomGenerator* rng;
00221 randomGeneratorParam* param;
00222 } randomGeneratorContext;
00223
00224
00225
00226
00227
00228
00229
00230 #ifdef __cplusplus
00231 extern "C" {
00232 #endif
00233
00234 BEECRYPTAPI
00235 int randomGeneratorContextInit(randomGeneratorContext*, const randomGenerator*);
00236 BEECRYPTAPI
00237 int randomGeneratorContextFree(randomGeneratorContext*);
00238 BEECRYPTAPI
00239 int randomGeneratorContextNext(randomGeneratorContext*, byte*, size_t);
00240
00241 #ifdef __cplusplus
00242 }
00243 #endif
00244
00245
00246
00247
00248
00252 typedef void hashFunctionParam;
00253
00254 typedef int (*hashFunctionReset )(hashFunctionParam*);
00255 typedef int (*hashFunctionUpdate)(hashFunctionParam*, const byte*, size_t);
00256 typedef int (*hashFunctionDigest)(hashFunctionParam*, byte*);
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269 typedef struct
00270 {
00271 const char* name;
00272 const size_t paramsize;
00273 const size_t blocksize;
00274 const size_t digestsize;
00275 const hashFunctionReset reset;
00276 const hashFunctionUpdate update;
00277 const hashFunctionDigest digest;
00278 } hashFunction;
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294 #ifdef __cplusplus
00295 extern "C" {
00296 #endif
00297
00298 BEECRYPTAPI
00299 int hashFunctionCount(void);
00300 BEECRYPTAPI
00301 const hashFunction* hashFunctionGet(int);
00302 BEECRYPTAPI
00303 const hashFunction* hashFunctionFind(const char*);
00304 BEECRYPTAPI
00305 const hashFunction* hashFunctionDefault(void);
00306
00307 #ifdef __cplusplus
00308 }
00309 #endif
00310
00311
00312
00313
00314
00315
00316 typedef struct
00317 {
00318 const hashFunction* algo;
00319 hashFunctionParam* param;
00320 } hashFunctionContext;
00321
00322
00323
00324
00325
00326
00327
00328 #ifdef __cplusplus
00329 extern "C" {
00330 #endif
00331
00332 BEECRYPTAPI
00333 int hashFunctionContextInit(hashFunctionContext*, const hashFunction*);
00334 BEECRYPTAPI
00335 int hashFunctionContextFree(hashFunctionContext*);
00336 BEECRYPTAPI
00337 int hashFunctionContextReset(hashFunctionContext*);
00338 BEECRYPTAPI
00339 int hashFunctionContextUpdate(hashFunctionContext*, const byte*, size_t);
00340 BEECRYPTAPI
00341 int hashFunctionContextUpdateMC(hashFunctionContext*, const memchunk*);
00342 BEECRYPTAPI
00343 int hashFunctionContextUpdateMP(hashFunctionContext*, const mpnumber*);
00344 BEECRYPTAPI
00345 int hashFunctionContextDigest(hashFunctionContext*, byte*);
00346 BEECRYPTAPI
00347 int hashFunctionContextDigestMP(hashFunctionContext*, mpnumber*);
00348 BEECRYPTAPI
00349 int hashFunctionContextDigestMatch(hashFunctionContext*, const mpnumber*);
00350
00351 #ifdef __cplusplus
00352 }
00353 #endif
00354
00355
00356
00357
00358
00362 typedef void keyedHashFunctionParam;
00363
00364 typedef int (*keyedHashFunctionSetup )(keyedHashFunctionParam*, const byte*, size_t);
00365 typedef int (*keyedHashFunctionReset )(keyedHashFunctionParam*);
00366 typedef int (*keyedHashFunctionUpdate )(keyedHashFunctionParam*, const byte*, size_t);
00367 typedef int (*keyedHashFunctionDigest )(keyedHashFunctionParam*, byte*);
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384 typedef struct
00385 {
00386 const char* name;
00387 const size_t paramsize;
00388 const size_t blocksize;
00389 const size_t digestsize;
00390 const size_t keybitsmin;
00391 const size_t keybitsmax;
00392 const size_t keybitsinc;
00393 const keyedHashFunctionSetup setup;
00394 const keyedHashFunctionReset reset;
00395 const keyedHashFunctionUpdate update;
00396 const keyedHashFunctionDigest digest;
00397 } keyedHashFunction;
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413 #ifdef __cplusplus
00414 extern "C" {
00415 #endif
00416
00417 BEECRYPTAPI
00418 int keyedHashFunctionCount(void);
00419 BEECRYPTAPI
00420 const keyedHashFunction* keyedHashFunctionGet(int);
00421 BEECRYPTAPI
00422 const keyedHashFunction* keyedHashFunctionFind(const char*);
00423 BEECRYPTAPI
00424 const keyedHashFunction* keyedHashFunctionDefault(void);
00425
00426 #ifdef __cplusplus
00427 }
00428 #endif
00429
00430
00431
00432
00433
00434
00435 typedef struct
00436 {
00437 const keyedHashFunction* algo;
00438 keyedHashFunctionParam* param;
00439 } keyedHashFunctionContext;
00440
00441
00442
00443
00444
00445
00446
00447 #ifdef __cplusplus
00448 extern "C" {
00449 #endif
00450
00451 BEECRYPTAPI
00452 int keyedHashFunctionContextInit(keyedHashFunctionContext*, const keyedHashFunction*);
00453 BEECRYPTAPI
00454 int keyedHashFunctionContextFree(keyedHashFunctionContext*);
00455 BEECRYPTAPI
00456 int keyedHashFunctionContextSetup(keyedHashFunctionContext*, const byte*, size_t);
00457 BEECRYPTAPI
00458 int keyedHashFunctionContextReset(keyedHashFunctionContext*);
00459 BEECRYPTAPI
00460 int keyedHashFunctionContextUpdate(keyedHashFunctionContext*, const byte*, size_t);
00461 BEECRYPTAPI
00462 int keyedHashFunctionContextUpdateMC(keyedHashFunctionContext*, const memchunk*);
00463 BEECRYPTAPI
00464 int keyedHashFunctionContextUpdateMP(keyedHashFunctionContext*, const mpnumber*);
00465 BEECRYPTAPI
00466 int keyedHashFunctionContextDigest(keyedHashFunctionContext*, byte*);
00467 BEECRYPTAPI
00468 int keyedHashFunctionContextDigestMP(keyedHashFunctionContext*, mpnumber*);
00469 BEECRYPTAPI
00470 int keyedHashFunctionContextDigestMatch(keyedHashFunctionContext*, const mpnumber*);
00471
00472 #ifdef __cplusplus
00473 }
00474 #endif
00475
00476
00477
00478
00479
00484 typedef enum
00485 {
00486 NOCRYPT,
00487 ENCRYPT,
00488 DECRYPT
00489 } cipherOperation;
00490
00496 typedef void blockCipherParam;
00497
00501 typedef int (*blockCipherSetup )(blockCipherParam*, const byte*, size_t, cipherOperation);
00502
00512 typedef int (*blockCipherSetIV )(blockCipherParam*, const byte*);
00513
00523 typedef int (*blockCipherRawcrypt)(blockCipherParam*, uint32_t*, const uint32_t*);
00524
00536 typedef int (*blockCipherModcrypt)(blockCipherParam*, uint32_t*, const uint32_t*, unsigned int);
00537
00538 typedef uint32_t* (*blockCipherFeedback)(blockCipherParam*);
00539
00540 typedef struct
00541 {
00542 const blockCipherRawcrypt encrypt;
00543 const blockCipherRawcrypt decrypt;
00544 } blockCipherRaw;
00545
00546 typedef struct
00547 {
00548 const blockCipherModcrypt encrypt;
00549 const blockCipherModcrypt decrypt;
00550 } blockCipherMode;
00551
00558 typedef struct
00559 {
00563 const char* name;
00567 const size_t paramsize;
00571 const size_t blocksize;
00575 const size_t keybitsmin;
00579 const size_t keybitsmax;
00584 const size_t keybitsinc;
00588 const blockCipherSetup setup;
00592 const blockCipherSetIV setiv;
00596 const blockCipherRaw raw;
00600 const blockCipherMode ecb;
00601 const blockCipherMode cbc;
00605 const blockCipherFeedback getfb;
00606 } blockCipher;
00607
00608 #ifdef __cplusplus
00609 extern "C" {
00610 #endif
00611
00617 BEECRYPTAPI
00618 int blockCipherCount(void);
00619
00628 BEECRYPTAPI
00629 const blockCipher* blockCipherGet(int);
00630
00636 BEECRYPTAPI
00637 const blockCipher* blockCipherFind(const char*);
00638
00644 BEECRYPTAPI
00645 const blockCipher* blockCipherDefault(void);
00646
00647 #ifdef __cplusplus
00648 }
00649 #endif
00650
00655 typedef struct
00656 {
00660 const blockCipher* algo;
00664 blockCipherParam* param;
00667 cipherOperation op;
00668 } blockCipherContext;
00669
00670
00671
00672
00673
00674
00675
00676 #ifdef __cplusplus
00677 extern "C" {
00678 #endif
00679
00680 BEECRYPTAPI
00681 int blockCipherContextInit(blockCipherContext*, const blockCipher*);
00682
00683 BEECRYPTAPI
00684 int blockCipherContextSetup(blockCipherContext*, const byte*, size_t, cipherOperation);
00685
00686 BEECRYPTAPI
00687 int blockCipherContextSetIV(blockCipherContext*, const byte*);
00688
00689 BEECRYPTAPI
00690 int blockCipherContextFree(blockCipherContext*);
00691
00692 BEECRYPTAPI
00693 int blockCipherContextECB(blockCipherContext*, uint32_t*, const uint32_t*, int);
00694
00695 BEECRYPTAPI
00696 int blockCipherContextCBC(blockCipherContext*, uint32_t*, const uint32_t*, int);
00697
00698 #ifdef __cplusplus
00699 }
00700 #endif
00701
00702 #endif