summaryrefslogtreecommitdiff
path: root/cipher/twofish.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/twofish.c
parentb725cf8008d74702b171862bea8052e7168561b6 (diff)
downloadlibgcrypt-7b66b8025a8487ab5e2c13263c2add0e237f414a.tar.gz
See ChangeLog: Sun Jan 17 11:04:33 CET 1999 Werner Koch
Diffstat (limited to 'cipher/twofish.c')
-rw-r--r--cipher/twofish.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/cipher/twofish.c b/cipher/twofish.c
index d93c145e..d52377f7 100644
--- a/cipher/twofish.c
+++ b/cipher/twofish.c
@@ -19,14 +19,14 @@
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
-#include <assert.h> /* for assert() */
#include <string.h> /* for memcmp() */
#include "types.h" /* for byte and u32 typedefs */
-#include "util.h" /* for log_fatal() */
+#include "errors.h"
+
/* Prototype for the self-test function. */
-static void selftest(void);
+static const char *selftest(void);
/* Macros used by the info function. */
#define FNCCAST_SETKEY(f) ((int(*)(void*, byte*, unsigned))(f))
@@ -456,17 +456,23 @@ twofish_setkey (TWOFISH_context *ctx, const byte *key, const unsigned keylen)
/* Temporary for CALC_S. */
byte tmp;
- /* Flag for self-test. */
+ /* Flags for self-test. */
static int initialized = 0;
+ static const char *selftest_failed=0;
/* Check key length. */
- assert (keylen == 16);
+ if( keylen != 16 )
+ return G10ERR_WRONG_KEYLEN;
/* Do self-test if necessary. */
if (!initialized) {
initialized = 1;
- selftest ();
+ selftest_failed = selftest ();
+ if( selftest_failed )
+ fprintf(stderr, "%s\n", selftest_failed );
}
+ if( selftest_failed )
+ return G10ERR_SELFTEST_FAILED;
/* Compute the S vector. The magic numbers are the entries of the RS
* matrix, preprocessed through poly_to_exp. The numbers in the comments
@@ -709,7 +715,7 @@ twofish_decrypt (const TWOFISH_context *ctx, byte *out, const byte *in)
/* Test a single encryption and decryption, as a sanity check. */
-static void
+static const char*
selftest (void)
{
TWOFISH_context ctx; /* Expanded key. */
@@ -736,10 +742,11 @@ selftest (void)
twofish_setkey (&ctx, key, sizeof(key));
twofish_encrypt (&ctx, scratch, plaintext);
if (memcmp (scratch, ciphertext, sizeof (ciphertext)))
- log_fatal ("Twofish test encryption failed\n");
+ return "Twofish test encryption failed.";
twofish_decrypt (&ctx, scratch, scratch);
if (memcmp (scratch, plaintext, sizeof (plaintext)))
- log_fatal ("Twofish test decryption failed\n");
+ return "Twofish test decryption failed.";
+ return NULL;
}
/* More complete test program. This does a thousand encryptions and