mirror of
https://github.com/dsprenkels/sss.git
synced 2026-01-10 06:07:59 -05:00
21 lines
455 B
C
21 lines
455 B
C
#include "randombytes.h"
|
|
#include <assert.h>
|
|
#include <string.h>
|
|
|
|
#ifdef __linux__
|
|
# define _GNU_SOURCE
|
|
# include <sys/syscall.h>
|
|
#endif
|
|
|
|
|
|
void randombytes(void *buf, const size_t n)
|
|
{
|
|
#ifdef __linux__
|
|
int tmp = syscall(SYS_getrandom, buf, n, 0);
|
|
assert(tmp == n); /* Failure indicates a bug in the code */
|
|
#else
|
|
# warning "randombytes(...) is not supported on this platform. Using INSECURE dummy version."
|
|
memset(buf, 42, n);
|
|
#endif /* __linux__ */
|
|
}
|