summaryrefslogtreecommitdiff
path: root/cipher/blowfish.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/blowfish.c
parentb725cf8008d74702b171862bea8052e7168561b6 (diff)
downloadlibgcrypt-7b66b8025a8487ab5e2c13263c2add0e237f414a.tar.gz
See ChangeLog: Sun Jan 17 11:04:33 CET 1999 Werner Koch
Diffstat (limited to 'cipher/blowfish.c')
-rw-r--r--cipher/blowfish.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/cipher/blowfish.c b/cipher/blowfish.c
index fdc4c4bf..3bbc0383 100644
--- a/cipher/blowfish.c
+++ b/cipher/blowfish.c
@@ -34,10 +34,12 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
-#include "util.h"
#include "types.h"
+#include "errors.h"
#include "blowfish.h"
+
+
#define CIPHER_ALGO_BLOWFISH 4 /* blowfish 128 bit key */
#define CIPHER_ALGO_BLOWFISH160 42 /* blowfish 160 bit key (not in OpenPGP)*/
@@ -451,7 +453,7 @@ decrypt_block( BLOWFISH_context *bc, byte *outbuf, byte *inbuf )
}
-static void
+static const char*
selftest()
{
BLOWFISH_context c;
@@ -464,18 +466,19 @@ selftest()
bf_setkey( &c, "abcdefghijklmnopqrstuvwxyz", 26 );
encrypt_block( &c, buffer, plain );
if( memcmp( buffer, "\x32\x4E\xD0\xFE\xF4\x13\xA2\x03", 8 ) )
- log_error("wrong blowfish encryption\n");
+ return "Blowfish selftest failed (1).";
decrypt_block( &c, buffer, buffer );
if( memcmp( buffer, plain, 8 ) )
- log_bug("blowfish failed\n");
+ return "Blowfish selftest failed (2).";
bf_setkey( &c, key3, 8 );
encrypt_block( &c, buffer, plain3 );
if( memcmp( buffer, cipher3, 8 ) )
- log_error("wrong blowfish encryption (3)\n");
+ return "Blowfish selftest failed (3).";
decrypt_block( &c, buffer, buffer );
if( memcmp( buffer, plain3, 8 ) )
- log_bug("blowfish failed (3)\n");
+ return "Blowfish selftest failed (4).";
+ return NULL;
}
@@ -486,11 +489,16 @@ bf_setkey( BLOWFISH_context *c, byte *key, unsigned keylen )
int i, j;
u32 data, datal, datar;
static int initialized;
+ static const char *selftest_failed;
if( !initialized ) {
initialized = 1;
- selftest();
+ selftest_failed = selftest();
+ if( selftest_failed )
+ fprintf(stderr,"%s\n", selftest_failed );
}
+ if( selftest_failed )
+ return G10ERR_SELFTEST_FAILED;
for(i=0; i < BLOWFISH_ROUNDS+2; i++ )
c->p[i] = ps[i];