diff options
author | 2022-03-25 09:50:57 -0600 | |
---|---|---|
committer | 2022-03-26 00:34:39 -0600 | |
commit | 7d45946e1d0213feafb68d09e4d9ecee99eb1d77 (patch) | |
tree | dc6bd96d17b89b5567353e3eb197b82a0963102e | |
parent | Compile with -pedantic (diff) | |
download | seedrng-7d45946e1d0213feafb68d09e4d9ecee99eb1d77.tar.xz seedrng-7d45946e1d0213feafb68d09e4d9ecee99eb1d77.zip |
Allow skipping crediting
Might be desirable in certain scenarios.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | README.md | 5 | ||||
-rw-r--r-- | seedrng.c | 9 |
2 files changed, 12 insertions, 2 deletions
@@ -28,7 +28,10 @@ when writing new seed files: new_seed = new_seed[:-32] || HASH(fixed_prefix || real_time || boot_time || old_seed_len || old_seed || new_seed_len || new_seed) ``` -The seed is stored in `LOCALSTATEDIR/seedrng/`, which can be adjusted at compile time. +The seed is stored in `LOCALSTATEDIR/seedrng/`, which can be adjusted at +compile time. If the `SEEDRNG_SKIP_CREDIT` environment variable is set to `1`, +`true`, `yes`, or `y`, then seeds never credit the RNG, even if the seed file +is creditable. ### Building & Installing @@ -354,6 +354,13 @@ static int seed_from_file_if_exists(const char *filename, bool credit, struct bl return ret; } +static bool skip_credit(void) +{ + const char *skip = getenv("SEEDRNG_SKIP_CREDIT"); + return skip && (!strcmp(skip, "1") || !strcasecmp(skip, "true") || + !strcasecmp(skip, "yes") || !strcasecmp(skip, "y")); +} + int main(int argc __attribute__((unused)), char *argv[] __attribute__((unused))) { static const char seedrng_prefix[] = "SeedRNG v1 Old+New Prefix"; @@ -392,7 +399,7 @@ int main(int argc __attribute__((unused)), char *argv[] __attribute__((unused))) ret = seed_from_file_if_exists(NON_CREDITABLE_SEED, false, &hash); if (ret < 0) program_ret |= 1 << 1; - ret = seed_from_file_if_exists(CREDITABLE_SEED, true, &hash); + ret = seed_from_file_if_exists(CREDITABLE_SEED, !skip_credit(), &hash); if (ret < 0) program_ret |= 1 << 2; |