Re: [hackers] Re: [sbase] Orphan patches and unsent patches

From: NRK <nrk_AT_disroot.org>
Date: Sun, 3 Mar 2024 21:20:03 +0000

On Sun, Mar 03, 2024 at 03:05:47PM +0100, Eolien55 wrote:
> but should we not rather implement "Debiased Int Mult (t-opt)"?

Both should be fine. The integer mul method avoids clz() so that could
be a reason to prefer it.

> arc4random(3) doesn't uses seeds, which means that I cannot initialize
> it wrong.

I see, that makes sense.

You had the right idea on one of your eariler patch about mixing
malloc-ed address and time but the implementation wasn't good.

        srandom((intptr_t)buf.nlines | time(NULL));

OR isn't a good mixer because it's biased towards 1 (it's also not
reversible):
        
        0 | 0 = 0
        0 | 1 = 1
        1 | 0 = 1
        1 | 1 = 1

XOR would be better. But even better would be to hash it before xor-ing.
Just a multiply by an large-ish odd number is usually sufficient:

        seed = ((uintptr_t)malloced_addr * 0xAC5533CD) ^ time(NULL) /* or use nanoseconds */;

You could also mix in a stack address and/or the address of a (usually)
dynamically linked function the same way. This should be enough to get a
decent seed without relying on system specific interfaces.
(See also: https://nullprogram.com/blog/2019/04/30/)

- NRK
Received on Sun Mar 03 2024 - 22:20:03 CET

This archive was generated by hypermail 2.3.0 : Sun Mar 03 2024 - 22:24:36 CET