This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH, libgfortran] Improve PRNG seed scrambling


Hi,

the attached patch improves the scrambling of the seed given by the
RANDOM_SEED intrinsic. Previously we shuffled the bytes in the seed
back and forth, the new implementation replaces this with a "XOR
cipher" (https://en.wikipedia.org/wiki/XOR_cipher). Also, now the
scrambling is also done for the random_seed_i8 variant, previously
only the i4 variant was scrambled.

Similarly to the previous implementation, this is of course not a
defence against somebody who is determined to generate a poor seed.
But it's a protection from naive users setting all seed values to 0 or
to some small constant value, or similar low entropy seeds.

Since this is bordering on obvious, I'm planning to commit this in a
few days unless somebody objects. Regtested on x86_64-pc-linux-gnu.

libgfortran:
2016-08-16  Janne Blomqvist  <jb@gcc.gnu.org>

    * intrinsics/random.c (xor_keys): New array with "secret" keys.
    (scramble_seed): XOR given seed with xor_keys array rather than
    shuffling bytes.
    (unscramble_seed): Remove function.
    (random_seed_i4): Use new scramble_seed.
    (random_seed_i8): Likewise.

frontend:
2016-08-16  Janne Blomqvist  <jb@gcc.gnu.org>

    * intrinsics.texi (RANDOM_NUMBER): Remove reference to
    init_random_seed in example.
    (RANDOM_SEED): Remove warning to not set all seed values to 0.


-- 
Janne Blomqvist

Attachment: random-xor.diff
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]