Use a more precise name for a CSPRNG API with an interval

I have plans to split this function in smaller functions that implement
bits of this functionallity, to simplify the implementation.  So, let's
use names that distinguish them.

This one produces a number within an interval, so make that clear.  Also
make clear that the function produces cryptographically-secure numbers.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alejandro Colomar 2022-12-30 18:46:22 +01:00 committed by Serge Hallyn
parent a27d5c51f1
commit 8f441c9f7a

View File

@ -94,7 +94,7 @@ static long read_random_bytes (void);
static /*@observer@*/const char *gensalt (size_t salt_size); static /*@observer@*/const char *gensalt (size_t salt_size);
#endif /* !USE_XCRYPT_GENSALT */ #endif /* !USE_XCRYPT_GENSALT */
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) #if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT)
static long shadow_random (long min, long max); static long csrand_interval (long min, long max);
#endif /* USE_SHA_CRYPT || USE_BCRYPT */ #endif /* USE_SHA_CRYPT || USE_BCRYPT */
#ifdef USE_SHA_CRYPT #ifdef USE_SHA_CRYPT
static /*@observer@*/unsigned long SHA_get_salt_rounds (/*@null@*/const int *prefered_rounds); static /*@observer@*/unsigned long SHA_get_salt_rounds (/*@null@*/const int *prefered_rounds);
@ -163,7 +163,7 @@ end:
* *
* It favors slightly the higher numbers. * It favors slightly the higher numbers.
*/ */
static long shadow_random (long min, long max) static long csrand_interval (long min, long max)
{ {
double drand; double drand;
long ret; long ret;
@ -207,7 +207,7 @@ static /*@observer@*/unsigned long SHA_get_salt_rounds (/*@null@*/const int *pre
max_rounds = min_rounds; max_rounds = min_rounds;
} }
rounds = (unsigned long) shadow_random (min_rounds, max_rounds); rounds = (unsigned long) csrand_interval (min_rounds, max_rounds);
} }
} else if (0 == *prefered_rounds) { } else if (0 == *prefered_rounds) {
rounds = SHA_ROUNDS_DEFAULT; rounds = SHA_ROUNDS_DEFAULT;
@ -280,7 +280,7 @@ static /*@observer@*/unsigned long BCRYPT_get_salt_rounds (/*@null@*/const int *
max_rounds = min_rounds; max_rounds = min_rounds;
} }
rounds = (unsigned long) shadow_random (min_rounds, max_rounds); rounds = (unsigned long) csrand_interval (min_rounds, max_rounds);
} }
} else if (0 == *prefered_rounds) { } else if (0 == *prefered_rounds) {
rounds = B_ROUNDS_DEFAULT; rounds = B_ROUNDS_DEFAULT;