mirror of
https://github.com/hashcat/hashcat.git
synced 2025-01-11 08:10:59 +00:00
Fix CID 1402374
This commit is contained in:
parent
8b28940630
commit
b381b38fd8
40
src/shared.c
40
src/shared.c
@ -12,13 +12,6 @@ bool is_power_of_2 (const u32 v)
|
||||
return (v && !(v & (v - 1)));
|
||||
}
|
||||
|
||||
u32 get_random_num (const u32 min, const u32 max)
|
||||
{
|
||||
if (min == max) return (min);
|
||||
|
||||
return (((u32) rand () % (max - min)) + min);
|
||||
}
|
||||
|
||||
u32 mydivc32 (const u32 dividend, const u32 divisor)
|
||||
{
|
||||
u32 quotient = dividend / divisor;
|
||||
@ -329,3 +322,36 @@ void setup_seeding (const bool rp_gen_seed_chgd, const u32 rp_gen_seed)
|
||||
srand (ts);
|
||||
}
|
||||
}
|
||||
|
||||
u32 get_random_num (const u32 min, const u32 max)
|
||||
{
|
||||
if (min == max) return (min);
|
||||
|
||||
const uint low = max - min;
|
||||
|
||||
if (low == 0) return (0);
|
||||
|
||||
#if defined (__linux__)
|
||||
|
||||
u32 data;
|
||||
|
||||
FILE *fp = fopen ("/dev/urandom", "rb");
|
||||
|
||||
if (fp == NULL) return (0);
|
||||
|
||||
const int nread = fread (&data, sizeof (u32), 1, fp);
|
||||
|
||||
fclose (fp);
|
||||
|
||||
if (nread != 1) return 0;
|
||||
|
||||
u64 r = data % low; r += min;
|
||||
|
||||
return (u32) r;
|
||||
|
||||
#else
|
||||
|
||||
return (((u32) rand () % (max - min)) + min);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user