mirror of
https://github.com/jedisct1/libsodium.git
synced 2024-12-28 22:21:15 -07:00
Directly use OpenBSD's arc4random() instead of opening /dev/urandom.
This commit is contained in:
parent
c7c4f95655
commit
7a85ec9789
@ -24,6 +24,39 @@
|
||||
# include <wincrypt.h>
|
||||
#endif
|
||||
|
||||
#ifdef __OpenBSD__
|
||||
|
||||
uint32_t
|
||||
randombytes_sysrandom(void)
|
||||
{
|
||||
return arc4random();
|
||||
}
|
||||
|
||||
void
|
||||
randombytes_sysrandom_stir(void)
|
||||
{
|
||||
}
|
||||
|
||||
uint32_t
|
||||
randombytes_sysrandom_uniform(const uint32_t upper_bound)
|
||||
{
|
||||
return arc4random_uniform(upper_bound);
|
||||
}
|
||||
|
||||
void
|
||||
randombytes_sysrandom_buf(void * const buf, const size_t size)
|
||||
{
|
||||
return arc4random_buf(buf, size);
|
||||
}
|
||||
|
||||
int
|
||||
randombytes_sysrandom_close(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else /* __OpenBSD__ */
|
||||
|
||||
typedef struct SysRandom_ {
|
||||
#ifdef _WIN32
|
||||
HCRYPTPROV hcrypt_prov;
|
||||
@ -202,6 +235,8 @@ randombytes_sysrandom_uniform(const uint32_t upper_bound)
|
||||
return r % upper_bound;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
const char *
|
||||
randombytes_sysrandom_implementation_name(void)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user