]> Kevux Git Server - kevux-tools/commitdiff
Progress: Further work in TacocaT.
authorKevin Day <thekevinday@gmail.com>
Sun, 31 Dec 2023 03:40:55 +0000 (21:40 -0600)
committerKevin Day <thekevinday@gmail.com>
Sun, 31 Dec 2023 03:40:55 +0000 (21:40 -0600)
I previously just jammed on a random seed based on time as a quick short term solution.

I created an f_random FLL project to provide some basic random entropy processing code.

This change set focuses on utilizing these to get set the random entropy.

The setup of the seed is set to non-blocking with a single delayed retry if blocked.
On failure, this still falls back to the time() based setup.
The fallback also must be cast t an unsigned int rather than a long.

data/build/tacocat/dependencies
data/build/tacocat/settings
sources/c/tacocat/main/common/define.h
sources/c/tacocat/main/tacocat.c
sources/c/tacocat/main/tacocat.h

index 9b4c10e..94519c6 100644 (file)
@@ -16,6 +16,7 @@ f_network
 f_path
 f_pipe
 f_print
+f_random
 f_signal
 f_socket
 f_status_string
index 3366b94..05f59ef 100644 (file)
@@ -32,7 +32,7 @@ build_indexer_arguments rcs
 build_language c
 
 build_libraries -lc
-build_libraries-individual -lfll_error -lfll_fss -lfll_print -lfll_program -lfl_conversion -lfl_fss -lfl_print -lf_color -lf_compare -lf_console -lf_conversion -lf_file -lf_fss -lf_memory -lf_network -lf_path -lf_pipe -lf_print -lf_signal -lf_socket -lf_status_string -lf_string -lf_time -lf_type_array -lf_utf
+build_libraries-individual -lfll_error -lfll_fss -lfll_print -lfll_program -lfl_conversion -lfl_fss -lfl_print -lf_color -lf_compare -lf_console -lf_conversion -lf_file -lf_fss -lf_memory -lf_network -lf_path -lf_pipe -lf_print -lf_random -lf_signal -lf_socket -lf_status_string -lf_string -lf_time -lf_type_array -lf_utf
 build_libraries-individual_thread -lf_thread
 build_libraries-level -lfll_2 -lfll_1 -lfll_0
 build_libraries-monolithic -lfll
index f8ca80e..1e59c7f 100644 (file)
@@ -56,6 +56,10 @@ extern "C" {
  *   - retry_delay_second:      The delay in seconds to wait between each retry.
  *   - retry_delay_millisecond: The delay in milliseconds to wait between each retry.
  *   - retry_max:               During start up, the maximum number of retries to perform when trying to establish the initial connection before giving up.
+ *
+ * kt_tacocat_startup_seed_*_d:
+ *   - delay_second:     The delay in seconds to wait if the first non-blocking random seed setup fails.
+ *   - delay_nanosecond: The delay in nanoseconds to wait if the first non-blocking random seed setup fails.
  */
 #ifndef _di_kt_tacocat_d_
   #define kt_tacocat_allocation_console_d 0x4
@@ -87,6 +91,9 @@ extern "C" {
   #define kt_tacocat_startup_retry_delay_second_d      3
   #define kt_tacocat_startup_retry_delay_millisecond_d 0
   #define kt_tacocat_startup_retry_max_d               24
+
+  #define kt_tacocat_startup_seed_delay_second_d      0
+  #define kt_tacocat_startup_seed_delay_nanosecond_d  100
 #endif // _di_kt_tacocat_d_
 
 /**
index a0e259a..4ff0112 100644 (file)
@@ -39,8 +39,26 @@ extern "C" {
       return;
     }
 
-    // Establish random seed.
-    srandom((long) time(0));
+    main->setting.state.status = f_random_seed(GRND_NONBLOCK);
+
+    // Try again, but only once if blocked.
+    if (main->setting.state.status == F_status_set_error(F_again)) {
+      {
+        const struct timespec time = { .tv_sec = kt_tacocat_startup_seed_delay_second_d, .tv_nsec = kt_tacocat_startup_seed_delay_nanosecond_d };
+
+        nanosleep(&time, 0);
+      }
+
+      main->setting.state.status = f_random_seed(GRND_NONBLOCK);
+    }
+
+    if (F_status_is_error(main->setting.state.status)) {
+
+      // Fall back to the far less secure but better than nothing method of using time as the seed.
+      f_random_seed_set((unsigned int) time(0));
+
+      main->setting.state.status = F_okay;
+    }
 
     kt_tacocat_process_main(main);
 
index 7cf37c4..b15ea95 100644 (file)
@@ -33,6 +33,7 @@
 #include <fll/level_0/path.h>
 #include <fll/level_0/pipe.h>
 #include <fll/level_0/print.h>
+#include <fll/level_0/random.h>
 #include <fll/level_0/signal.h>
 #include <fll/level_0/socket.h>
 #include <fll/level_0/status_string.h>