2012-02-16 14:12:37 +00:00
|
|
|
/*
|
|
|
|
Serval Distributed Numbering Architecture (DNA)
|
|
|
|
Copyright (C) 2010 Paul Gardner-Stephen
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2013-08-27 05:44:17 +00:00
|
|
|
#include "os.h"
|
2011-10-25 03:45:19 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
/* it's really stupid that there isn't a syscall for this */
|
|
|
|
|
|
|
|
static int fd = -1;
|
|
|
|
|
|
|
|
void randombytes(unsigned char *x,unsigned long long xlen)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (fd == -1) {
|
|
|
|
for (;;) {
|
|
|
|
fd = open("/dev/urandom",O_RDONLY);
|
|
|
|
if (fd != -1) break;
|
2013-08-27 05:44:17 +00:00
|
|
|
sleep_ms(1000);
|
2011-10-25 03:45:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (xlen > 0) {
|
|
|
|
if (xlen < 1048576) i = xlen; else i = 1048576;
|
|
|
|
|
|
|
|
i = read(fd,x,i);
|
|
|
|
if (i < 1) {
|
2013-08-27 05:44:17 +00:00
|
|
|
sleep_ms(1000);
|
2011-10-25 03:45:19 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
x += i;
|
|
|
|
xlen -= i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|