From c4b3e47e87632bb959b9529aba6a640dadd3718f Mon Sep 17 00:00:00 2001 From: Steven Dee Date: Thu, 5 Mar 2015 20:58:57 -0500 Subject: [PATCH 1/2] Use pwd command, not PWD env var So, sometimes PWD isn't exported. Like if you're in some kind of weird sudo login session or something. I don't know. It was broken for me. This fixed it. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 01e06c8bb..7d4c03757 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ ENDIAN=little # BIN=bin -LIB=$(PWD)/urb +LIB=$(shell pwd)/urb RM=rm -f CC=gcc From 0308c9a00a40114a902a84a40fb433b2c6f91db5 Mon Sep 17 00:00:00 2001 From: Steven Dee Date: Wed, 18 Mar 2015 18:48:29 -0400 Subject: [PATCH 2/2] Use getentropy(2) on OpenBSD --- i/c/portable.h | 9 +++++++++ i/v/vere.h | 5 +++++ v/sist.c | 12 ++++++------ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/i/c/portable.h b/i/c/portable.h index 30381ced1..4cbf0a3c7 100644 --- a/i/c/portable.h +++ b/i/c/portable.h @@ -178,3 +178,12 @@ # else # error "port: timeconvert" # endif + +/* Entropy + */ +# if defined(U3_OS_bsd) && defined(__OpenBSD__) +# define c3_rand(rd) (getentropy((void*)rd, 32) == 0 ? \ + (void)0 : c3_assert(!"ent")) +# else +# define c3_rand u3_sist_rand +# endif diff --git a/i/v/vere.h b/i/v/vere.h index e4ebb4e12..6e6868031 100644 --- a/i/v/vere.h +++ b/i/v/vere.h @@ -1094,6 +1094,11 @@ void u3_sist_get(const c3_c* key_c, c3_y* val_y); + /* u3_sist_rand(): fill 8 words (32 bytes) with high-quality entropy. + */ + void + u3_sist_rand(c3_w* rad_w); + /** New timer system. **/ /* u3_temp_io_init(): initialize time timer. diff --git a/v/sist.c b/v/sist.c index b3655f5ff..7013d05b5 100644 --- a/v/sist.c +++ b/v/sist.c @@ -444,10 +444,10 @@ _sist_bask(c3_c* pop_c, u3_noun may) } #endif -/* _sist_rand(): fill a 256-bit (8-word) buffer. +/* u3_sist_rand(): fill a 256-bit (8-word) buffer. */ -static void -_sist_rand(c3_w* rad_w) +void +u3_sist_rand(c3_w* rad_w) { c3_i fid_i = open(DEVRANDOM, O_RDONLY); @@ -589,7 +589,7 @@ _sist_zest() { c3_w rad_w[8]; - _sist_rand(rad_w); + c3_rand(rad_w); sal_l = (0x7fffffff & rad_w[0]); } @@ -599,7 +599,7 @@ _sist_zest() c3_w rad_w[8]; u3_noun pas; - _sist_rand(rad_w); + c3_rand(rad_w); pas = u3i_words(2, rad_w); u3A->key = _sist_fatt(sal_l, u3k(pas)); @@ -1201,7 +1201,7 @@ _sist_zen() { c3_w rad_w[8]; - _sist_rand(rad_w); + c3_rand(rad_w); return u3i_words(8, rad_w); }