Compare commits

...

2 Commits

Author SHA1 Message Date
Nicholas J. Kain
219443ba7a
random: Use unmodified SFC64. 2023-06-24 20:11:45 -04:00
Nicholas J. Kain
98e0ca3f6f
README: Writing PID files is not supported anymore. 2023-02-13 10:27:00 -05:00
2 changed files with 3 additions and 7 deletions

View File

@ -68,8 +68,7 @@ even sees the data. ndhc also only listens to DHCP traffic when it's
necessary. necessary.
*Flexible*. ndhc can request particular IPs, send user-specified client *Flexible*. ndhc can request particular IPs, send user-specified client
IDs, write a file that contains the current lease IP, write PID files, IDs, write a file that contains the current lease IP, etc.
etc.
*Self-contained*. ndhc does not exec other processes, or rely on the shell. *Self-contained*. ndhc does not exec other processes, or rely on the shell.
Further, ndhc relies on no external libraries aside from the system libc. Further, ndhc relies on no external libraries aside from the system libc.

View File

@ -1,11 +1,9 @@
// Copyright 2013-2022 Nicholas J. Kain <njkain at gmail dot com> // Copyright 2013-2023 Nicholas J. Kain <njkain at gmail dot com>
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <stdint.h> #include <stdint.h>
#include "nk/hwrng.h" #include "nk/hwrng.h"
#include "nk/random.h" #include "nk/random.h"
// SFC64 modified to use a Weyl counter.
void nk_random_init(struct nk_random_state *s) void nk_random_init(struct nk_random_state *s)
{ {
nk_hwrng_bytes(s->seed, sizeof(uint64_t) * 3); nk_hwrng_bytes(s->seed, sizeof(uint64_t) * 3);
@ -19,8 +17,7 @@ static inline uint64_t rotl64(const uint64_t x, int k) {
uint64_t nk_random_u64(struct nk_random_state *s) uint64_t nk_random_u64(struct nk_random_state *s)
{ {
const uint64_t t = (s->seed[0] + s->seed[1]) ^ s->seed[3]; const uint64_t t = s->seed[0] + s->seed[1] + s->seed[3]++;
s->seed[3] += 0x6a09e667a7541669ull;
s->seed[0] = s->seed[1] ^ (s->seed[1] >> 11); s->seed[0] = s->seed[1] ^ (s->seed[1] >> 11);
s->seed[1] = s->seed[2] + (s->seed[2] << 3); s->seed[1] = s->seed[2] + (s->seed[2] << 3);
s->seed[2] = rotl64(s->seed[2], 24) + t; s->seed[2] = rotl64(s->seed[2], 24) + t;