diff options
author | Werner Koch <[email protected]> | 1999-01-17 10:06:03 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 1999-01-17 10:06:03 +0000 |
commit | befacf7efa649de7ee4421a154cc06a40a181cf2 (patch) | |
tree | 8197e739f35fbe9d4afa9dc96cfa82aee75d74f5 /cipher/cast5.c | |
parent | See ChangeLog: Sat Jan 16 21:25:17 CET 1999 Werner Koch (diff) | |
download | gnupg-befacf7efa649de7ee4421a154cc06a40a181cf2.tar.gz gnupg-befacf7efa649de7ee4421a154cc06a40a181cf2.zip |
See ChangeLog: Sun Jan 17 11:04:33 CET 1999 Werner Koch
Diffstat (limited to '')
-rw-r--r-- | cipher/cast5.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/cipher/cast5.c b/cipher/cast5.c index 279838fa3..6f131ca23 100644 --- a/cipher/cast5.c +++ b/cipher/cast5.c @@ -39,9 +39,8 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <assert.h> -#include "util.h" #include "types.h" +#include "errors.h" #include "cast5.h" @@ -455,7 +454,7 @@ decrypt_block( CAST5_context *c, byte *outbuf, byte *inbuf ) -static void +static const char* selftest() { CAST5_context c; @@ -468,10 +467,10 @@ selftest() cast_setkey( &c, key, 16 ); encrypt_block( &c, buffer, plain ); if( memcmp( buffer, cipher, 8 ) ) - log_error("wrong cast5-128 encryption\n"); + return "1"; decrypt_block( &c, buffer, buffer ); if( memcmp( buffer, plain, 8 ) ) - log_bug("cast5-128 failed\n"); + return "2"; #if 0 /* full maintenance test */ { @@ -494,10 +493,11 @@ selftest() encrypt_block( &c, b0+8, b0+8 ); } if( memcmp( a0, a1, 16 ) || memcmp( b0, b1, 16 ) ) - log_bug("cast5-128 maintenance test failed\n"); + return "3"; } #endif + return NULL; } @@ -553,6 +553,7 @@ static int cast_setkey( CAST5_context *c, byte *key, unsigned keylen ) { static int initialized; + static const char* selftest_failed; int i; u32 x[4]; u32 z[4]; @@ -560,10 +561,16 @@ cast_setkey( CAST5_context *c, byte *key, unsigned keylen ) if( !initialized ) { initialized = 1; - selftest(); + selftest_failed = selftest(); + if( selftest_failed ) + fprintf(stderr,"CAST5 selftest failed (%s).\n", selftest_failed ); } + if( selftest_failed ) + return G10ERR_SELFTEST_FAILED; + + if( keylen != 16 ) + return G10ERR_WRONG_KEYLEN; - assert(keylen==16); x[0] = key[0] << 24 | key[1] << 16 | key[2] << 8 | key[3]; x[1] = key[4] << 24 | key[5] << 16 | key[6] << 8 | key[7]; x[2] = key[8] << 24 | key[9] << 16 | key[10] << 8 | key[11]; |