ObjFW  Diff

Differences From Artifact [975aa82042]:

To Artifact [41e131467f]:

  • File src/macros.h — part of check-in [c1fe4b2b77] at 2020-07-12 09:49:35 on branch trunk — Make of_random() a function

    When arc4random() is unavailable, either random() or rand() is used and
    both need to be seeded. If of_random() is a macro, it needs to be
    (re)seeded every time, as it's unknown whether it has already been
    seeded. As it is seeded with gettimeofday() due to the lack of a better
    initial seed, this means every call returns the first state for the
    current time, which is very predictable. random() and rand() are both
    not cryptographic, but this should at least make it a little bit better
    now. (user: js, size: 21483) [annotate] [blame] [check-ins using] [more...]


894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
}

static OF_INLINE char
of_ascii_tolower(char c)
{
	return (c >= 'A' && c <= 'Z' ? 'a' + (c - 'A') : c);
}

/* This does *NOT* provide cryptographically secure randomness! */
static OF_INLINE uint32_t
of_random(void) {
#if defined(OF_HAVE_ARC4RANDOM)
	return arc4random();
#elif defined(OF_HAVE_RANDOM)
	struct timeval tv;

	gettimeofday(&tv, NULL);
	srandom((unsigned)(tv.tv_sec ^ tv.tv_usec));
	return (((uint32_t)(random()) << 16) | ((uint32_t)(random()) & 0xFFFF));
#else
	struct timeval tv;

	gettimeofday(&tv, NULL);
	srand((unsigned)(tv.tv_sec ^ tv.tv_usec));
	return (((uint32_t)(rand()) << 16) | ((uint32_t)(rand()) & 0xFFFF));
#endif
}

#endif







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

<
<
<
894
895
896
897
898
899
900


















901



}

static OF_INLINE char
of_ascii_tolower(char c)
{
	return (c >= 'A' && c <= 'Z' ? 'a' + (c - 'A') : c);
}


















#endif