diff options
author | Werner Koch <[email protected]> | 1998-09-14 15:49:56 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 1998-09-14 15:49:56 +0000 |
commit | c07a88da5d293db89726767fef58090177b423f4 (patch) | |
tree | 7ea1d5d10d3e65cf29c4b03616772fb4c829f4d1 /cipher/blowfish.c | |
parent | Updates (diff) | |
download | gnupg-c07a88da5d293db89726767fef58090177b423f4.tar.gz gnupg-c07a88da5d293db89726767fef58090177b423f4.zip |
New release
Diffstat (limited to '')
-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 3ed2ed858..f5c29c6aa 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 ) ) |