aboutsummaryrefslogtreecommitdiff
path: root/builtins/functions.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-07-04 16:46:24 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-07-04 16:46:24 -0400
commit78960b1461a8fb184de4ffddf2d2ec4df729fb05 (patch)
treef62f39c9d6b420c304bffba8143a41789980e68a /builtins/functions.c
parentdfb7bb1984b555519851d084ac8b5f8e760c55ce (diff)
Randomize hash key on startup and rename to TOMO_HASH_KEY.
Diffstat (limited to 'builtins/functions.c')
-rw-r--r--builtins/functions.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/builtins/functions.c b/builtins/functions.c
index 7ece75ea..8916f936 100644
--- a/builtins/functions.c
+++ b/builtins/functions.c
@@ -7,6 +7,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <sys/param.h>
+#include <sys/random.h>
#include <uninorm.h>
#include <unistd.h>
@@ -22,14 +23,17 @@
#include "types.h"
#include "util.h"
-public const char *TOMO_HASH_VECTOR = "tomo hash vector ---------------------------------------------";
+public uint8_t TOMO_HASH_KEY[8] = {0};
public void tomo_init(void)
{
GC_INIT();
USE_COLOR = getenv("COLOR") ? strcmp(getenv("COLOR"), "1") == 0 : isatty(STDOUT_FILENO);
- srand(arc4random_uniform(UINT32_MAX));
- srand48(arc4random_uniform(UINT32_MAX));
+ getrandom(TOMO_HASH_KEY, sizeof(TOMO_HASH_KEY), 0);
+ unsigned int seed;
+ getrandom(&seed, sizeof(seed), 0);
+ srand(seed);
+ srand48(seed);
}
public void fail(CORD fmt, ...)
@@ -98,7 +102,7 @@ public uint32_t generic_hash(const void *obj, const TypeInfo *type)
default: {
hash_data:;
uint32_t hash;
- halfsiphash((void*)obj, type->size, TOMO_HASH_VECTOR, (uint8_t*)&hash, sizeof(hash));
+ halfsiphash((void*)obj, type->size, TOMO_HASH_KEY, (uint8_t*)&hash, sizeof(hash));
return hash;
}
}