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); }