From e106c71c0432df7cf2df48fb443459b7057ebfbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se> Date: Thu, 10 Apr 1997 04:33:27 +0200 Subject: [PATCH] Fixed a few bugs Rev: lib/modules/Crypto/randomness.pmod.pike:1.2 Rev: lib/modules/Crypto/rsa.pike:1.5 Rev: src/modules/_Crypto/cbc.c:1.8 Rev: src/modules/_Crypto/crypto.c:1.20 Rev: src/modules/_Crypto/test_crypto.pike:1.4 --- lib/modules/Crypto/randomness.pmod.pike | 2 +- lib/modules/Crypto/rsa.pike | 2 +- src/modules/_Crypto/cbc.c | 4 ++-- src/modules/_Crypto/crypto.c | 9 ++++----- src/modules/_Crypto/test_crypto.pike | 4 +--- 5 files changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/modules/Crypto/randomness.pmod.pike b/lib/modules/Crypto/randomness.pmod.pike index 7a9d4d8d10..dc77256a20 100644 --- a/lib/modules/Crypto/randomness.pmod.pike +++ b/lib/modules/Crypto/randomness.pmod.pike @@ -105,7 +105,7 @@ object reasonably_random() object really_random(int|void may_block) { - object res; + object res = Stdio.File(); if (may_block && file_stat(RANDOM_DEVICE)) { if (res->open(RANDOM_DEVICE, "r")) diff --git a/lib/modules/Crypto/rsa.pike b/lib/modules/Crypto/rsa.pike index a6d694192e..92b6de1bc3 100644 --- a/lib/modules/Crypto/rsa.pike +++ b/lib/modules/Crypto/rsa.pike @@ -81,7 +81,7 @@ int sha_verify(string message, string signature) string s; hash->update(message); - s = hash->digest; + s = hash->digest(); s = sprintf("%c%s%c%s", 4, "sha1", strlen(s), s); return s == rsa_unpad(BIGNUM(signature, 256)->powm(e, n), 1); diff --git a/src/modules/_Crypto/cbc.c b/src/modules/_Crypto/cbc.c index 3147bb1144..4a9dd85440 100644 --- a/src/modules/_Crypto/cbc.c +++ b/src/modules/_Crypto/cbc.c @@ -1,5 +1,5 @@ /* - * $Id: cbc.c,v 1.7 1997/03/17 03:11:14 hubbe Exp $ + * $Id: cbc.c,v 1.8 1997/04/10 02:33:26 nisse Exp $ * * CBC (Cipher Block Chaining Mode) crypto module for Pike. * @@ -260,7 +260,7 @@ static void f_decrypt_block(INT32 args) if (sp[-1].type != T_STRING) { error("Bad argument 1 to cbc->decrypt_block()\n"); } - if (sp[-1].u.string->len & THIS->block_size) { + if (sp[-1].u.string->len % THIS->block_size) { error("Bad length of argument 1 to cbc->decrypt_block()\n"); } if (!(result = alloca(sp[-1].u.string->len))) { diff --git a/src/modules/_Crypto/crypto.c b/src/modules/_Crypto/crypto.c index 03858cb3b4..7960d73b3d 100644 --- a/src/modules/_Crypto/crypto.c +++ b/src/modules/_Crypto/crypto.c @@ -1,5 +1,5 @@ /* - * $Id: crypto.c,v 1.19 1997/03/23 18:18:55 nisse Exp $ + * $Id: crypto.c,v 1.20 1997/04/10 02:33:27 nisse Exp $ * * A pike module for getting access to some common cryptos. * @@ -397,11 +397,10 @@ static void f_pad(INT32 args) error("Too many arguments to crypto->pad()\n"); } - len = THIS->block_size - 1 - THIS->backlog_len; - for (i=0; i < len; i++) - THIS->backlog[THIS->backlog_len + i] = my_rand() & 0xff; + for (i = THIS->backlog_len; i < THIS->block_size - 1; i++) + THIS->backlog[i] = my_rand() & 0xff; - THIS->backlog[i] = len; + THIS->backlog[THIS->block_size - 1] = 7 - THIS->backlog_len; push_string(make_shared_binary_string((const char *)THIS->backlog, THIS->block_size)); diff --git a/src/modules/_Crypto/test_crypto.pike b/src/modules/_Crypto/test_crypto.pike index b31efb54cf..0088a61261 100755 --- a/src/modules/_Crypto/test_crypto.pike +++ b/src/modules/_Crypto/test_crypto.pike @@ -7,7 +7,6 @@ import Crypto; #define K(a) hex_to_string(a) #define H(a) string_to_hex(a) - int test_des() { string *keys = ({ K("0101010101010180"), @@ -60,7 +59,6 @@ int test_des() return err; } - int test_idea() { string key = K("0123456789abcdef0123456789abcdef"); @@ -220,5 +218,5 @@ int test_cbc() int main() { - return test_des() | test_idea() | test_cbc(); + return test_des() | test_idea() | test_cbc(); } -- GitLab