summaryrefslogtreecommitdiff
path: root/src/basic/random-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-11-07 18:27:57 +0100
committerLennart Poettering <lennart@poettering.net>2018-11-08 09:44:27 +0100
commit3335dc2d7591fa4e5ae28efa9a2ab35fd5ba1951 (patch)
tree9aece79b3bd3c4ea6e4331bbfe98246604a7e915 /src/basic/random-util.c
parent8d2411f69348a081419c2fb7cddbe1970cf3eac5 (diff)
downloadsystemd-3335dc2d7591fa4e5ae28efa9a2ab35fd5ba1951.tar.gz
random-util: rename acquire_random_bytes() → genuine_random_bytes()
It's more descriptive, since we also have a function random_bytes() which sounds very similar. Also rename pseudorandom_bytes() to pseudo_random_bytes(). This way the two functions are nicely systematic, one returning genuine random bytes and the other pseudo random ones.
Diffstat (limited to 'src/basic/random-util.c')
-rw-r--r--src/basic/random-util.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/basic/random-util.c b/src/basic/random-util.c
index 071a41f186..5e4ed2da9d 100644
--- a/src/basic/random-util.c
+++ b/src/basic/random-util.c
@@ -65,7 +65,7 @@ int rdrand64(uint64_t *ret) {
#endif
}
-int acquire_random_bytes(void *p, size_t n, bool high_quality_required) {
+int genuine_random_bytes(void *p, size_t n, bool high_quality_required) {
static int have_syscall = -1;
_cleanup_close_ int fd = -1;
@@ -88,7 +88,7 @@ int acquire_random_bytes(void *p, size_t n, bool high_quality_required) {
return 0;
if (!high_quality_required) {
/* Fill in the remaining bytes using pseudorandom values */
- pseudorandom_bytes((uint8_t*) p + r, n - r);
+ pseudo_random_bytes((uint8_t*) p + r, n - r);
return 0;
}
@@ -124,7 +124,7 @@ int acquire_random_bytes(void *p, size_t n, bool high_quality_required) {
memcpy(p, &u, k);
/* We only get 64bit out of RDRAND, the rest let's fill up with pseudo-random crap. */
- pseudorandom_bytes((uint8_t*) p + k, n - k);
+ pseudo_random_bytes((uint8_t*) p + k, n - k);
return 0;
}
} else
@@ -180,7 +180,7 @@ void initialize_srand(void) {
# define RAND_STEP 1
#endif
-void pseudorandom_bytes(void *p, size_t n) {
+void pseudo_random_bytes(void *p, size_t n) {
uint8_t *q;
initialize_srand();
@@ -203,13 +203,10 @@ void pseudorandom_bytes(void *p, size_t n) {
}
void random_bytes(void *p, size_t n) {
- int r;
- r = acquire_random_bytes(p, n, false);
- if (r >= 0)
+ if (genuine_random_bytes(p, n, false) >= 0)
return;
- /* If some idiot made /dev/urandom unavailable to us, or the
- * kernel has no entropy, use a PRNG instead. */
- return pseudorandom_bytes(p, n);
+ /* If for some reason some user made /dev/urandom unavailable to us, or the kernel has no entropy, use a PRNG instead. */
+ pseudo_random_bytes(p, n);
}