1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-04-17 15:44:34 +02:00

* algorithms.h, cast5.c, cipher.c, idea-stub.c, twofish.c, blowfish.c,

des.c, rijndael.c: Consistently use const for input buffers.
This commit is contained in:
David Shaw 2004-10-12 17:35:50 +00:00
parent ca6dcb7258
commit b15cc684b8
9 changed files with 112 additions and 135 deletions

View File

@ -1,3 +1,9 @@
2004-10-12 David Shaw <dshaw@jabberwocky.com>
* algorithms.h, cast5.c, cipher.c, idea-stub.c, twofish.c,
blowfish.c, des.c, rijndael.c: Consistently use const for input
buffers.
2004-09-23 Werner Koch <wk@g10code.com> 2004-09-23 Werner Koch <wk@g10code.com>
* rsa.c (rsa_generate): Return the dummy list of factors only if * rsa.c (rsa_generate): Return the dummy list of factors only if

View File

@ -79,55 +79,53 @@ sha512_get_info (int algo, size_t *contextsize,
const char * const char *
des_get_info( int algo, size_t *keylen, des_get_info( int algo, size_t *keylen,
size_t *blocksize, size_t *contextsize, size_t *blocksize, size_t *contextsize,
int (**setkeyf)( void *c, byte *key, unsigned keylen ), int (**setkeyf)( void *c, const byte *key, unsigned keylen ),
void (**encryptf)( void *c, byte *outbuf, byte *inbuf ), void (**encryptf)( void *c, byte *outbuf, const byte *inbuf ),
void (**decryptf)( void *c, byte *outbuf, byte *inbuf ) void (**decryptf)( void *c, byte *outbuf, const byte *inbuf )
); );
const char * const char *
cast5_get_info( int algo, size_t *keylen, cast5_get_info( int algo, size_t *keylen,
size_t *blocksize, size_t *contextsize, size_t *blocksize, size_t *contextsize,
int (**setkeyf)( void *c, byte *key, unsigned keylen ), int (**setkeyf)( void *c, const byte *key, unsigned keylen ),
void (**encryptf)( void *c, byte *outbuf, byte *inbuf ), void (**encryptf)( void *c, byte *outbuf, const byte *inbuf ),
void (**decryptf)( void *c, byte *outbuf, byte *inbuf ) void (**decryptf)( void *c, byte *outbuf, const byte *inbuf )
); );
const char * const char *
blowfish_get_info( int algo, size_t *keylen, blowfish_get_info( int algo, size_t *keylen,
size_t *blocksize, size_t *contextsize, size_t *blocksize, size_t *contextsize,
int (**setkeyf)( void *c, byte *key, unsigned keylen ), int (**setkeyf)(void *c, const byte *key, unsigned keylen),
void (**encryptf)( void *c, byte *outbuf, byte *inbuf ), void (**encryptf)(void *c, byte *outbuf, const byte *inbuf),
void (**decryptf)( void *c, byte *outbuf, byte *inbuf ) void (**decryptf)(void *c, byte *outbuf, const byte *inbuf)
); );
const char * const char *
twofish_get_info( int algo, size_t *keylen, twofish_get_info( int algo, size_t *keylen,
size_t *blocksize, size_t *contextsize, size_t *blocksize, size_t *contextsize,
int (**setkeyf)( void *c, byte *key, unsigned keylen ), int (**setkeyf)( void *c, const byte *key, unsigned keylen ),
void (**encryptf)( void *c, byte *outbuf, byte *inbuf ), void (**encryptf)( void *c, byte *outbuf, const byte *inbuf),
void (**decryptf)( void *c, byte *outbuf, byte *inbuf ) void (**decryptf)( void *c, byte *outbuf, const byte *inbuf )
); );
/* this is just a kludge for the time we have not yet changed the cipher /* this is just a kludge for the time we have not yet changed the cipher
* stuff to the scheme we use for random and digests */ * stuff to the scheme we use for random and digests */
const char * const char *
rijndael_get_info( int algo, size_t *keylen, rijndael_get_info( int algo, size_t *keylen,
size_t *blocksize, size_t *contextsize, size_t *blocksize, size_t *contextsize,
int (**setkeyf)( void *c, byte *key, unsigned keylen ), int (**setkeyf)( void *c, const byte *key, unsigned keylen),
void (**encryptf)( void *c, byte *outbuf, byte *inbuf ), void (**encryptf)(void *c, byte *outbuf, const byte *inbuf),
void (**decryptf)( void *c, byte *outbuf, byte *inbuf ) void (**decryptf)(void *c, byte *outbuf, const byte *inbuf)
); );
const char * const char *
idea_get_info( int algo, size_t *keylen, idea_get_info( int algo, size_t *keylen,
size_t *blocksize, size_t *contextsize, size_t *blocksize, size_t *contextsize,
int (**setkeyf)( void *c, byte *key, unsigned keylen ), int (**setkeyf)( void *c, const byte *key, unsigned keylen ),
void (**encryptf)( void *c, byte *outbuf, byte *inbuf ), void (**encryptf)( void *c, byte *outbuf, const byte *inbuf ),
void (**decryptf)( void *c, byte *outbuf, byte *inbuf ) void (**decryptf)( void *c, byte *outbuf, const byte *inbuf )
); );
#endif /*GNUPG_ALGORITHMS_H*/ #endif /*GNUPG_ALGORITHMS_H*/

View File

@ -54,10 +54,7 @@ typedef struct {
u32 p[BLOWFISH_ROUNDS+2]; u32 p[BLOWFISH_ROUNDS+2];
} BLOWFISH_context; } BLOWFISH_context;
static int bf_setkey( BLOWFISH_context *c, byte *key, unsigned keylen ); static int bf_setkey( void *c, const byte *key, unsigned keylen );
static void encrypt_block( BLOWFISH_context *bc, byte *outbuf, byte *inbuf );
static void decrypt_block( BLOWFISH_context *bc, byte *outbuf, byte *inbuf );
/* precomputed S boxes */ /* precomputed S boxes */
static const u32 ks0[256] = { static const u32 ks0[256] = {
@ -424,7 +421,7 @@ decrypt( BLOWFISH_context *bc, u32 *ret_xl, u32 *ret_xr )
#undef R #undef R
static void static void
do_encrypt_block( BLOWFISH_context *bc, byte *outbuf, byte *inbuf ) do_encrypt_block( BLOWFISH_context *bc, byte *outbuf, const byte *inbuf )
{ {
u32 d1, d2; u32 d1, d2;
@ -442,14 +439,14 @@ do_encrypt_block( BLOWFISH_context *bc, byte *outbuf, byte *inbuf )
} }
static void static void
encrypt_block( BLOWFISH_context *bc, byte *outbuf, byte *inbuf ) encrypt_block( void *bc, byte *outbuf, const byte *inbuf )
{ {
do_encrypt_block (bc, outbuf, inbuf); do_encrypt_block (bc, outbuf, inbuf);
burn_stack (64); burn_stack (64);
} }
static void static void
do_decrypt_block( BLOWFISH_context *bc, byte *outbuf, byte *inbuf ) do_decrypt_block( BLOWFISH_context *bc, byte *outbuf, const byte *inbuf )
{ {
u32 d1, d2; u32 d1, d2;
@ -467,7 +464,7 @@ do_decrypt_block( BLOWFISH_context *bc, byte *outbuf, byte *inbuf )
} }
static void static void
decrypt_block( BLOWFISH_context *bc, byte *outbuf, byte *inbuf ) decrypt_block( void *bc, byte *outbuf, const byte *inbuf )
{ {
do_decrypt_block (bc, outbuf, inbuf); do_decrypt_block (bc, outbuf, inbuf);
burn_stack (64); burn_stack (64);
@ -504,7 +501,7 @@ selftest(void)
static int static int
do_bf_setkey( BLOWFISH_context *c, byte *key, unsigned keylen ) do_bf_setkey( BLOWFISH_context *c, const byte *key, unsigned keylen )
{ {
int i, j; int i, j;
u32 data, datal, datar; u32 data, datal, datar;
@ -587,7 +584,7 @@ do_bf_setkey( BLOWFISH_context *c, byte *key, unsigned keylen )
} }
static int static int
bf_setkey( BLOWFISH_context *c, byte *key, unsigned keylen ) bf_setkey( void *c, const byte *key, unsigned keylen )
{ {
int rc = do_bf_setkey (c, key, keylen); int rc = do_bf_setkey (c, key, keylen);
burn_stack (64); burn_stack (64);
@ -601,22 +598,19 @@ bf_setkey( BLOWFISH_context *c, byte *key, unsigned keylen )
* the ALGO is invalid. * the ALGO is invalid.
*/ */
const char * const char *
blowfish_get_info( int algo, size_t *keylen, blowfish_get_info(int algo, size_t *keylen,
size_t *blocksize, size_t *contextsize, size_t *blocksize, size_t *contextsize,
int (**r_setkey)( void *c, byte *key, unsigned keylen ), int (**r_setkey)(void *c, const byte *key, unsigned keylen),
void (**r_encrypt)( void *c, byte *outbuf, byte *inbuf ), void (**r_encrypt)(void *c, byte *outbuf, const byte *inbuf),
void (**r_decrypt)( void *c, byte *outbuf, byte *inbuf ) void (**r_decrypt)( void *c, byte *outbuf, const byte *inbuf)
) )
{ {
*keylen = 128; *keylen = 128;
*blocksize = BLOWFISH_BLOCKSIZE; *blocksize = BLOWFISH_BLOCKSIZE;
*contextsize = sizeof(BLOWFISH_context); *contextsize = sizeof(BLOWFISH_context);
*(int (**)(BLOWFISH_context*, byte*, unsigned))r_setkey *r_setkey = bf_setkey;
= bf_setkey; *r_encrypt = encrypt_block;
*(void (**)(BLOWFISH_context*, byte*, byte*))r_encrypt *r_decrypt = decrypt_block;
= encrypt_block;
*(void (**)(BLOWFISH_context*, byte*, byte*))r_decrypt
= decrypt_block;
if( algo == CIPHER_ALGO_BLOWFISH ) if( algo == CIPHER_ALGO_BLOWFISH )
return "BLOWFISH"; return "BLOWFISH";

View File

@ -54,12 +54,7 @@ typedef struct {
byte Kr[16]; byte Kr[16];
} CAST5_context; } CAST5_context;
static int cast_setkey( CAST5_context *c, byte *key, unsigned keylen ); static int cast_setkey( void *c, const byte *key, unsigned keylen );
static void encrypt_block( CAST5_context *bc, byte *outbuf, byte *inbuf );
static void decrypt_block( CAST5_context *bc, byte *outbuf, byte *inbuf );
static const u32 s1[256] = { static const u32 s1[256] = {
0x30fb40d4, 0x9fa0ff0b, 0x6beccd2f, 0x3f258c7a, 0x1e213f2f, 0x9c004dd3, 0x6003e540, 0xcf9fc949, 0x30fb40d4, 0x9fa0ff0b, 0x6beccd2f, 0x3f258c7a, 0x1e213f2f, 0x9c004dd3, 0x6003e540, 0xcf9fc949,
@ -368,7 +363,7 @@ burn_stack (int bytes)
static void static void
do_encrypt_block( CAST5_context *c, byte *outbuf, byte *inbuf ) do_encrypt_block( CAST5_context *c, byte *outbuf, const byte *inbuf )
{ {
u32 l, r, t; u32 l, r, t;
u32 I; /* used by the Fx macros */ u32 I; /* used by the Fx macros */
@ -422,14 +417,14 @@ do_encrypt_block( CAST5_context *c, byte *outbuf, byte *inbuf )
} }
static void static void
encrypt_block( CAST5_context *c, byte *outbuf, byte *inbuf ) encrypt_block( void *c, byte *outbuf, const byte *inbuf )
{ {
do_encrypt_block (c, outbuf, inbuf); do_encrypt_block (c, outbuf, inbuf);
burn_stack (20+4*sizeof(void*)); burn_stack (20+4*sizeof(void*));
} }
static void static void
do_decrypt_block (CAST5_context *c, byte *outbuf, byte *inbuf ) do_decrypt_block (CAST5_context *c, byte *outbuf, const byte *inbuf )
{ {
u32 l, r, t; u32 l, r, t;
u32 I; u32 I;
@ -470,7 +465,7 @@ do_decrypt_block (CAST5_context *c, byte *outbuf, byte *inbuf )
} }
static void static void
decrypt_block( CAST5_context *c, byte *outbuf, byte *inbuf ) decrypt_block( void *c, byte *outbuf, const byte *inbuf )
{ {
do_decrypt_block (c, outbuf, inbuf); do_decrypt_block (c, outbuf, inbuf);
burn_stack (20+4*sizeof(void*)); burn_stack (20+4*sizeof(void*));
@ -573,7 +568,7 @@ key_schedule( u32 *x, u32 *z, u32 *k )
static int static int
do_cast_setkey( CAST5_context *c, byte *key, unsigned keylen ) do_cast_setkey( CAST5_context *c, const byte *key, unsigned keylen )
{ {
static int initialized; static int initialized;
static const char* selftest_failed; static const char* selftest_failed;
@ -616,7 +611,7 @@ do_cast_setkey( CAST5_context *c, byte *key, unsigned keylen )
} }
static int static int
cast_setkey( CAST5_context *c, byte *key, unsigned keylen ) cast_setkey( void *c, const byte *key, unsigned keylen )
{ {
int rc = do_cast_setkey (c, key, keylen); int rc = do_cast_setkey (c, key, keylen);
burn_stack (96+7*sizeof(void*)); burn_stack (96+7*sizeof(void*));
@ -631,22 +626,18 @@ cast_setkey( CAST5_context *c, byte *key, unsigned keylen )
*/ */
const char * const char *
cast5_get_info( int algo, size_t *keylen, cast5_get_info( int algo, size_t *keylen,
size_t *blocksize, size_t *contextsize, size_t *blocksize, size_t *contextsize,
int (**r_setkey)( void *c, byte *key, unsigned keylen ), int (**r_setkey)( void *c, const byte *key, unsigned keylen ),
void (**r_encrypt)( void *c, byte *outbuf, byte *inbuf ), void (**r_encrypt)( void *c, byte *outbuf, const byte *inbuf ),
void (**r_decrypt)( void *c, byte *outbuf, byte *inbuf ) void (**r_decrypt)( void *c, byte *outbuf, const byte *inbuf )
) )
{ {
*keylen = 128; *keylen = 128;
*blocksize = CAST5_BLOCKSIZE; *blocksize = CAST5_BLOCKSIZE;
*contextsize = sizeof(CAST5_context); *contextsize = sizeof(CAST5_context);
*(int (**)(CAST5_context*, byte*, unsigned))r_setkey *r_setkey = cast_setkey;
= cast_setkey; *r_encrypt = encrypt_block;
*(void (**)(CAST5_context*, byte*, byte*))r_encrypt *r_decrypt = decrypt_block;
= encrypt_block;
*(void (**)(CAST5_context*, byte*, byte*))r_decrypt
= decrypt_block;
if( algo == CIPHER_ALGO_CAST5 ) if( algo == CIPHER_ALGO_CAST5 )
return "CAST5"; return "CAST5";

View File

@ -43,9 +43,9 @@ struct cipher_table_s {
size_t blocksize; size_t blocksize;
size_t keylen; size_t keylen;
size_t contextsize; /* allocate this amount of context */ size_t contextsize; /* allocate this amount of context */
int (*setkey)( void *c, byte *key, unsigned keylen ); int (*setkey)( void *c, const byte *key, unsigned keylen );
void (*encrypt)( void *c, byte *outbuf, byte *inbuf ); void (*encrypt)( void *c, byte *outbuf, const byte *inbuf );
void (*decrypt)( void *c, byte *outbuf, byte *inbuf ); void (*decrypt)( void *c, byte *outbuf, const byte *inbuf );
}; };
static struct cipher_table_s cipher_table[TABLE_SIZE]; static struct cipher_table_s cipher_table[TABLE_SIZE];
@ -59,9 +59,9 @@ struct cipher_handle_s {
byte iv[MAX_BLOCKSIZE]; /* (this should be ulong aligned) */ byte iv[MAX_BLOCKSIZE]; /* (this should be ulong aligned) */
byte lastiv[MAX_BLOCKSIZE]; byte lastiv[MAX_BLOCKSIZE];
int unused; /* in IV */ int unused; /* in IV */
int (*setkey)( void *c, byte *key, unsigned keylen ); int (*setkey)( void *c, const byte *key, unsigned keylen );
void (*encrypt)( void *c, byte *outbuf, byte *inbuf ); void (*encrypt)( void *c, byte *outbuf, const byte *inbuf );
void (*decrypt)( void *c, byte *outbuf, byte *inbuf ); void (*decrypt)( void *c, byte *outbuf, const byte *inbuf );
PROPERLY_ALIGNED_TYPE context; PROPERLY_ALIGNED_TYPE context;
}; };
@ -431,7 +431,6 @@ cipher_setkey( CIPHER_HANDLE c, byte *key, unsigned keylen )
} }
void void
cipher_setiv( CIPHER_HANDLE c, const byte *iv, unsigned ivlen ) cipher_setiv( CIPHER_HANDLE c, const byte *iv, unsigned ivlen )
{ {
@ -447,8 +446,6 @@ cipher_setiv( CIPHER_HANDLE c, const byte *iv, unsigned ivlen )
c->unused = 0; c->unused = 0;
} }
static void static void
do_ecb_encrypt( CIPHER_HANDLE c, byte *outbuf, byte *inbuf, unsigned nblocks ) do_ecb_encrypt( CIPHER_HANDLE c, byte *outbuf, byte *inbuf, unsigned nblocks )
{ {

View File

@ -41,7 +41,7 @@
* bits are parity bits and they will _not_ checked in this implementation, but * bits are parity bits and they will _not_ checked in this implementation, but
* simply ignored. * simply ignored.
* *
* For Tripple-DES you could use either two 64bit keys or three 64bit keys. * For Triple-DES you could use either two 64bit keys or three 64bit keys.
* The parity bits will _not_ checked, too. * The parity bits will _not_ checked, too.
* *
* After initializing a context with a key you could use this context to * After initializing a context with a key you could use this context to
@ -948,7 +948,7 @@ selftest (void)
static int static int
do_tripledes_setkey ( struct _tripledes_ctx *ctx, byte *key, unsigned keylen ) do_tripledes_setkey ( void *ctx, const byte *key, unsigned keylen )
{ {
if( selftest_failed ) if( selftest_failed )
return G10ERR_SELFTEST_FAILED; return G10ERR_SELFTEST_FAILED;
@ -968,14 +968,14 @@ do_tripledes_setkey ( struct _tripledes_ctx *ctx, byte *key, unsigned keylen )
static void static void
do_tripledes_encrypt( struct _tripledes_ctx *ctx, byte *outbuf, byte *inbuf ) do_tripledes_encrypt( void *ctx, byte *outbuf, const byte *inbuf )
{ {
tripledes_ecb_encrypt ( ctx, inbuf, outbuf ); tripledes_ecb_encrypt ( ctx, inbuf, outbuf );
burn_stack (32); burn_stack (32);
} }
static void static void
do_tripledes_decrypt( struct _tripledes_ctx *ctx, byte *outbuf, byte *inbuf ) do_tripledes_decrypt( void *ctx, byte *outbuf, const byte *inbuf )
{ {
tripledes_ecb_decrypt ( ctx, inbuf, outbuf ); tripledes_ecb_decrypt ( ctx, inbuf, outbuf );
burn_stack (32); burn_stack (32);
@ -990,11 +990,11 @@ do_tripledes_decrypt( struct _tripledes_ctx *ctx, byte *outbuf, byte *inbuf )
*/ */
const char * const char *
des_get_info( int algo, size_t *keylen, des_get_info( int algo, size_t *keylen,
size_t *blocksize, size_t *contextsize, size_t *blocksize, size_t *contextsize,
int (**r_setkey)( void *c, byte *key, unsigned keylen ), int (**r_setkey)( void *c, const byte *key, unsigned keylen ),
void (**r_encrypt)( void *c, byte *outbuf, byte *inbuf ), void (**r_encrypt)( void *c, byte *outbuf, const byte *inbuf ),
void (**r_decrypt)( void *c, byte *outbuf, byte *inbuf ) void (**r_decrypt)( void *c, byte *outbuf, const byte *inbuf )
) )
{ {
static int did_selftest = 0; static int did_selftest = 0;
@ -1012,12 +1012,9 @@ des_get_info( int algo, size_t *keylen,
*keylen = 192; *keylen = 192;
*blocksize = 8; *blocksize = 8;
*contextsize = sizeof(struct _tripledes_ctx); *contextsize = sizeof(struct _tripledes_ctx);
*(int (**)(struct _tripledes_ctx*, byte*, unsigned))r_setkey *r_setkey = do_tripledes_setkey;
= do_tripledes_setkey; *r_encrypt = do_tripledes_encrypt;
*(void (**)(struct _tripledes_ctx*, byte*, byte*))r_encrypt *r_decrypt = do_tripledes_decrypt;
= do_tripledes_encrypt;
*(void (**)(struct _tripledes_ctx*, byte*, byte*))r_decrypt
= do_tripledes_decrypt;
return "3DES"; return "3DES";
} }
return NULL; return NULL;

View File

@ -109,9 +109,9 @@ dlsym ( void *handle, const char *name )
typedef typedef
const char *(*INFO_FNC)(int, size_t*, size_t*, size_t*, const char *(*INFO_FNC)(int, size_t*, size_t*, size_t*,
int (**)( void *, byte *, unsigned), int (**)( void *, const byte *, unsigned),
void (**)( void *, byte *, byte *), void (**)( void *, byte *, const byte *),
void (**)( void *, byte *, byte *)); void (**)( void *, byte *, const byte *));
static INFO_FNC static INFO_FNC
load_module (const char *name) load_module (const char *name)
@ -152,11 +152,11 @@ load_module (const char *name)
const char * const char *
idea_get_info( int algo, size_t *keylen, idea_get_info( int algo, size_t *keylen,
size_t *blocksize, size_t *contextsize, size_t *blocksize, size_t *contextsize,
int (**r_setkey)( void *c, byte *key, unsigned keylen ), int (**r_setkey)( void *c, const byte *key, unsigned keylen ),
void (**r_encrypt)( void *c, byte *outbuf, byte *inbuf ), void (**r_encrypt)( void *c, byte *outbuf, const byte *inbuf ),
void (**r_decrypt)( void *c, byte *outbuf, byte *inbuf ) void (**r_decrypt)( void *c, byte *outbuf, const byte *inbuf )
) )
{ {
static int initialized; static int initialized;
static INFO_FNC info_fnc; static INFO_FNC info_fnc;

View File

@ -1824,7 +1824,7 @@ do_setkey (RIJNDAEL_context *ctx, const byte *key, const unsigned keylen)
} }
static int static int
rijndael_setkey (RIJNDAEL_context *ctx, const byte *key, const unsigned keylen) rijndael_setkey (void *ctx, const byte *key, const unsigned keylen)
{ {
int rc = do_setkey (ctx, key, keylen); int rc = do_setkey (ctx, key, keylen);
burn_stack ( 100 + 16*sizeof(int)); burn_stack ( 100 + 16*sizeof(int));
@ -1948,7 +1948,7 @@ do_encrypt (const RIJNDAEL_context *ctx, byte *b, const byte *a)
} }
static void static void
rijndael_encrypt (const RIJNDAEL_context *ctx, byte *b, const byte *a) rijndael_encrypt (void *ctx, byte *b, const byte *a)
{ {
do_encrypt (ctx, b, a); do_encrypt (ctx, b, a);
burn_stack (16 + 2*sizeof(int)); burn_stack (16 + 2*sizeof(int));
@ -2042,7 +2042,7 @@ do_decrypt (RIJNDAEL_context *ctx, byte *b, const byte *a)
} }
static void static void
rijndael_decrypt (RIJNDAEL_context *ctx, byte *b, const byte *a) rijndael_decrypt (void *ctx, byte *b, const byte *a)
{ {
do_decrypt (ctx, b, a); do_decrypt (ctx, b, a);
burn_stack (16+2*sizeof(int)); burn_stack (16+2*sizeof(int));
@ -2127,25 +2127,22 @@ selftest (void)
return NULL; return NULL;
} }
const char * const char *
rijndael_get_info (int algo, size_t *keylen, rijndael_get_info(int algo, size_t *keylen,
size_t *blocksize, size_t *contextsize, size_t *blocksize, size_t *contextsize,
int (**r_setkey) (void *c, byte *key, unsigned keylen), int (**r_setkey)(void *c, const byte *key, unsigned keylen),
void (**r_encrypt) (void *c, byte *outbuf, byte *inbuf), void (**r_encrypt)(void *c, byte *outbuf, const byte *inbuf),
void (**r_decrypt) (void *c, byte *outbuf, byte *inbuf) void (**r_decrypt)(void *c, byte *outbuf, const byte *inbuf)
) )
{ {
*keylen = algo==7? 128 : algo==8? 192 : 256; *keylen = algo==7? 128 : algo==8? 192 : 256;
*blocksize = 16; *blocksize = 16;
*contextsize = sizeof (RIJNDAEL_context); *contextsize = sizeof (RIJNDAEL_context);
*(int (**)(RIJNDAEL_context*, const byte*, const unsigned))r_setkey *r_setkey = rijndael_setkey;
= rijndael_setkey; *r_encrypt = rijndael_encrypt;
*(void (**)(const RIJNDAEL_context*, byte*, const byte*))r_encrypt *r_decrypt = rijndael_decrypt;
= rijndael_encrypt;
*(void (**)(RIJNDAEL_context*, byte*, const byte*))r_decrypt
= rijndael_decrypt;
if( algo == 7 ) if( algo == 7 )
return "AES"; return "AES";

View File

@ -696,7 +696,7 @@ do_twofish_setkey (TWOFISH_context *ctx, const byte *key, unsigned int keylen)
} }
static int static int
twofish_setkey (TWOFISH_context *ctx, const byte *key, unsigned int keylen) twofish_setkey (void *ctx, const byte *key, unsigned int keylen)
{ {
int rc = do_twofish_setkey (ctx, key, keylen); int rc = do_twofish_setkey (ctx, key, keylen);
burn_stack (23+6*sizeof(void*)); burn_stack (23+6*sizeof(void*));
@ -798,7 +798,7 @@ do_twofish_encrypt (const TWOFISH_context *ctx, byte *out, const byte *in)
} }
static void static void
twofish_encrypt (const TWOFISH_context *ctx, byte *out, const byte *in) twofish_encrypt (void *ctx, byte *out, const byte *in)
{ {
do_twofish_encrypt (ctx, out, in); do_twofish_encrypt (ctx, out, in);
burn_stack (24+3*sizeof (void*)); burn_stack (24+3*sizeof (void*));
@ -839,7 +839,7 @@ do_twofish_decrypt (const TWOFISH_context *ctx, byte *out, const byte *in)
} }
static void static void
twofish_decrypt (const TWOFISH_context *ctx, byte *out, const byte *in) twofish_decrypt (void *ctx, byte *out, const byte *in)
{ {
do_twofish_decrypt (ctx, out, in); do_twofish_decrypt (ctx, out, in);
burn_stack (24+3*sizeof (void*)); burn_stack (24+3*sizeof (void*));
@ -1008,25 +1008,22 @@ main()
} }
#endif /* TEST */ #endif /* TEST */
const char * const char *
twofish_get_info (int algo, size_t *keylen, twofish_get_info(int algo, size_t *keylen,
size_t *blocksize, size_t *contextsize, size_t *blocksize, size_t *contextsize,
int (**r_setkey) (void *c, byte *key, unsigned keylen), int (**r_setkey) (void *c, const byte *key, unsigned keylen),
void (**r_encrypt) (void *c, byte *outbuf, byte *inbuf), void (**r_encrypt) (void *c, byte *outbuf, const byte *inbuf),
void (**r_decrypt) (void *c, byte *outbuf, byte *inbuf) void (**r_decrypt) (void *c, byte *outbuf, const byte *inbuf)
) )
{ {
*keylen = algo==10? 256 : 128; *keylen = algo==10? 256 : 128;
*blocksize = 16; *blocksize = 16;
*contextsize = sizeof (TWOFISH_context); *contextsize = sizeof (TWOFISH_context);
*(int (**)(TWOFISH_context*, const byte*, const unsigned))r_setkey *r_setkey = twofish_setkey;
= twofish_setkey; *r_encrypt = twofish_encrypt;
*(void (**)(const TWOFISH_context*, byte*, const byte*))r_encrypt *r_decrypt = twofish_decrypt;
= twofish_encrypt;
*(void (**)(const TWOFISH_context*, byte*, const byte*))r_decrypt
= twofish_decrypt;
if( algo == 10 ) if( algo == 10 )
return "TWOFISH"; return "TWOFISH";