Browse Source

Issue #594 - provide an OVERRIDE_GET_RANDOM_SEED cmake variable to override json_c_get_random_seed() for embedded platforms where time(NULL) doesn't work.

Example:
mkdir build && cd build
cmake -DOVERRIDE_GET_RANDOM_SEED='do { extern uint32_t getMsTicks(void); int ms = getMsTicks() * 433494437; return ms; } while(0)' ..
tags/json-c-0.15-20200726
Eric Haszlakiewicz 5 years ago
parent
commit
730e3d044f
4 changed files with 9 additions and 0 deletions
  1. +2
    -0
      CMakeLists.txt
  2. +1
    -0
      README.md
  3. +3
    -0
      cmake/config.h.in
  4. +3
    -0
      random_seed.c

+ 2
- 0
CMakeLists.txt View File

@@ -96,6 +96,8 @@ option(DISABLE_THREAD_LOCAL_STORAGE "Disable using Thread-Local Storage (HAVE_
option(DISABLE_WERROR "Avoid treating compiler warnings as fatal errors." OFF) option(DISABLE_WERROR "Avoid treating compiler warnings as fatal errors." OFF)
option(ENABLE_RDRAND "Enable RDRAND Hardware RNG Hash Seed." OFF) option(ENABLE_RDRAND "Enable RDRAND Hardware RNG Hash Seed." OFF)
option(ENABLE_THREADING "Enable partial threading support." OFF) option(ENABLE_THREADING "Enable partial threading support." OFF)
option(OVERRIDE_GET_RANDOM_SEED "Override json_c_get_random_seed() with custom code." OFF)



if (UNIX OR MINGW OR CYGWIN) if (UNIX OR MINGW OR CYGWIN)
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)


+ 1
- 0
README.md View File

@@ -107,6 +107,7 @@ DISABLE_THREAD_LOCAL_STORAGE | Bool | Disable use of Thread-Local Storage (HAV
DISABLE_WERROR | Bool | Disable use of -Werror. DISABLE_WERROR | Bool | Disable use of -Werror.
ENABLE_RDRAND | Bool | Enable RDRAND Hardware RNG Hash Seed. ENABLE_RDRAND | Bool | Enable RDRAND Hardware RNG Hash Seed.
ENABLE_THREADING | Bool | Enable partial threading support. ENABLE_THREADING | Bool | Enable partial threading support.
OVERRIDE_GET_RANDOM_SEED | String | A block of code to use instead of the default implementation of json_c_get_random_seed(), e.g. on embedded platforms where not even the fallback to time() works. Must be a single line.


Pass these options as `-D` on CMake's command-line. Pass these options as `-D` on CMake's command-line.




+ 3
- 0
cmake/config.h.in View File

@@ -2,6 +2,9 @@
/* Enable RDRAND Hardware RNG Hash Seed */ /* Enable RDRAND Hardware RNG Hash Seed */
#cmakedefine ENABLE_RDRAND "@ENABLE_RDRAND@" #cmakedefine ENABLE_RDRAND "@ENABLE_RDRAND@"


/* Override json_c_get_random_seed() with custom code */
#cmakedefine OVERRIDE_GET_RANDOM_SEED @OVERRIDE_GET_RANDOM_SEED@

/* Enable partial threading support */ /* Enable partial threading support */
#cmakedefine ENABLE_THREADING "@@" #cmakedefine ENABLE_THREADING "@@"




+ 3
- 0
random_seed.c View File

@@ -276,6 +276,9 @@ static int get_time_seed(void)


int json_c_get_random_seed(void) int json_c_get_random_seed(void)
{ {
#ifdef OVERRIDE_GET_RANDOM_SEED
OVERRIDE_GET_RANDOM_SEED;
#endif
#if defined HAVE_RDRAND && HAVE_RDRAND #if defined HAVE_RDRAND && HAVE_RDRAND
if (has_rdrand()) if (has_rdrand())
return get_rdrand_seed(); return get_rdrand_seed();


Loading…
Cancel
Save