From cb99f58c58b19bc64c98b5b30b225349cead90d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?= <grubba@grubba.org> Date: Mon, 2 Oct 2000 22:06:46 +0200 Subject: [PATCH] Oops, missed a few details... Rev: src/modules/_Crypto/include/rijndael.h:1.2 Rev: src/modules/_Crypto/rijndael.c:1.2 Rev: src/modules/_Crypto/testsuite.in:1.15 --- src/modules/_Crypto/include/rijndael.h | 4 +++- src/modules/_Crypto/rijndael.c | 19 +++++++++++-------- src/modules/_Crypto/testsuite.in | 1 + 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/modules/_Crypto/include/rijndael.h b/src/modules/_Crypto/include/rijndael.h index a10210ffa4..e0500579de 100644 --- a/src/modules/_Crypto/include/rijndael.h +++ b/src/modules/_Crypto/include/rijndael.h @@ -1,5 +1,5 @@ /* - * $Id: rijndael.h,v 1.1 2000/10/02 19:35:03 grubba Exp $ + * $Id: rijndael.h,v 1.2 2000/10/02 20:06:46 grubba Exp $ */ /* @@ -16,6 +16,8 @@ #define MAXKC (256/32) #define MAXROUNDS 14 +#define RIJNDAEL_BLOCK_SIZE 16 + #ifndef USUAL_TYPES #define USUAL_TYPES typedef unsigned char byte; diff --git a/src/modules/_Crypto/rijndael.c b/src/modules/_Crypto/rijndael.c index a0a647c98e..4064b475ca 100644 --- a/src/modules/_Crypto/rijndael.c +++ b/src/modules/_Crypto/rijndael.c @@ -1,5 +1,5 @@ /* - * $Id: rijndael.c,v 1.1 2000/10/02 19:35:02 grubba Exp $ + * $Id: rijndael.c,v 1.2 2000/10/02 20:06:45 grubba Exp $ * * A pike module for getting access to some common cryptos. * @@ -20,8 +20,7 @@ #include "threads.h" #include "object.h" #include "stralloc.h" -/* #include "builtin_functions.h" - */ +#include "module_support.h" /* System includes */ #include <sys/types.h> #include <sys/stat.h> @@ -80,7 +79,7 @@ static void exit_pike_crypto_rijndael(struct object *o) static void f_query_block_size(INT32 args) { pop_n_elems(args); - push_int(MAX_IV_SIZE); + push_int(RIJNDAEL_BLOCK_SIZE); } /* int query_key_length(void) */ @@ -94,14 +93,16 @@ static void f_query_key_length(INT32 args) static void f_set_encrypt_key(INT32 args) { struct pike_string *key = NULL; + word8 k[MAXKC][4]; get_all_args("rijndael->set_encrypt_key()", args, "%S", &key); if (((key->len - 8) & ~0x18) || (!key->len)) { error("rijndael->set_encrypt_key(): Bad key length " "(must be 16, 24 or 32).\n"); } + MEMCPY(k, key->str, key->len); THIS->rounds = 6 + key->len/32; - rijndaelKeySched(key, &(THIS->keySchedule), THIS->rounds); + rijndaelKeySched(k, THIS->keySchedule, THIS->rounds); THIS->crypt_fun = rijndaelEncrypt; } @@ -109,14 +110,16 @@ static void f_set_encrypt_key(INT32 args) static void f_set_decrypt_key(INT32 args) { struct pike_string *key = NULL; + word8 k[MAXKC][4]; get_all_args("rijndael->set_encrypt_key()", args, "%S", &key); if (((key->len - 8) & ~0x18) || (key->len != 8)) { error("rijndael->set_encrypt_key(): Bad key length " "(must be 16, 24 or 32).\n"); } + MEMCPY(k, key->str, key->len); THIS->rounds = 6 + key->len/32; - rijndaelKeySched(key, &(THIS->keySchedule), THIS->rounds); + rijndaelKeySched(k, THIS->keySchedule, THIS->rounds); rijndaelKeyEncToDec(THIS->keySchedule, THIS->rounds); THIS->crypt_fun = rijndaelDecrypt; } @@ -136,11 +139,11 @@ static void f_crypt_block(INT32 args) if (sp[-1].type != T_STRING) { error("Bad argument 1 to rijndael->crypt_block()\n"); } - if ((len = sp[-1].u.string->len) % MAX_IV_SIZE) { + if ((len = sp[-1].u.string->len) % RIJNDAEL_BLOCK_SIZE) { error("Bad string length in rijndael->crypt_block()\n"); } s = begin_shared_string(len); - for(i = 0; i < len; i += MAX_IV_SIZE) + for(i = 0; i < len; i += RIJNDAEL_BLOCK_SIZE) THIS->crypt_fun((unsigned INT8 *) sp[-1].u.string->str + i, (unsigned INT8 *) s->str + i, THIS->keySchedule, THIS->rounds); diff --git a/src/modules/_Crypto/testsuite.in b/src/modules/_Crypto/testsuite.in index c384cda08b..72f1aedc9b 100644 --- a/src/modules/_Crypto/testsuite.in +++ b/src/modules/_Crypto/testsuite.in @@ -21,6 +21,7 @@ test_true([[programp(xCrypto.pipe)]]) test_true([[programp(xCrypto.sha)]]) // BEGIN NATIONAL SECURITY +test_true([[programp(Crypto.rijndael)]]) test_true([[programp(Crypto.des)]]) test_true([[programp(Crypto.idea)]]) test_true([[programp(Crypto.cast)]]) -- GitLab