diff options
author | Werner Koch <[email protected]> | 1998-04-08 19:49:02 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 1998-04-08 19:49:02 +0000 |
commit | 8b10a87908f4d382735a046e7d043ebc250d8d67 (patch) | |
tree | 9c4255d5cd84df663f9a7001b7b6277e53cf6e6e /cipher | |
parent | New tests (diff) | |
download | gnupg-8b10a87908f4d382735a046e7d043ebc250d8d67.tar.gz gnupg-8b10a87908f4d382735a046e7d043ebc250d8d67.zip |
test release
Diffstat (limited to 'cipher')
-rw-r--r-- | cipher/ChangeLog | 4 | ||||
-rw-r--r-- | cipher/blowfish.c | 76 | ||||
-rw-r--r-- | cipher/cipher.c | 6 | ||||
-rw-r--r-- | cipher/misc.c | 21 |
4 files changed, 43 insertions, 64 deletions
diff --git a/cipher/ChangeLog b/cipher/ChangeLog index e1bc0b8ec..bc9261b75 100644 --- a/cipher/ChangeLog +++ b/cipher/ChangeLog @@ -1,3 +1,7 @@ +Wed Apr 8 14:57:11 1998 Werner Koch ([email protected]) + + * misc.c (check_pubkey_algo2): New. + Tue Apr 7 18:46:49 1998 Werner Koch ([email protected]) * cipher.c: New diff --git a/cipher/blowfish.c b/cipher/blowfish.c index 9e3c2bdcc..466e8da67 100644 --- a/cipher/blowfish.c +++ b/cipher/blowfish.c @@ -396,35 +396,17 @@ blowfish_encrypt_block( BLOWFISH_context *bc, byte *outbuf, byte *inbuf ) { u32 d1, d2; - #ifdef BIG_ENDIAN_HOST - d1 = ((u32*)inbuf)[0]; /* fixme: this may not be aligned */ - d2 = ((u32*)inbuf)[1]; - #else - ((byte*)&d1)[3] = inbuf[0]; - ((byte*)&d1)[2] = inbuf[1]; - ((byte*)&d1)[1] = inbuf[2]; - ((byte*)&d1)[0] = inbuf[3]; - ((byte*)&d2)[3] = inbuf[4]; - ((byte*)&d2)[2] = inbuf[5]; - ((byte*)&d2)[1] = inbuf[6]; - ((byte*)&d2)[0] = inbuf[7]; - #endif - + d1 = inbuf[0] << 24 | inbuf[1] << 16 | inbuf[2] << 8 | inbuf[3]; + d2 = inbuf[4] << 24 | inbuf[5] << 16 | inbuf[6] << 8 | inbuf[7]; encrypt( bc, &d1, &d2 ); - - #ifdef BIG_ENDIAN_HOST - ((u32*)outbuf)[0] = d1; - ((u32*)outbuf)[1] = d2; - #else - outbuf[0] = ((byte*)&d1)[3]; - outbuf[1] = ((byte*)&d1)[2]; - outbuf[2] = ((byte*)&d1)[1]; - outbuf[3] = ((byte*)&d1)[0]; - outbuf[4] = ((byte*)&d2)[3]; - outbuf[5] = ((byte*)&d2)[2]; - outbuf[6] = ((byte*)&d2)[1]; - outbuf[7] = ((byte*)&d2)[0]; - #endif + outbuf[0] = (d1 >> 24) & 0xff; + outbuf[1] = (d1 >> 16) & 0xff; + outbuf[2] = (d1 >> 8) & 0xff; + outbuf[3] = d1 & 0xff; + outbuf[4] = (d2 >> 24) & 0xff; + outbuf[5] = (d2 >> 16) & 0xff; + outbuf[6] = (d2 >> 8) & 0xff; + outbuf[7] = d2 & 0xff; } @@ -433,35 +415,17 @@ blowfish_decrypt_block( BLOWFISH_context *bc, byte *outbuf, byte *inbuf ) { u32 d1, d2; - #ifdef BIG_ENDIAN_HOST - d1 = ((u32*)inbuf)[0]; /* fixme: this may not be aligned */ - d2 = ((u32*)inbuf)[1]; - #else - ((byte*)&d1)[3] = inbuf[0]; - ((byte*)&d1)[2] = inbuf[1]; - ((byte*)&d1)[1] = inbuf[2]; - ((byte*)&d1)[0] = inbuf[3]; - ((byte*)&d2)[3] = inbuf[4]; - ((byte*)&d2)[2] = inbuf[5]; - ((byte*)&d2)[1] = inbuf[6]; - ((byte*)&d2)[0] = inbuf[7]; - #endif - + d1 = inbuf[0] << 24 | inbuf[1] << 16 | inbuf[2] << 8 | inbuf[3]; + d2 = inbuf[4] << 24 | inbuf[5] << 16 | inbuf[6] << 8 | inbuf[7]; decrypt( bc, &d1, &d2 ); - - #ifdef BIG_ENDIAN_HOST - ((u32*)outbuf)[0] = d1; - ((u32*)outbuf)[1] = d2; - #else - outbuf[0] = ((byte*)&d1)[3]; - outbuf[1] = ((byte*)&d1)[2]; - outbuf[2] = ((byte*)&d1)[1]; - outbuf[3] = ((byte*)&d1)[0]; - outbuf[4] = ((byte*)&d2)[3]; - outbuf[5] = ((byte*)&d2)[2]; - outbuf[6] = ((byte*)&d2)[1]; - outbuf[7] = ((byte*)&d2)[0]; - #endif + outbuf[0] = (d1 >> 24) & 0xff; + outbuf[1] = (d1 >> 16) & 0xff; + outbuf[2] = (d1 >> 8) & 0xff; + outbuf[3] = d1 & 0xff; + outbuf[4] = (d2 >> 24) & 0xff; + outbuf[5] = (d2 >> 16) & 0xff; + outbuf[6] = (d2 >> 8) & 0xff; + outbuf[7] = d2 & 0xff; } diff --git a/cipher/cipher.c b/cipher/cipher.c index 6e2bcce08..1f24c6b0e 100644 --- a/cipher/cipher.c +++ b/cipher/cipher.c @@ -225,8 +225,7 @@ do_cfb_encrypt( CIPHER_HANDLE c, byte *outbuf, byte *inbuf, unsigned nbytes ) if( nbytes <= c->unused ) { /* short enough to be encoded by the remaining XOR mask */ /* XOR the input with the IV and store input into IV */ - c->unused -= nbytes; - for(ivp=c->iv+STD_BLOCKSIZE - c->unused; nbytes; nbytes-- ) + for(ivp=c->iv+STD_BLOCKSIZE - c->unused; nbytes; nbytes--, c->unused-- ) *outbuf++ = (*ivp++ ^= *inbuf++); return; } @@ -271,8 +270,7 @@ do_cfb_decrypt( CIPHER_HANDLE c, byte *outbuf, byte *inbuf, unsigned nbytes ) if( nbytes <= c->unused ) { /* short enough to be encoded by the remaining XOR mask */ /* XOR the input with the IV and store input into IV */ - c->unused -= nbytes; - for(ivp=c->iv+STD_BLOCKSIZE - c->unused; nbytes; nbytes-- ) { + for(ivp=c->iv+STD_BLOCKSIZE - c->unused; nbytes; nbytes--,c->unused--){ temp = *inbuf++; *outbuf++ = *ivp ^ temp; *ivp++ = temp; diff --git a/cipher/misc.c b/cipher/misc.c index 35761e4f5..3016b8e56 100644 --- a/cipher/misc.c +++ b/cipher/misc.c @@ -114,18 +114,31 @@ digest_algo_to_string( int algo ) - - int check_pubkey_algo( int algo ) { + return check_pubkey_algo2( algo, 0 ); +} + +/**************** + * a usage of 0 means: don't care + */ +int +check_pubkey_algo2( int algo, unsigned usage ) +{ switch( algo ) { - case PUBKEY_ALGO_ELGAMAL: case PUBKEY_ALGO_DSA: + if( usage & 2 ) + return G10ERR_WR_PUBKEY_ALGO; + return 0; + + case PUBKEY_ALGO_ELGAMAL: + return 0; + #ifdef HAVE_RSA_CIPHER case PUBKEY_ALGO_RSA: - #endif return 0; + #endif default: return G10ERR_PUBKEY_ALGO; } |