Skip to content

Commit

Permalink
Add seed operation for unix RAND method
Browse files Browse the repository at this point in the history
  • Loading branch information
nicowilliams committed Apr 15, 2016
1 parent 2cd233d commit f064f2d
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion lib/hcrypto/rand-unix.c
Expand Up @@ -68,8 +68,33 @@ _hc_unix_device_fd(int flags, const char **fn)
}

static void
unix_seed(const void *indata, int size)
unix_seed(const void *p, int size)
{
const unsigned char *indata = p;
ssize_t count;
int fd;

if (size < 0)
return;
else if (size == 0)
return;

fd = _hc_unix_device_fd(O_RDONLY, NULL);
if (fd < 0)
return;

while (size > 0) {
count = write(fd, indata, size);
if (count < 0 && errno == EINTR)
continue;
else if (count <= 0) {
close(fd);
return;
}
indata += count;
size -= count;
}
close(fd);
}


Expand Down

0 comments on commit f064f2d

Please sign in to comment.