summaryrefslogtreecommitdiff
path: root/cipher/cast5.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>1999-01-17 10:06:02 +0000
committerWerner Koch <wk@gnupg.org>1999-01-17 10:06:02 +0000
commit7b66b8025a8487ab5e2c13263c2add0e237f414a (patch)
tree75ce898bf4235b38c01f1fcb06969f80db7fa5e4 /cipher/cast5.c
parentb725cf8008d74702b171862bea8052e7168561b6 (diff)
downloadlibgcrypt-7b66b8025a8487ab5e2c13263c2add0e237f414a.tar.gz
See ChangeLog: Sun Jan 17 11:04:33 CET 1999 Werner Koch
Diffstat (limited to 'cipher/cast5.c')
-rw-r--r--cipher/cast5.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/cipher/cast5.c b/cipher/cast5.c
index 279838fa..6f131ca2 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];