#
e8337330 |
| 20-Jun-2024 |
Nina Schoetterl-Glausch <nsg@linux.ibm.com> |
lib: Add pseudo random functions
Add functions for generating pseudo random 32 and 64 bit values. The implementation uses SHA-256 and so the randomness should have good quality. Implement the necess
lib: Add pseudo random functions
Add functions for generating pseudo random 32 and 64 bit values. The implementation uses SHA-256 and so the randomness should have good quality. Implement the necessary subset of SHA-256. The PRNG algorithm is equivalent to the following python snippet:
def prng32(seed): from hashlib import sha256 state = seed.to_bytes(8, byteorder="big") while True: state = sha256(state).digest() for i in range(8): yield int.from_bytes(state[i*4:(i+1)*4], byteorder="big")
Acked-by: Andrew Jones <andrew.jones@linux.dev> Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com> Acked-by: Nicholas Piggin <npiggin@gmail.com> Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
show more ...
|