random: cleanup, assume getrandom libc wrapper exists
This commit is contained in:
parent
b44ca5bd79
commit
0792d8890f
27
random.h
27
random.h
@ -3,37 +3,13 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#include <linux/random.h>
|
#include <sys/random.h>
|
||||||
#endif
|
|
||||||
#ifndef SYS_getrandom
|
|
||||||
#include <openssl/rand.h>
|
|
||||||
#endif
|
#endif
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
//dirty hacks
|
|
||||||
#ifdef SYS_getrandom
|
|
||||||
inline int getrandom(void *buf, size_t buflen, unsigned int flags)
|
|
||||||
{
|
|
||||||
return syscall(SYS_getrandom, buf, buflen, flags);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
|
|
||||||
#if __linux__
|
|
||||||
//ancient linux systems
|
|
||||||
#define GRND_NONBLOCK 0
|
|
||||||
inline int getrandom(void *buf, size_t buflen, unsigned int flags)
|
|
||||||
{
|
|
||||||
int result = RAND_bytes(buf, buflen);
|
|
||||||
if(result == 1)
|
|
||||||
{
|
|
||||||
return (int) buflen;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#if __OpenBSD__
|
#if __OpenBSD__
|
||||||
inline int getrandom(void *buf, size_t buflen, unsigned int flags)
|
inline int getrandom(void *buf, size_t buflen, unsigned int flags)
|
||||||
{
|
{
|
||||||
@ -41,7 +17,6 @@ inline int getrandom(void *buf, size_t buflen, unsigned int flags)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
/* TODO: if the >=C++11 prngr are good enough, use them */
|
/* TODO: if the >=C++11 prngr are good enough, use them */
|
||||||
class Random
|
class Random
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user