]> feistymeow.org Git - feisty_meow.git/commitdiff
still borked, but moving dev
authorFred T. Hamster <fred@feistymeow.org>
Sun, 22 Mar 2026 00:40:36 +0000 (20:40 -0400)
committerFred T. Hamster <fred@feistymeow.org>
Sun, 22 Mar 2026 00:40:36 +0000 (20:40 -0400)
nucleus/library/crypto/borked_blowfish_crypto.h
nucleus/library/crypto/cryptical_envelopment.cpp
nucleus/library/crypto/cryptical_envelopment.h
nucleus/library/crypto/twofish_crypto.h
nucleus/library/tests_crypto/test_blowfish_crypto.cpp
nucleus/library/tests_crypto/test_twofish_crypto.cpp

index dfe0709da0d65610d30b866b8ebe129c6832a4a0..972e1742873c2c3199ee4a52f47775fb6d7ed4c2 100644 (file)
@@ -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.
index 838c37dd8ec93658c6280798d9cb01b0324249bf..906b3808bd0add1e9ba7440c93027984a5e2ac91 100644 (file)
@@ -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);
index 899c6ab3c560261dc38686f5a3645548d45e7779..aa2e79220678b5d498db85abba5fb3b574a4daa7 100644 (file)
@@ -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.
 
index 95e74297cfe23651f478b3eb9316171a8ef48a7d..f2a756a487e817710411df142004399702f32e8d 100644 (file)
@@ -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.
index 4fa124ee0f7cf8ef81e34dc40bbcf34ae4b7117d..649eb37d83cb93472bf6e54e7953821bc7544e34 100644 (file)
@@ -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 <application/hoople_main.h>
@@ -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());
index 565b7cc73f2bbffc02f574f34cc36aaf3b2f9b5e..04e7eeca3cb9935288f596834bac6835e867fc50 100644 (file)
@@ -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