1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-31 15:43:01 +00:00

Add JANET_HASHSEED environment variable.

This commit is contained in:
Calvin Rose
2020-08-03 20:53:32 -05:00
parent f200bd9594
commit 76cfbde933
6 changed files with 35 additions and 9 deletions

View File

@@ -1018,14 +1018,22 @@ int main(int argc, char **argv) {
#endif
#if defined(JANET_PRF)
uint8_t hash_key[JANET_HASH_KEY_SIZE];
if (janet_cryptorand(hash_key, JANET_HASH_KEY_SIZE) != 0) {
uint8_t hash_key[JANET_HASH_KEY_SIZE + 1];
#ifdef JANET_REDUCED_OS
char *envvar = NULL;
#else
char *envvar = getenv("JANET_HASHSEED");
#endif
if (NULL != envvar) {
strncpy((char *) hash_key, envvar, sizeof(hash_key) - 1);
} else if (janet_cryptorand(hash_key, JANET_HASH_KEY_SIZE) != 0) {
fputs("unable to initialize janet PRF hash function.\n", stderr);
return 1;
}
janet_init_hash_key(hash_key);
#endif
/* Set up VM */
janet_init();