From 6a6be39e3b7f530b1bd0246bf407ae2b96b97ae5 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Mon, 1 Jan 2024 18:25:12 -0600 Subject: [PATCH] Update: Add custom defines for the random seed macros via random/common.h. I try to avoid the direct use of core/standard macros like GRND_NONBLOCK. Add f_random specific macros for these GRND_* macros. --- build/level_0/settings | 2 +- build/monolithic/settings | 2 +- level_0/f_random/c/random.h | 11 +++++--- level_0/f_random/c/random/common.h | 42 ++++++++++++++++++++++++++++++ level_0/f_random/data/build/settings | 2 +- level_0/f_random/data/build/settings-mocks | 2 +- 6 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 level_0/f_random/c/random/common.h diff --git a/build/level_0/settings b/build/level_0/settings index 140879c..c870f37 100644 --- a/build/level_0/settings +++ b/build/level_0/settings @@ -105,7 +105,7 @@ build_sources_headers parse.h parse/utf.h build_sources_headers path.h path/common.h build_sources_headers pipe.h build_sources_headers print.h print/to.h print/common.h -build_sources_headers random.h +build_sources_headers random.h random/common.h build_sources_headers rip.h rip/utf.h build_sources_headers serialize.h serialize/common.h build_sources_headers signal.h signal/common.h diff --git a/build/monolithic/settings b/build/monolithic/settings index ded3fc9..fb943cf 100644 --- a/build/monolithic/settings +++ b/build/monolithic/settings @@ -126,7 +126,7 @@ build_sources_headers level_0/parse.h level_0/parse/utf.h build_sources_headers level_0/path.h level_0/path/common.h build_sources_headers level_0/pipe.h build_sources_headers level_0/print.h level_0/print/to.h level_0/print/common.h -build_sources_headers level_0/random.h +build_sources_headers level_0/random.h level_0/random/common.h build_sources_headers level_0/rip.h level_0/rip/utf.h build_sources_headers level_0/serialize.h level_0/serialize/common.h build_sources_headers level_0/signal.h level_0/signal/common.h diff --git a/level_0/f_random/c/random.h b/level_0/f_random/c/random.h index f58f739..cdb7c99 100644 --- a/level_0/f_random/c/random.h +++ b/level_0/f_random/c/random.h @@ -21,6 +21,9 @@ #include #include +// FLL-0 random includes. +#include + #ifdef __cplusplus extern "C" { #endif @@ -62,8 +65,8 @@ extern "C" { * The flags to be passed to getrandom(). * * Flag bits: - * - GRND_RANDOM: Random data is taken from the random source, such as /dev/random and not the urandom source. - * - GRND_NONBLOCK: Does not block when getting the bits. + * - F_random_seed_flag_block_not_d: Does not block when getting the bits. + * - F_random_seed_flag_source_d: Random data is taken from the random source, such as /dev/random and not the urandom source. * @param length * The size within the destination string to copy. * The standard max size is 255. @@ -108,8 +111,8 @@ extern "C" { * The flags to be passed to getrandom(). * * Flag bits: - * - GRND_RANDOM: Random data is taken from the random source, such as /dev/random and not the urandom source. - * - GRND_NONBLOCK: Does not block when getting the bits. + * - F_random_seed_flag_block_not_d: Does not block when getting the bits. + * - F_random_seed_flag_source_d: Random data is taken from the random source, such as /dev/random and not the urandom source. * * @return * F_okay on success. diff --git a/level_0/f_random/c/random/common.h b/level_0/f_random/c/random/common.h new file mode 100644 index 0000000..9431477 --- /dev/null +++ b/level_0/f_random/c/random/common.h @@ -0,0 +1,42 @@ +/** + * FLL - Level 0 + * + * Project: Random + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Defines common data to be used for/by project random. + * + * This is auto-included by random.h and should not need to be explicitly included. + */ +#ifndef _F_random_common_h +#define _F_random_common_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Defines associated with random seed flags. + * + * F_random_seed_flag_*: + * - block_not: Does not block when getting the bits. + * - insecure: Use insecure, aka non-cryptographic, random bytes. + * - source: Random data is taken from the random source, such as /dev/random and not the urandom source. + */ +#ifndef _di_f_random_seed_flag_d_ + #define F_random_seed_flag_block_not_d GRND_NONBLOCK + #define F_random_seed_flag_source_d GRND_RANDOM + + #ifdef GRND_INSECURE + #define F_random_seed_flag_insecure_d GRND_INSECURE + #else + #define F_random_seed_flag_insecure_d 0x0004 + #endif // GRND_INSECURE +#endif // _di_f_random_seed_flag_d_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_random_common_h diff --git a/level_0/f_random/data/build/settings b/level_0/f_random/data/build/settings index b9bb7f8..d4f56f4 100644 --- a/level_0/f_random/data/build/settings +++ b/level_0/f_random/data/build/settings @@ -34,7 +34,7 @@ build_libraries-individual -lf_memory -lf_string build_sources_library random.c -build_sources_headers random.h +build_sources_headers random.h random/common.h build_script yes build_shared yes diff --git a/level_0/f_random/data/build/settings-mocks b/level_0/f_random/data/build/settings-mocks index 9548555..4ee4533 100644 --- a/level_0/f_random/data/build/settings-mocks +++ b/level_0/f_random/data/build/settings-mocks @@ -23,7 +23,7 @@ build_libraries-individual -lf_memory build_sources_library random.c build_sources_library ../../tests/unit/c/mock-random.c -build_sources_headers random.h +build_sources_headers random.h random/common.h build_script yes build_shared yes -- 1.8.3.1