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.
f_path
f_pipe
f_print
+f_random
f_signal
f_socket
f_status_string
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
* - 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
#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_
/**
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);
#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>