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

# beecrypt/beecrypt.h

Go to the documentation of this file.

    00001 /*
    00002  * beecrypt.h
    00003  *
    00004  * BeeCrypt library hooks & stubs, header
    00005  *
    00006  * Copyright (c) 1999, 2000, 2001 Virtual Unlimited B.V.
    00007  *
    00008  * Author: Bob Deblier <bob@virtualunlimited.com>
    00009  *
    00010  * This library is free software; you can redistribute it and/or
    00011  * modify it under the terms of the GNU Lesser General Public
    00012  * License as published by the Free Software Foundation; either
    00013  * version 2.1 of the License, or (at your option) any later version.
    00014  *
    00015  * This library is distributed in the hope that it will be useful,
    00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00018  * Lesser General Public License for more details.
    00019  *
    00020  * You should have received a copy of the GNU Lesser General Public
    00021  * License along with this library; if not, write to the Free Software
    00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00023  *
    00024  */
    00025
    00026 #ifndef _BEECRYPT_H
    00027 #define _BEECRYPT_H
    00028
    00029 #include "types.h"
    00030
    00031 #include "memchunk.h"
    00032 #include "mp32number.h"
    00033
    00036
    00045 typedef int (*entropyNext) (/*@out@*/ uint32* data, int size)
    00046         /*@modifies data @*/;
    00047
    00052 typedef struct
    00053 {
    00054 /*@observer@*/
    00055     const char* name;
    00056 /*@unused@*/
    00057     const entropyNext next;
    00058 } entropySource;
    00059
    00060 #ifdef __cplusplus
    00061 extern "C" {
    00062 #endif
    00063
    00068 BEECRYPTAPI /*@unused@*/
    00069 int entropySourceCount(void)
    00070         /*@*/;
    00071
    00077 BEECRYPTAPI /*@observer@*/ /*@null@*/ /*@unused@*/
    00078 const entropySource* entropySourceGet(int index)
    00079         /*@*/;
    00080
    00086 /*@-exportlocal@*/
    00087 BEECRYPTAPI /*@observer@*/ /*@null@*/
    00088 const entropySource* entropySourceFind(const char* name)
    00089         /*@*/;
    00090 /*@=exportlocal@*/
    00091
    00098 BEECRYPTAPI /*@observer@*/ /*@null@*/ /*@unused@*/
    00099 const entropySource* entropySourceDefault(void)
    00100         /*@*/;
    00101
    00109 BEECRYPTAPI
    00110 int entropyGatherNext(uint32* data, int size)
    00111         /*@*/;
    00112
    00113 #ifdef __cplusplus
    00114 }
    00115 #endif
    00116
    00120
    00123 typedef void randomGeneratorParam;
    00124
    00132 typedef int (*randomGeneratorSetup) (randomGeneratorParam* param)
    00133         /*@modifies *param @*/;
    00134
    00143 typedef int (*randomGeneratorSeed) (randomGeneratorParam* param, const uint32* data, int size)
    00144         /*@modifies *param @*/;
    00145
    00155 typedef int (*randomGeneratorNext) (randomGeneratorParam* param, /*@out@*/ uint32* data, int size)
    00156         /*@modifies *param, *data @*/;
    00157
    00164 typedef int (*randomGeneratorCleanup) (randomGeneratorParam* param)
    00165         /*@modifies *param @*/;
    00166
    00181 typedef struct
    00182 {
    00183 /*@observer@*/
    00184     const char* name;
    00185     const unsigned int paramsize;
    00186     const randomGeneratorSetup setup;
    00187     const randomGeneratorSeed seed;
    00188     const randomGeneratorNext next;
    00189     const randomGeneratorCleanup cleanup;
    00190 } randomGenerator;
    00191
    00192 #ifdef __cplusplus
    00193 extern "C" {
    00194 #endif
    00195
    00200 BEECRYPTAPI /*@unused@*/
    00201 int randomGeneratorCount(void)
    00202         /*@*/;
    00203
    00209 BEECRYPTAPI /*@observer@*/ /*@null@*/ /*@unused@*/
    00210 const randomGenerator* randomGeneratorGet(int index)
    00211         /*@*/;
    00212
    00218 /*@-exportlocal@*/
    00219 BEECRYPTAPI /*@observer@*/ /*@null@*/
    00220 const randomGenerator* randomGeneratorFind(const char* name)
    00221         /*@*/;
    00222 /*@=exportlocal@*/
    00223
    00230 BEECRYPTAPI /*@observer@*/ /*@null@*/ /*@unused@*/
    00231 const randomGenerator* randomGeneratorDefault(void)
    00232         /*@*/;
    00233
    00234 #ifdef __cplusplus
    00235 }
    00236 #endif
    00237
    00241 typedef struct
    00242 {
    00243 /*@observer@*/ /*@dependent@*/
    00244     const randomGenerator* rng;
    00245 /*@only@*/
    00246     randomGeneratorParam* param;
    00247 } randomGeneratorContext;
    00248
    00249 #ifdef __cplusplus
    00250 extern "C" {
    00251 #endif
    00252
    00256 BEECRYPTAPI /*@unused@*/
    00257 int randomGeneratorContextInit(randomGeneratorContext* ctxt, /*@observer@*/ /*@dependent@*/ const randomGenerator* rng)
    00258         /*@modifies ctxt->rng, ctxt->param @*/;
    00259
    00263 BEECRYPTAPI /*@unused@*/
    00264 int randomGeneratorContextFree(/*@special@*/ randomGeneratorContext* ctxt)
    00265         /*@uses ctxt->rng @*/
    00266         /*@releases ctxt->param @*/
    00267         /*@modifies ctxt->rng, ctxt->param @*/;
    00268
    00269 BEECRYPTAPI /*@unused@*/
    00270 int randomGeneratorContextNext(randomGeneratorContext* ctxt, /*@out@*/ uint32* data, int size)
    00271         /*@modifies ctxt->param, *data @*/;
    00272
    00273 #ifdef __cplusplus
    00274 }
    00275 #endif
    00276
    00280
    00283 BEECRYPTAPI
    00284 typedef void hashFunctionParam;
    00285
    00292 typedef int (*hashFunctionReset) (hashFunctionParam* param)
    00293         /*@modifies *param @*/;
    00294
    00303 typedef int (*hashFunctionUpdate) (hashFunctionParam* param, const byte* data, int size)
    00304         /*@modifies *param @*/;
    00305
    00320 typedef int (*hashFunctionDigest) (hashFunctionParam* param, /*@out@*/ uint32* data)
    00321         /*@modifies *param, *data @*/;
    00322
    00327 typedef struct
    00328 {
    00329 /*@observer@*/
    00330     const char* name;
    00331     const unsigned int paramsize;
    00332     const unsigned int blocksize;
    00333     const unsigned int digestsize;
    00334     const hashFunctionReset reset;
    00335     const hashFunctionUpdate update;
    00336     const hashFunctionDigest digest;
    00337 } hashFunction;
    00338
    00339 #ifdef __cplusplus
    00340 extern "C" {
    00341 #endif
    00342
    00347 BEECRYPTAPI /*@unused@*/
    00348 int hashFunctionCount(void)
    00349         /*@*/;
    00350
    00356 BEECRYPTAPI /*@observer@*/ /*@null@*/ /*@unused@*/
    00357 const hashFunction* hashFunctionGet(int index)
    00358         /*@*/;
    00359
    00365 /*@-exportlocal@*/
    00366 BEECRYPTAPI /*@observer@*/ /*@null@*/
    00367 const hashFunction* hashFunctionFind(const char* name)
    00368         /*@*/;
    00369 /*@=exportlocal@*/
    00370
    00377 BEECRYPTAPI /*@observer@*/ /*@null@*/ /*@unused@*/
    00378 const hashFunction* hashFunctionDefault(void)
    00379         /*@*/;
    00380
    00381 #ifdef __cplusplus
    00382 }
    00383 #endif
    00384
    00388 typedef struct
    00389 {
    00390 /*@observer@*/ /*@dependent@*/
    00391     const hashFunction* algo;
    00392 /*@only@*/
    00393     hashFunctionParam* param;
    00394 } hashFunctionContext;
    00395
    00396 #ifdef __cplusplus
    00397 extern "C" {
    00398 #endif
    00399
    00403 BEECRYPTAPI
    00404 int hashFunctionContextInit(hashFunctionContext* ctxt, /*@observer@*/ /*@dependent@*/ const hashFunction* hash)
    00405         /*@modifies ctxt->algo, ctxt->param */;
    00406
    00410 BEECRYPTAPI
    00411 int hashFunctionContextFree(/*@special@*/ hashFunctionContext* ctxt)
    00412         /*@releases ctxt->param @*/
    00413         /*@modifies ctxt->algo, ctxt->param */;
    00414
    00417 BEECRYPTAPI
    00418 int hashFunctionContextReset(hashFunctionContext* ctxt)
    00419         /*@modifies ctxt */;
    00420
    00423 BEECRYPTAPI /*@unused@*/
    00424 int hashFunctionContextUpdate(hashFunctionContext* ctxt, const byte* data, int size)
    00425         /*@modifies ctxt */;
    00426
    00429 BEECRYPTAPI /*@unused@*/
    00430 int hashFunctionContextUpdateMC(hashFunctionContext* ctxt, const memchunk* m)
    00431         /*@modifies ctxt */;
    00432
    00435 BEECRYPTAPI
    00436 int hashFunctionContextUpdateMP32(hashFunctionContext* ctxt, const mp32number* n)
    00437         /*@modifies ctxt */;
    00438
    00441 BEECRYPTAPI
    00442 int hashFunctionContextDigest(hashFunctionContext* ctxt, mp32number* dig)
    00443         /*@modifies ctxt, *dig */;
    00444
    00447 BEECRYPTAPI /*@unused@*/
    00448 int hashFunctionContextDigestMatch(hashFunctionContext* ctxt, const mp32number* match)
    00449         /*@modifies ctxt */;
    00450
    00451 #ifdef __cplusplus
    00452 }
    00453 #endif
    00454
    00458
    00461 typedef void keyedHashFunctionParam;
    00462
    00475 typedef int (*keyedHashFunctionSetup) (keyedHashFunctionParam* param, const uint32* key, int keybits)
    00476         /*@modifies *param @*/;
    00477
    00484 typedef int (*keyedHashFunctionReset) (keyedHashFunctionParam* param)
    00485         /*@modifies *param @*/;
    00486
    00495 typedef int (*keyedHashFunctionUpdate) (keyedHashFunctionParam* param, const byte* data, int size)
    00496         /*@modifies *param @*/;
    00497
    00512 typedef int (*keyedHashFunctionDigest) (keyedHashFunctionParam* param, /*@out@*/ uint32* data)
    00513         /*@modifies *param, *data @*/;
    00514
    00519 typedef struct
    00520 {
    00521 /*@observer@*/
    00522     const char* name;
    00523     const unsigned int paramsize;
    00524     const unsigned int blocksize;
    00525     const unsigned int digestsize;
    00526     const unsigned int keybitsmin;
    00527     const unsigned int keybitsmax;
    00528     const unsigned int keybitsinc;
    00529     const keyedHashFunctionSetup setup;
    00530     const keyedHashFunctionReset reset;
    00531     const keyedHashFunctionUpdate update;
    00532     const keyedHashFunctionDigest digest;
    00533 } keyedHashFunction;
    00534
    00535 #ifdef __cplusplus
    00536 extern "C" {
    00537 #endif
    00538
    00543 BEECRYPTAPI /*@unused@*/
    00544 int keyedHashFunctionCount(void)
    00545         /*@*/;
    00546
    00552 BEECRYPTAPI /*@observer@*/ /*@null@*/ /*@unused@*/
    00553 const keyedHashFunction* keyedHashFunctionGet(int index)
    00554         /*@*/;
    00555
    00561 /*@-exportlocal@*/
    00562 BEECRYPTAPI /*@observer@*/ /*@null@*/
    00563 const keyedHashFunction* keyedHashFunctionFind(const char* name)
    00564         /*@*/;
    00565 /*@=exportlocal@*/
    00566
    00573 BEECRYPTAPI /*@observer@*/ /*@null@*/ /*@unused@*/
    00574 const keyedHashFunction* keyedHashFunctionDefault(void)
    00575         /*@*/;
    00576
    00577 #ifdef __cplusplus
    00578 }
    00579 #endif
    00580
    00584 typedef struct
    00585 {
    00586 /*@observer@*/ /*@dependent@*/
    00587     const keyedHashFunction* algo;
    00588 /*@only@*/
    00589     keyedHashFunctionParam* param;
    00590 } keyedHashFunctionContext;
    00591
    00592 #ifdef __cplusplus
    00593 extern "C" {
    00594 #endif
    00595
    00599 BEECRYPTAPI
    00600 int keyedHashFunctionContextInit(keyedHashFunctionContext* ctxt, /*@observer@*/ /*@dependent@*/ const keyedHashFunction* mac)
    00601         /*@modifies ctxt->algo, ctxt->param @*/;
    00602
    00606 BEECRYPTAPI
    00607 int keyedHashFunctionContextFree(/*@special@*/ keyedHashFunctionContext* ctxt)
    00608         /*@uses ctxt->algo @*/
    00609         /*@releases ctxt->param @*/
    00610         /*@modifies ctxt->algo, ctxt->param @*/;
    00611
    00614 BEECRYPTAPI
    00615 int keyedHashFunctionContextSetup(keyedHashFunctionContext* ctxt, const uint32* key, int keybits)
    00616         /*@modifies ctxt @*/;
    00617
    00620 BEECRYPTAPI /*@unused@*/
    00621 int keyedHashFunctionContextReset(keyedHashFunctionContext* ctxt)
    00622         /*@modifies ctxt @*/;
    00623
    00626 BEECRYPTAPI /*@unused@*/
    00627 int keyedHashFunctionContextUpdate(keyedHashFunctionContext* ctxt, const byte* data, int size)
    00628         /*@modifies ctxt @*/;
    00629
    00632 BEECRYPTAPI
    00633 int keyedHashFunctionContextUpdateMC(keyedHashFunctionContext* ctxt, const memchunk* m)
    00634         /*@modifies ctxt @*/;
    00635
    00638 BEECRYPTAPI /*@unused@*/
    00639 int keyedHashFunctionContextUpdateMP32(keyedHashFunctionContext* ctxt, const mp32number* n)
    00640         /*@modifies ctxt @*/;
    00641
    00644 BEECRYPTAPI
    00645 int keyedHashFunctionContextDigest(keyedHashFunctionContext* ctxt, mp32number* dig)
    00646         /*@modifies ctxt, *dig @*/;
    00647
    00650 BEECRYPTAPI
    00651 int keyedHashFunctionContextDigestMatch(keyedHashFunctionContext* ctxt, const mp32number* match)
    00652         /*@modifies ctxt @*/;
    00653
    00654 #ifdef __cplusplus
    00655 }
    00656 #endif
    00657
    00661
    00664 typedef void blockCipherParam;
    00665
    00669 typedef enum
    00670 {
    00671         ENCRYPT,
    00672         DECRYPT
    00673 } cipherOperation;
    00674
    00678 /*@-enummemuse@*/
    00679 typedef enum
    00680 {
    00681         ECB,
    00682         CBC
    00683 } cipherMode;
    00684 /*@=enummemuse@*/
    00685
    00693 typedef int (*blockModeEncrypt) (blockCipherParam* param, int count, uint32* dst, const uint32* src)
    00694         /*@modifies *param, *dst @*/;
    00695
    00703 typedef int (*blockModeDecrypt) (blockCipherParam* param, int count, uint32* dst, const uint32* src)
    00704         /*@modifies *param, *dst @*/;
    00705
    00708 typedef struct
    00709 {
    00710         const blockModeEncrypt  encrypt;
    00711         const blockModeDecrypt  decrypt;
    00712 } blockMode;
    00713
    00727 typedef int (*blockCipherSetup) (blockCipherParam* param, const uint32* key, int keybits, cipherOperation cipherOperation)
    00728         /*@modifies param @*/;
    00729
    00736 typedef int (*blockCipherSetIV) (blockCipherParam* param, const uint32* data)
    00737         /*@modifies param @*/;
    00738
    00748 typedef int (*blockCipherEncrypt) (blockCipherParam* param, uint32* dst, const uint32* src)
    00749         /*@modifies param, dst @*/;
    00750
    00760 typedef int (*blockCipherDecrypt) (blockCipherParam* param, uint32* dst, const uint32* src)
    00761         /*@modifies param, dst @*/;
    00762
    00767 typedef struct
    00768 {
    00769 /*@observer@*/
    00770     const char* name;
    00771     const unsigned int paramsize;
    00772     const unsigned int blocksize;
    00773     const unsigned int keybitsmin;
    00774     const unsigned int keybitsmax;
    00775     const unsigned int keybitsinc;
    00776     const blockCipherSetup setup;
    00777     const blockCipherSetIV setiv;
    00778     const blockCipherEncrypt encrypt;
    00779     const blockCipherDecrypt decrypt;
    00780 /*@dependent@*/
    00781     const blockMode* mode;
    00782 } blockCipher;
    00783
    00784 #ifdef __cplusplus
    00785 extern "C" {
    00786 #endif
    00787
    00792 BEECRYPTAPI /*@unused@*/
    00793 int blockCipherCount(void)
    00794         /*@*/;
    00795
    00801 BEECRYPTAPI /*@observer@*/ /*@null@*/ /*@unused@*/
    00802 const blockCipher* blockCipherGet(int index)
    00803         /*@*/;
    00804
    00810 /*@-exportlocal@*/
    00811 BEECRYPTAPI /*@observer@*/ /*@null@*/
    00812 const blockCipher* blockCipherFind(const char* name)
    00813         /*@*/;
    00814 /*@=exportlocal@*/
    00815
    00822 BEECRYPTAPI /*@observer@*/ /*@null@*/ /*@unused@*/
    00823 const blockCipher* blockCipherDefault(void)
    00824         /*@*/;
    00825
    00826 #ifdef __cplusplus
    00827 }
    00828 #endif
    00829
    00833 typedef struct
    00834 {
    00835 /*@observer@*/ /*@dependent@*/
    00836     const blockCipher* algo;
    00837 /*@only@*/
    00838     blockCipherParam* param;
    00839 } blockCipherContext;
    00840
    00841 #ifdef __cplusplus
    00842 extern "C" {
    00843 #endif
    00844
    00848 BEECRYPTAPI
    00849 int blockCipherContextInit(blockCipherContext* ctxt, /*@observer@*/ /*@dependent@*/ const blockCipher* ciph)
    00850         /*@modifies ctxt->algo, ctxt->param @*/;
    00851
    00854 BEECRYPTAPI
    00855 int blockCipherContextSetup(blockCipherContext* ctxt, const uint32* key, int keybits, cipherOperation op)
    00856         /*@modifies ctxt @*/;
    00857
    00860 BEECRYPTAPI /*@unused@*/
    00861 int blockCipherContextSetIV(blockCipherContext* ctxt, const uint32* iv)
    00862         /*@modifies ctxt @*/;
    00863
    00867 BEECRYPTAPI
    00868 int blockCipherContextFree(/*@special@*/ blockCipherContext* ctxt)
    00869         /*@releases ctxt->param @*/
    00870         /*@modifies ctxt->algo, ctxt->param @*/;
    00871
    00872 #ifdef __cplusplus
    00873 }
    00874 #endif
    00875
    00877 #endif