Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

beecrypt.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1999, 2000, 2001, 2002 Virtual Unlimited B.V.
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  * 
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  * 
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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  * Entropy Sources
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  * Pseudo-random Number Generators
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  * The struct 'randomGenerator' holds information and pointers to code specific
00134  * to each random generator. Each specific random generator MUST be written to
00135  * be multithread safe.
00136  *
00137  * WARNING: each randomGenerator, when used in cryptographic applications, MUST
00138  * be guaranteed to be of suitable quality and strength (i.e. don't use the
00139  * random() function found in most UN*X-es).
00140  *
00141  * Multiple instances of each randomGenerator can be used (even concurrently),
00142  * provided they each use their own randomGeneratorParam parameters, a chunk
00143  * of memory which must be at least as large as indicated by the paramsize
00144  * field.
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  * You can use the following functions to find random generators implemented by
00184  * the library:
00185  *
00186  * randomGeneratorCount returns the number of generators available.
00187  *
00188  * randomGeneratorGet returns the random generator with a given index (starting
00189  * at zero, up to randomGeneratorCount() - 1), or NULL if the index was out of
00190  * bounds.
00191  *
00192  * randomGeneratorFind returns the random generator with the given name, or
00193  * NULL if no random generator exists with that name.
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  * The struct 'randomGeneratorContext' is used to contain both the functional
00215  * part (the randomGenerator), and its parameters.
00216  */
00217 
00218 typedef struct
00219 {
00220     const randomGenerator* rng;
00221     randomGeneratorParam* param;
00222 } randomGeneratorContext;
00223 
00224 /*
00225  * The following functions can be used to initialize and free a
00226  * randomGeneratorContext. Initializing will allocate a buffer of the size
00227  * required by the randomGenerator, freeing will deallocate that buffer.
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  * Hash Functions
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  * The struct 'hashFunction' holds information and pointers to code specific
00260  * to each hash function. Specific hash functions MAY be written to be
00261  * multithread-safe.
00262  *
00263  * NOTE: data MUST have a size (in bytes) of at least 'digestsize' as described
00264  * in the hashFunction struct.
00265  * NOTE: for safety reasons, after calling digest, each specific implementation
00266  * MUST reset itself so that previous values in the parameters are erased.
00267  */
00268 
00269 typedef struct
00270 {
00271     const char*                 name;
00272     const size_t                paramsize;  /* in bytes */
00273     const size_t                blocksize;  /* in bytes */
00274     const size_t                digestsize; /* in bytes */
00275     const hashFunctionReset     reset;
00276     const hashFunctionUpdate    update;
00277     const hashFunctionDigest    digest;
00278 } hashFunction;
00279 
00280 /*
00281  * You can use the following functions to find hash functions implemented by
00282  * the library:
00283  *
00284  * hashFunctionCount returns the number of hash functions available.
00285  *
00286  * hashFunctionGet returns the hash function with a given index (starting
00287  * at zero, up to hashFunctionCount() - 1), or NULL if the index was out of
00288  * bounds.
00289  *
00290  * hashFunctionFind returns the hash function with the given name, or
00291  * NULL if no hash function exists with that name.
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  * The struct 'hashFunctionContext' is used to contain both the functional
00313  * part (the hashFunction), and its parameters.
00314  */
00315 
00316 typedef struct
00317 {
00318     const hashFunction* algo;
00319     hashFunctionParam* param;
00320 } hashFunctionContext;
00321 
00322 /*
00323  * The following functions can be used to initialize and free a
00324  * hashFunctionContext. Initializing will allocate a buffer of the size
00325  * required by the hashFunction, freeing will deallocate that buffer.
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  * Keyed Hash Functions, a.k.a. Message Authentication Codes
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  * The struct 'keyedHashFunction' holds information and pointers to code
00371  * specific to each keyed hash function. Specific keyed hash functions MAY be
00372  * written to be multithread-safe.
00373  *
00374  * The struct field 'keybitsmin' contains the minimum number of bits a key
00375  * must contains, 'keybitsmax' the maximum number of bits a key may contain,
00376  * 'keybitsinc', the increment in bits that may be used between min and max.
00377  * 
00378  * NOTE: data must be at least have a bytesize of 'digestsize' as described
00379  * in the keyedHashFunction struct.
00380  * NOTE: for safety reasons, after calling digest, each specific implementation
00381  * MUST reset itself so that previous values in the parameters are erased.
00382  */
00383 
00384 typedef struct
00385 {
00386     const char*                     name;
00387     const size_t                    paramsize;  /* in bytes */
00388     const size_t                    blocksize;  /* in bytes */
00389     const size_t                    digestsize; /* in bytes */
00390     const size_t                    keybitsmin; /* in bits */
00391     const size_t                    keybitsmax; /* in bits */
00392     const size_t                    keybitsinc; /* in bits */
00393     const keyedHashFunctionSetup    setup;
00394     const keyedHashFunctionReset    reset;
00395     const keyedHashFunctionUpdate   update;
00396     const keyedHashFunctionDigest   digest;
00397 } keyedHashFunction;
00398 
00399 /*
00400  * You can use the following functions to find keyed hash functions implemented
00401  * by the library:
00402  *
00403  * keyedHashFunctionCount returns the number of keyed hash functions available.
00404  *
00405  * keyedHashFunctionGet returns the keyed hash function with a given index
00406  * (starting at zero, up to keyedHashFunctionCount() - 1), or NULL if the index
00407  * was out of bounds.
00408  *
00409  * keyedHashFunctionFind returns the keyed hash function with the given name,
00410  * or NULL if no keyed hash function exists with that name.
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  * The struct 'keyedHashFunctionContext' is used to contain both the functional
00432  * part (the keyedHashFunction), and its parameters.
00433  */
00434 
00435 typedef struct
00436 {
00437     const keyedHashFunction*    algo;
00438     keyedHashFunctionParam*     param;
00439 } keyedHashFunctionContext;
00440 
00441 /*
00442  * The following functions can be used to initialize and free a
00443  * keyedHashFunctionContext. Initializing will allocate a buffer of the size
00444  * required by the keyedHashFunction, freeing will deallocate that buffer.
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  * Block ciphers
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  * The following functions can be used to initialize and free a
00672  * blockCipherContext. Initializing will allocate a buffer of the size
00673  * required by the blockCipher, freeing will deallocate that buffer.
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

Generated on Wed Mar 24 13:56:53 2004 for BeeCrypt by doxygen 1.3.6