From: Fred T. Hamster Date: Sun, 22 Mar 2026 00:40:36 +0000 (-0400) Subject: still borked, but moving X-Git-Url: https://feistymeow.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fdev;p=feisty_meow.git still borked, but moving --- diff --git a/nucleus/library/crypto/borked_blowfish_crypto.h b/nucleus/library/crypto/borked_blowfish_crypto.h index dfe0709d..972e1742 100644 --- a/nucleus/library/crypto/borked_blowfish_crypto.h +++ b/nucleus/library/crypto/borked_blowfish_crypto.h @@ -54,8 +54,8 @@ public: DEFINE_CLASS_NAME("borked_blowfish_crypto"); // blowfish relevant values for appropriate key sizes. - virtual int minimum_key_size() const { return 64; } // officially, this is 32. - virtual int maximum_key_size() const { return 448; } + virtual int minimum_key_size_in_bits() const { return 64; } // officially, this is 32. + virtual int maximum_key_size_in_bits() const { return 448; } }; } //namespace. diff --git a/nucleus/library/crypto/cryptical_envelopment.cpp b/nucleus/library/crypto/cryptical_envelopment.cpp index 838c37dd..906b3808 100644 --- a/nucleus/library/crypto/cryptical_envelopment.cpp +++ b/nucleus/library/crypto/cryptical_envelopment.cpp @@ -72,16 +72,16 @@ const int FUDGE = 1024; // this macro checks on the validity of the key sizes (in bits). #define DISCUSS_KEY_SIZE(key_size) \ - if (key_size < minimum_key_size()) { \ + if (key_size < minimum_key_size_in_bits()) { \ ERROR_BAILOUT(static_class_name(), func, \ a_sprintf("key size (%d bits) is less than minimum key size %d.", \ - key_size, minimum_key_size())); \ + key_size, minimum_key_size_in_bits())); \ return false; \ } \ - if (key_size > maximum_key_size()) { \ + if (key_size > maximum_key_size_in_bits()) { \ ERROR_BAILOUT(static_class_name(), func, \ a_sprintf("key size (%d bits) is greater than maximum key size %d.", \ - key_size, maximum_key_size())); \ + key_size, maximum_key_size_in_bits())); \ return false; \ } @@ -126,32 +126,13 @@ bool cryptical_envelopment::set_key(int key_size) { FUNCDEF("set_key(int)"); DISCUSS_KEY_SIZE(key_size); -/// if (key_size < minimum_key_size()) -/// _key_size = minimum_key_size(); -/// if (key_size > maximum_key_size()) -/// _key_size = maximum_key_size(); LOG("prior to generate key"); _key_size = key_size; -/// WHACK(_key); // clear any existing key. -/// _key = new byte_array(); bool to_return = generate_key(_key_size, *_key); LOG("after generate key"); return to_return; } -/* -bool cryptical_envelopment::set_key(const byte_array &key, int key_size) -{ - FUNCDEF("set_key(byte_array,int)"); -//// static_ssl_initializer(); - DISCUSS_KEY_SIZE(key_size); - DISCUSS_PROVIDED_KEY(key_size, key); - _key_size = key_size; - _key = new byte_array(key); - return true; -} -*/ - int cryptical_envelopment::key_size() const { return _key_size; } const byte_array &cryptical_envelopment::get_key() const { return *_key; } @@ -168,14 +149,8 @@ cryptical_envelopment &cryptical_envelopment::operator = (const cryptical_envelo bool cryptical_envelopment::set_key(const byte_array &new_key, int key_size) { FUNCDEF("set_key(byte_array,int)"); -// if (!new_key.length()) return false; DISCUSS_KEY_SIZE(key_size); DISCUSS_PROVIDED_KEY(key_size, new_key); -// if ( (key_size < minimum_key_size()) || (key_size > maximum_key_size()) ) -// return false; -// if (new_key.length() * BITS_PER_BYTE < key_size) return false; -//// if (!_key) -//// _key = new byte_array(); _key_size = key_size; *_key = new_key; return true; @@ -197,13 +172,7 @@ bool cryptical_envelopment::generate_key(int size, byte_array &new_key) { FUNCDEF("generate_key"); static_ssl_initializer(); -//// if (!_key) -//// _key = new byte_array(); DISCUSS_KEY_SIZE(size); -// if (size < minimum_key_size()) -// size = minimum_key_size(); -// else if (size > maximum_key_size()) -// size = maximum_key_size(); int bytes = size / BITS_PER_BYTE; // calculate the number of bytes needed. if (size % BITS_PER_BYTE) bytes++; // add one for non-integral portion. new_key.reset(bytes); diff --git a/nucleus/library/crypto/cryptical_envelopment.h b/nucleus/library/crypto/cryptical_envelopment.h index 899c6ab3..aa2e7922 100644 --- a/nucleus/library/crypto/cryptical_envelopment.h +++ b/nucleus/library/crypto/cryptical_envelopment.h @@ -48,10 +48,10 @@ public: int key_size() const; // returns the size of our key, in bits. // derived classes must provide the min and max for key sizes. - virtual int minimum_key_size() const = 0; - //!< returns the minimum key size (in bits) supported here. - virtual int maximum_key_size() const = 0; - //!< returns the maximum key size (in bits) supported here. + virtual int minimum_key_size_in_bits() const = 0; + //!< returns the minimum key size in bits supported here. + virtual int maximum_key_size_in_bits() const = 0; + //!< returns the maximum key size in bits supported here. const basis::byte_array &get_key() const; //!< returns our current key. diff --git a/nucleus/library/crypto/twofish_crypto.h b/nucleus/library/crypto/twofish_crypto.h index 95e74297..f2a756a4 100644 --- a/nucleus/library/crypto/twofish_crypto.h +++ b/nucleus/library/crypto/twofish_crypto.h @@ -42,7 +42,7 @@ public: DEFINE_CLASS_NAME("twofish_crypto"); // twofish relevant values for appropriate key sizes. - virtual int minimum_key_size() const { return 92; } + virtual int minimum_key_size_in_bits() const { return 92; } /* note that the lower bound above was discovered for openssl library through experimentation, and is not officially documented for the twofish algorithm anywhere we can find (yet). @@ -50,7 +50,7 @@ public: would succeed on the same key length but then would trigger an 'invalid key length' error. not the kind of deterministic behavior we might expect. */ - virtual int maximum_key_size() const { return 256; } + virtual int maximum_key_size_in_bits() const { return 256; } }; } //namespace. diff --git a/nucleus/library/tests_crypto/test_blowfish_crypto.cpp b/nucleus/library/tests_crypto/test_blowfish_crypto.cpp index 4fa124ee..649eb37d 100644 --- a/nucleus/library/tests_crypto/test_blowfish_crypto.cpp +++ b/nucleus/library/tests_crypto/test_blowfish_crypto.cpp @@ -3,12 +3,12 @@ * Author : Chris Koeritz * Purpose: Exercises the BlowFish encryption methods in the crypto library. ** -* Copyright (c) 2005-$now By Author. This program is free software; you can * -* redistribute it and/or modify it under the terms of the GNU General Public * -* License as published by the Free Software Foundation; either version 2 of * -* the License or (at your option) any later version. This is online at: * -* http://www.fsf.org/copyleft/gpl.html * -* Please send any updates to: fred@gruntose.com * +* Copyright (c) 2005-$now By Author. This program is free software; you can +* redistribute it and/or modify it under the terms of the GNU General Public +* License as published by the Free Software Foundation; either version 2 of +* the License or (at your option) any later version. This is online at: +* http://www.fsf.org/copyleft/gpl.html +* Please send any updates to: fred@gruntose.com */ #include @@ -58,8 +58,8 @@ const int ITERATIONS = 80; // number of test runs in our testing threads. const int MAX_STRING = 20000; // largest chunk that we'll try to encrypt. // some constants snagged from older version of borked_blowfish_crypto class... -const int borked_blowfish_crypto_minimum_key_size_in_bits = 32; -const int borked_blowfish_crypto_maximum_key_size_in_bits = 448; +///const int borked_blowfish_crypto_minimum_key_size_in_bits = 32; +///const int borked_blowfish_crypto_maximum_key_size_in_bits = 448; ////////////// @@ -141,8 +141,8 @@ void blowfish_thread::perform_activity(void *) int left = ITERATIONS; while (left--) { time_stamp key_start; - borked_blowfish_crypto bc(_parent.randomizer().inclusive(borked_blowfish_crypto_minimum_key_size_in_bits, - borked_blowfish_crypto_maximum_key_size_in_bits)); + borked_blowfish_crypto bc(256); + bc = borked_blowfish_crypto(_parent.randomizer().inclusive(bc.minimum_key_size_in_bits(), bc.maximum_key_size_in_bits())); #ifdef DEBUG_BLOWFISH LOG(a_sprintf("%d bit key has:", bc.key_size())); astring dumped_key = byte_formatter::text_dump(bc.get_key()); diff --git a/nucleus/library/tests_crypto/test_twofish_crypto.cpp b/nucleus/library/tests_crypto/test_twofish_crypto.cpp index 565b7cc7..04e7eeca 100644 --- a/nucleus/library/tests_crypto/test_twofish_crypto.cpp +++ b/nucleus/library/tests_crypto/test_twofish_crypto.cpp @@ -57,14 +57,6 @@ const int MAX_STRING = 64 * KILOBYTE; // largest chunk that we'll try to encryp // some constants snagged from older version of twofish_crypto class... //const int twofish_crypto_minimum_key_size_in_bits = 92; //const int twofish_crypto_maximum_key_size_in_bits = 256; -/* - Q: is twofish truly requiring 128/192/256 key sizes only? - A: no, schneier says any key size up to 256 bits. - Q: can twofish really support *any* key length up to 256? - A: well, not in openssl. we are getting invalid key length complaints - with keys below 92 bits. this was calculated by testing for quite - a while with only those size keys, and 92 seems reliable as a minimum. -*/ ////////////// @@ -146,11 +138,11 @@ void twofish_thread::perform_activity(void *) int left = ITERATIONS; while (left--) { time_stamp key_start; - twofish_crypto bc(_parent.randomizer().inclusive(twofish_crypto_minimum_key_size_in_bits, - twofish_crypto_maximum_key_size_in_bits)); + twofish_crypto tc(256); + tc = twofish_crypto(_parent.randomizer().inclusive(tc.minimum_key_size_in_bits(), tc.maximum_key_size_in_bits())); #ifdef DEBUG_TWOFISH - LOG(a_sprintf("%d bit key has:", bc.key_size())); - astring dumped_key = byte_formatter::text_dump(bc.get_key()); + LOG(a_sprintf("%d bit key has:", tc.key_size())); + astring dumped_key = byte_formatter::text_dump(tc.get_key()); LOG(a_sprintf("%s", dumped_key.s())); #endif int key_dur = int(time_stamp().value() - key_start.value()); @@ -173,13 +165,13 @@ LOG(a_sprintf("test run %d on this key.", i+1)); byte_array target; time_stamp test_start; - bool worked = bc.encrypt(byte_array(ranstring.length() + 1, (abyte*)ranstring.s()), target); + bool worked = tc.encrypt(byte_array(ranstring.length() + 1, (abyte*)ranstring.s()), target); int enc_durat = int(time_stamp().value() - test_start.value()); ASSERT_TRUE(worked, "phase 1 should not fail to encrypt the string"); byte_array recovered; test_start.reset(); - worked = bc.decrypt(target, recovered); + worked = tc.decrypt(target, recovered); int dec_durat = int(time_stamp().value() - test_start.value()); ASSERT_TRUE(worked, "phase 1 should not fail to decrypt the string"); #ifdef DEBUG_TWOFISH