Use naming consistent with other common functions
arc4random(3) returns a number. arc4random_buf(3) fills a buffer. arc4random_uniform(3) returns a number less than a bound. and I'd add a hypothetical one which we use: *_interval() should return a number within the interval [min, max]. In reality, the function being called csrand() in this patch is not really cryptographically secure, since it had a bias, but a subsequent patch will fix that. Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
parent
6d2337d9e8
commit
986ef4e69c
@ -89,7 +89,7 @@
|
|||||||
#define GENSALT_SETTING_SIZE 100
|
#define GENSALT_SETTING_SIZE 100
|
||||||
|
|
||||||
/* local function prototypes */
|
/* local function prototypes */
|
||||||
static long read_random_bytes (void);
|
static long csrand (void);
|
||||||
#if !USE_XCRYPT_GENSALT
|
#if !USE_XCRYPT_GENSALT
|
||||||
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 */
|
||||||
@ -110,7 +110,7 @@ static /*@observer@*/void YESCRYPT_salt_cost_to_buf (char *buf, unsigned long co
|
|||||||
#endif /* USE_YESCRYPT */
|
#endif /* USE_YESCRYPT */
|
||||||
|
|
||||||
/* Read sizeof (long) random bytes from /dev/urandom. */
|
/* Read sizeof (long) random bytes from /dev/urandom. */
|
||||||
static long read_random_bytes (void)
|
static long csrand (void)
|
||||||
{
|
{
|
||||||
long randval = 0;
|
long randval = 0;
|
||||||
|
|
||||||
@ -168,7 +168,7 @@ static unsigned long csrand_interval (unsigned long min, unsigned long max)
|
|||||||
double drand;
|
double drand;
|
||||||
long ret;
|
long ret;
|
||||||
|
|
||||||
drand = (double) (read_random_bytes () & RAND_MAX) / (double) RAND_MAX;
|
drand = (double) (csrand () & RAND_MAX) / (double) RAND_MAX;
|
||||||
drand *= (double) (max - min + 1);
|
drand *= (double) (max - min + 1);
|
||||||
/* On systems were this is not random() range is lower, we favor
|
/* On systems were this is not random() range is lower, we favor
|
||||||
* higher numbers of salt. */
|
* higher numbers of salt. */
|
||||||
@ -401,9 +401,9 @@ static /*@observer@*/const char *gensalt (size_t salt_size)
|
|||||||
|
|
||||||
assert (salt_size >= MIN_SALT_SIZE &&
|
assert (salt_size >= MIN_SALT_SIZE &&
|
||||||
salt_size <= MAX_SALT_SIZE);
|
salt_size <= MAX_SALT_SIZE);
|
||||||
strcat (salt, l64a (read_random_bytes ()));
|
strcat (salt, l64a (csrand ()));
|
||||||
do {
|
do {
|
||||||
strcat (salt, l64a (read_random_bytes ()));
|
strcat (salt, l64a (csrand ()));
|
||||||
} while (strlen (salt) < salt_size);
|
} while (strlen (salt) < salt_size);
|
||||||
|
|
||||||
salt[salt_size] = '\0';
|
salt[salt_size] = '\0';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user