From 3ccf4e3759684e9809ad80c2f2639ec5f069beff Mon Sep 17 00:00:00 2001 From: default Date: Sun, 16 Apr 2023 20:27:38 +0200 Subject: [PATCH] arc4random() does not exist in not-so-old systems, so revert this. Revert "Replaced random() with arc4random()." This reverts commit f658f345cac7b24d6fa61f08b4ec09823d28b11a. --- mastoapi.c | 8 ++++---- snac.c | 2 +- utils.c | 7 ++++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/mastoapi.c b/mastoapi.c index c562203..af8fb27 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -21,10 +21,10 @@ static xs_str *random_str(void) fclose(f); } else { - data[0] = arc4random(); - data[1] = arc4random(); - data[2] = arc4random(); - data[3] = arc4random(); + data[0] = random() % 0xffffffff; + data[1] = random() % 0xffffffff; + data[2] = random() % 0xffffffff; + data[3] = random() % 0xffffffff; } return xs_hex_enc((char *)data, sizeof(data)); diff --git a/snac.c b/snac.c index f818dd8..a5b2080 100644 --- a/snac.c +++ b/snac.c @@ -123,7 +123,7 @@ d_char *hash_password(const char *uid, const char *passwd, const char *nonce) xs *hash; if (nonce == NULL) { - d_nonce = xs_fmt("%08x", arc4random()); + d_nonce = xs_fmt("%08x", random()); nonce = d_nonce; } diff --git a/utils.c b/utils.c index 24a2c66..24a6be6 100644 --- a/utils.c +++ b/utils.c @@ -198,9 +198,10 @@ void new_password(const char *uid, d_char **clear_pwd, d_char **hashed_pwd) { int rndbuf[3]; - rndbuf[0] = arc4random(); - rndbuf[1] = arc4random(); - rndbuf[2] = arc4random(); + srandom(time(NULL) ^ getpid()); + rndbuf[0] = random() & 0xffffffff; + rndbuf[1] = random() & 0xffffffff; + rndbuf[2] = random() & 0xffffffff; *clear_pwd = xs_base64_enc((char *)rndbuf, sizeof(rndbuf)); *hashed_pwd = hash_password(uid, *clear_pwd, NULL);