diff options
author | Werner Koch <wk@gnupg.org> | 1998-09-14 15:49:50 +0000 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 1998-09-14 15:49:50 +0000 |
commit | 91e0657206cc084d6877d6da26e3475f8f82c612 (patch) | |
tree | f2928a468eaf4919e716cdd6896a1b2a2171c634 /cipher/blowfish.c | |
parent | 4301e92fe95887a7ecab8206eb1ed7eea77a766c (diff) | |
download | libgcrypt-91e0657206cc084d6877d6da26e3475f8f82c612.tar.gz |
New release
Diffstat (limited to 'cipher/blowfish.c')
-rw-r--r-- | cipher/blowfish.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/cipher/blowfish.c b/cipher/blowfish.c index 3ed2ed85..f5c29c6a 100644 --- a/cipher/blowfish.c +++ b/cipher/blowfish.c @@ -41,7 +41,7 @@ #define CIPHER_ALGO_BLOWFISH 4 /* blowfish 128 bit key */ #define CIPHER_ALGO_BLOWFISH160 42 /* blowfish 160 bit key (not in OpenPGP)*/ -#define FNCCAST_SETKEY(f) (void(*)(void*, byte*, unsigned))(f) +#define FNCCAST_SETKEY(f) (int(*)(void*, byte*, unsigned))(f) #define FNCCAST_CRYPT(f) (void(*)(void*, byte*, byte*))(f) #define BLOWFISH_BLOCKSIZE 8 @@ -55,7 +55,7 @@ typedef struct { u32 p[BLOWFISH_ROUNDS+2]; } BLOWFISH_context; -static void bf_setkey( BLOWFISH_context *c, byte *key, unsigned keylen ); +static int bf_setkey( BLOWFISH_context *c, 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 ); @@ -480,7 +480,7 @@ selftest() -static void +static int bf_setkey( BLOWFISH_context *c, byte *key, unsigned keylen ) { int i, j; @@ -543,6 +543,19 @@ bf_setkey( BLOWFISH_context *c, byte *key, unsigned keylen ) c->s3[i] = datal; c->s3[i+1] = datar; } + + + /* Check for weak key. A weak key is a key in which a value in */ + /* the P-array (here c) occurs more than once per table. */ + for(i=0; i < 255; i++ ) { + for( j=i+1; j < 256; j++) { + if( (c->s0[i] == c->s0[j]) || (c->s1[i] == c->s1[j]) || + (c->s2[i] == c->s2[j]) || (c->s3[i] == c->s3[j]) ) + return G10ERR_WEAK_KEY; + } + } + + return 0; } @@ -555,7 +568,7 @@ bf_setkey( BLOWFISH_context *c, byte *key, unsigned keylen ) const char * blowfish_get_info( int algo, size_t *keylen, size_t *blocksize, size_t *contextsize, - void (**r_setkey)( void *c, byte *key, unsigned keylen ), + int (**r_setkey)( void *c, byte *key, unsigned keylen ), void (**r_encrypt)( void *c, byte *outbuf, byte *inbuf ), void (**r_decrypt)( void *c, byte *outbuf, byte *inbuf ) ) |