head 1.2; access; symbols; locks; strict; comment @# @; 1.2 date 2022.09.11.19.33.05; author schmonz; state dead; branches; next 1.1; commitid U2Ki3xiyPWB5RtTD; 1.1 date 2022.08.30.17.55.31; author schmonz; state Exp; branches; next ; commitid TzVUibcj0mpxHVRD; desc @@ 1.2 log @Update to 20220901. From the changelog: - fixed randombytes(), uses getentropy() and /dev/urandom where getentropy() does not exist @ text @$NetBSD: patch-randombytes.c-02devurandom,v 1.1 2022/08/30 17:55:31 schmonz Exp $ Apply upstream commit 0cb7bb4 to fall back to /dev/urandom on systems where getentropy() is not present. --- randombytes.c-02devurandom.orig 2022-08-30 17:47:01.000000000 +0000 +++ randombytes.c-02devurandom @@@@ -0,0 +1,43 @@@@ +#include +#include +#include +#include +#include "randombytes.h" + +static int fd = -1; + +void randombytes(void *xv, long long xlen) { + + long long i; + unsigned char *x = xv; + + if (fd == -1) { + for (;;) { +#ifdef O_CLOEXEC + fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC); +#else + fd = open("/dev/urandom", O_RDONLY); + fcntl(fd, F_SETFD, 1); +#endif + if (fd != -1) break; + sleep(1); + } + } + + while (xlen > 0) { + if (xlen < 1048576) + i = xlen; + else + i = 1048576; + + i = read(fd, x, i); + if (i < 1) { + sleep(1); + continue; + } + + x += i; + xlen -= i; + } + __asm__ __volatile__("" : : "r"(xv) : "memory"); +} @ 1.1 log @Apply upstream commit 0cb7bb4 to fall back to /dev/urandom on systems where getentropy() is not present. Bump PKGREVISION. @ text @d1 1 a1 1 $NetBSD$ @