Menu

#21 efiix8x48::seed initialisation problem

v1.0_(example)
accepted
nobody
None
5
2025-06-21
2025-06-21
Lucas Rey
No

if you look at the answer in here:
https://stackoverflow.com/questions/7760291/default-initialization-of-c-member-arrays

it is stated in the standard that c-style arrays of chars are not initialised. for the rng efiix8x48, the tables indirection_table and iteration_table are c-style arrays of type std_uint8_t which is equivalent to a char. This means that those arrays will NOT be default initialised, therefore having potentially random values in them.

By the time we reach the function efiix8x48::seed in line 240 of brng/test/external/PractRand-pre0.95/src/RNGs/efiix.cpp, we will start reading from that table at a potentially uninitialised and random state. For example if seed=1, then in line 256 we will be reading indirectino_table[1] and that has never been set to any value.

a way to solve this would be to replace the lines 243-244:
iteration_table[0] = 0;
indirection_table[0] = 0;

with:
for (unsigned long y = 0; y < ITERATION_SIZE; y++) {
iteration_table[y] = 0;
}
for (unsigned long y = 0; y < INDIRECTION_SIZE; y++) {
indirection_table[y] = 0;
}

That way we are sure that those tables are properly initialised before any subsequent read-write

Discussion

  • - 2025-06-21

    Indeed seeding in 0.95 does use some uninitialized variables, though I would say the problem lies elsewhere, starting with line 252 (mask should have been initialized to 0, not 1), and continuing inside the loop where the code isn't fully adapted - it was supposed to start with an effective ITERATION_SIZE and INDIRECTION_SIZE of 1, use that to double the size of the initialized section of each array, then double the effective array sizes and repeat until both arrays are entirely populated, but I hadn't finished that code and it was left with nondeterministic behavior. That should be fixed for version 0.96.

     

    Last edit: 2025-06-21
  • - 2025-06-21
    • status: open --> accepted
     

Log in to post a comment.

MongoDB Logo MongoDB