2004-01-22 19:15:32 +00:00
|
|
|
/*
|
|
|
|
* uxgen.c: Unix implementation of get_heavy_noise() from cmdgen.c.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "putty.h"
|
|
|
|
|
|
|
|
char *get_random_data(int len)
|
|
|
|
{
|
|
|
|
char *buf = snewn(len, char);
|
|
|
|
int fd;
|
|
|
|
int ngot, ret;
|
|
|
|
|
|
|
|
fd = open("/dev/random", O_RDONLY);
|
|
|
|
if (fd < 0) {
|
|
|
|
sfree(buf);
|
|
|
|
perror("puttygen: unable to open /dev/random");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ngot = 0;
|
|
|
|
while (ngot < len) {
|
|
|
|
ret = read(fd, buf+ngot, len-ngot);
|
|
|
|
if (ret < 0) {
|
|
|
|
close(fd);
|
2013-07-14 10:46:07 +00:00
|
|
|
sfree(buf);
|
2004-01-22 19:15:32 +00:00
|
|
|
perror("puttygen: unable to read /dev/random");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
ngot += ret;
|
|
|
|
}
|
|
|
|
|
2010-09-09 14:36:46 +00:00
|
|
|
close(fd);
|
|
|
|
|
2004-01-22 19:15:32 +00:00
|
|
|
return buf;
|
|
|
|
}
|