39#ifdef HAVE_SYS_RANDOM_H
40#include <sys/random.h>
47static const unsigned char Base32[] =
"abcdefghijklmnopqrstuvwxyz234567";
71 rc = getrandom((
char *) buf + count, buflen - count, 0);
74 }
while (((rc >= 0) && (count < buflen)) || ((rc == -1) && (errno == EINTR)));
82 FpRandom = fopen(
"/dev/urandom",
"rb");
85 mutt_error(
_(
"open /dev/urandom: %s"), strerror(errno));
90 if (fread(buf, 1, buflen,
FpRandom) != buflen)
92 mutt_error(
_(
"read /dev/urandom: %s"), strerror(errno));
106 if (!buf || (buflen == 0))
109 uint8_t *p = (uint8_t *) buf;
113 for (
size_t pos = 0; pos < buflen; pos++)
114 p[pos] =
Base32[p[pos] % 32];
void mutt_exit(int code)
Leave NeoMutt NOW.
static const unsigned char Base32[]
Base 32 alphabet.
uint64_t mutt_rand64(void)
Create a 64-bit random number.
static int mutt_randbuf(void *buf, size_t buflen)
Fill a buffer with randomness.
uint32_t mutt_rand32(void)
Create a 32-bit random number.
static FILE * FpRandom
FILE pointer of the random source.
void mutt_rand_base32(char *buf, size_t buflen)
Fill a buffer with a base32-encoded random string.
Random number/string functions.