]> feistymeow.org Git - feisty_meow.git/commitdiff
debugging into the crash
authorFred T. Hamster <fred@feistymeow.org>
Wed, 25 Feb 2026 02:34:34 +0000 (21:34 -0500)
committerFred T. Hamster <fred@feistymeow.org>
Wed, 25 Feb 2026 02:34:34 +0000 (21:34 -0500)
getting a segment violation when calling into EVP_CIPHER_CTX_set_key_length.
not helpful, and no obvious reason why yet.

nucleus/library/crypto/blowfish_crypto.cpp
nucleus/library/tests_crypto/test_blowfish_crypto.cpp

index 77b70f285d445a0b6fe90c703b23b70a52144c7f..d1a3fec317d16d16df8c5a541193177283be0a7b 100644 (file)
@@ -41,7 +41,7 @@ const int FUDGE = 128;
 //#undef set_key
   // get rid of a macro we don't want.
 
-//#define DEBUG_BLOWFISH
+#define DEBUG_BLOWFISH
   // uncomment for noisier version.
 
 #ifdef DEBUG_BLOWFISH
@@ -187,8 +187,9 @@ const byte_array &blowfish_crypto::init_vector()
   if (!initted) {
     LOG("actually doing init");
     for (int i = 0; i < EVP_MAX_IV_LENGTH; i++)
-      to_return[i] = 214 - i;
+      to_return[i] = abyte(214 - i);
     initted = true;
+    LOG("finished init process");
   }
   LOG("leaving init check");
   return to_return;
@@ -205,13 +206,18 @@ bool blowfish_crypto::encrypt(const byte_array &source,
   // initialize an encoding session.
   EVP_CIPHER_CTX *session = EVP_CIPHER_CTX_new();
 
+LOG("enc 001");
   EVP_CIPHER_CTX_init(session);
-  EVP_EncryptInit_ex(session, EVP_bf_cbc(), NULL_POINTER, _key->observe(),
-      init_vector().observe());
+LOG("enc 002");
+  EVP_EncryptInit_ex(session, EVP_bf_cbc(), NULL_POINTER, _key->observe(), init_vector().observe());
+LOG("enc 003");
+LOG(a_sprintf("going to do set key len with key size of %d", _key_size));
   EVP_CIPHER_CTX_set_key_length(session, _key_size);
+LOG("enc 004");
 
   // allocate temporary space for encrypted data.
   byte_array encoded(source.length() + FUDGE);
+LOG("enc 005");
 
   // encrypt the entire source buffer.
   int encoded_len = 0;
index 4ae10ecd62fa3ef1946ed39e8362cf2950726910..04e449da31e00907f677c3b3dc4760d775d87c71 100644 (file)
@@ -41,14 +41,15 @@ using namespace textual;
 using namespace timely;
 using namespace unit_test;
 
-#define LOG(to_print) EMERGENCY_LOG(program_wide_logger::get(), to_print)
+#define LOG(to_print) EMERGENCY_LOG(program_wide_logger::get(), astring(to_print))
 
 #define DEBUG_BLOWFISH
   // uncomment for noisier run.
 
 const int TEST_RUNS_PER_KEY = 5;  // encryption test cycles done on each key.
 
-const int THREAD_COUNT = 10;  // number of threads testing blowfish at once.
+//const int THREAD_COUNT = 10;  // number of threads testing blowfish at once.
+const int THREAD_COUNT = 1;  // number of threads testing blowfish at once.
 
 const int ITERATIONS = 4;  // number of test runs in our testing threads.
 
@@ -92,7 +93,7 @@ int test_blowfish::execute()
 {
   FUNCDEF("execute");
 #ifdef DEBUG_BLOWFISH
-  LOG(astring("starting blowfish test..."));
+  LOG("starting blowfish test...");
 #endif
   int left = THREAD_COUNT;
   while (left--) {
@@ -103,12 +104,12 @@ int test_blowfish::execute()
   }
 
 #ifdef DEBUG_BLOWFISH
-  LOG(astring("started all threads..."));
+  LOG("started all threads...");
 #endif
 
   while (_threads.threads()) {
 #ifdef DEBUG_BLOWFISH
-    LOG(astring("cleaning debris."));
+    LOG("cleaning debris.");
 #endif
     _threads.clean_debris();
     time_control::sleep_ms(1000);
@@ -145,7 +146,6 @@ void blowfish_thread::perform_activity(void *)
     LOG(a_sprintf("%s", dumped_key.s()));
 #endif
     int key_dur = int(time_stamp().value() - key_start.value());
-
 #ifdef DEBUG_BLOWFISH
     LOG(a_sprintf("  key generation took %d ms", key_dur));
 #endif
@@ -154,31 +154,43 @@ void blowfish_thread::perform_activity(void *)
       byte_array key;
       byte_array iv;
 
+LOG(a_sprintf("loop iter %d", i));
+
       int string_start = _parent.randomizer().inclusive(0, MAX_STRING - 1);
       int string_end = _parent.randomizer().inclusive(0, MAX_STRING - 1);
       flip_increasing(string_start, string_end);
       astring ranstring = _parent._fodder.substring(string_start, string_end);
-//LOG(a_sprintf("encoding %s\n", ranstring.s());
-//LOG(a_sprintf("string length encoded: %d\n", ranstring.length());
+#ifdef DEBUG_BLOWFISH
+      LOG(a_sprintf("encoding %s\n", ranstring.s()));
+      LOG(a_sprintf("string length encoded: %d\n", ranstring.length()));
+#endif
 
+LOG("point A");
       byte_array target;
-
       time_stamp test_start;
-      bool worked = bc.encrypt(byte_array(ranstring.length() + 1,
-          (abyte*)ranstring.s()), target);
+LOG("point A.2");
+      bool worked = bc.encrypt(byte_array(ranstring.length() + 1, (abyte*)ranstring.s()), target);
+LOG("point B");
       int enc_durat = int(time_stamp().value() - test_start.value());
       ASSERT_TRUE(worked, "phase 1 should not fail to encrypt the string");
+LOG("point C");
 
       byte_array recovered;
+LOG("point D");
       test_start.reset();
       worked = bc.decrypt(target, recovered);
+LOG("point E");
       int dec_durat = int(time_stamp().value() - test_start.value());
       ASSERT_TRUE(worked, "phase 1 should not fail to decrypt the string");
-//    LOG(a_sprintf("original has %d chars, recovered has %d chars\n",
-//        ranstring.length(), recovered.length() - 1));
+#ifdef DEBUG_BLOWFISH
+      LOG(a_sprintf("original has %d chars, recovered has %d chars\n",
+          ranstring.length(), recovered.length() - 1));
+#endif
 
       astring teddro = (char *)recovered.observe();
-//LOG(a_sprintf("decoded %s\n", teddro.s()));
+#ifdef DEBUG_BLOWFISH
+      LOG(a_sprintf("decoded %s\n", teddro.s()));
+#endif
 
 #ifdef DEBUG_BLOWFISH
       if (teddro != ranstring) {