[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Implementing getrandom/getentropy, anybody?
From: |
Samuel Thibault |
Subject: |
Re: Implementing getrandom/getentropy, anybody? |
Date: |
Wed, 30 Oct 2019 09:43:07 +0100 |
User-agent: |
NeoMutt/20170609 (1.8.3) |
Hello,
Andrew Eggenberger, le mar. 29 oct. 2019 23:28:26 -0500, a ecrit:
> Updated patch attached.
Thanks!
> +/* Implementation of getentropy based on the getrandom system call.
getrandom is not a system call on GNU/Hurd, just say "on getrandom".
> + /* NB: No cancellation point. */
> + ssize_t bytes = getrandom(buffer, end - buffer, 0);
Ah, yes, the cancelation thing. Inside getrandom(), rather use
__open_nocancel, __read_nocancel, and __close_nocancel.
> +/* Write up to LENGTH bytes of randomness starting at BUFFER.
> + Return the number of bytes written, or -1 on error. */
> +ssize_t
> +getrandom (void *buffer, size_t length, unsigned int flags)
> +{
> + char* random_source = "/dev/urandom";
You can even make it a const char* actually.
> + int amount_read, fp;
> +
> + if (flags & GRND_RANDOM){
> + random_source = "/dev/random";
> + }
> +
> + fp = open(random_source, O_RDONLY);
> + amount_read = read(fp, buffer, length);
You need to check against errors, and in such a case return -1 (leaving
errno as set by the function).
Samuel