Use getentropy(2) on OpenBSD

This commit is contained in:
Steven Dee 2015-03-18 18:48:29 -04:00
parent 5e00372d40
commit 0308c9a00a
3 changed files with 20 additions and 6 deletions

View File

@ -178,3 +178,12 @@
# else # else
# error "port: timeconvert" # error "port: timeconvert"
# endif # 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

View File

@ -1094,6 +1094,11 @@
void void
u3_sist_get(const c3_c* key_c, c3_y* val_y); 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. /** New timer system.
**/ **/
/* u3_temp_io_init(): initialize time timer. /* u3_temp_io_init(): initialize time timer.

View File

@ -444,10 +444,10 @@ _sist_bask(c3_c* pop_c, u3_noun may)
} }
#endif #endif
/* _sist_rand(): fill a 256-bit (8-word) buffer. /* u3_sist_rand(): fill a 256-bit (8-word) buffer.
*/ */
static void void
_sist_rand(c3_w* rad_w) u3_sist_rand(c3_w* rad_w)
{ {
c3_i fid_i = open(DEVRANDOM, O_RDONLY); c3_i fid_i = open(DEVRANDOM, O_RDONLY);
@ -589,7 +589,7 @@ _sist_zest()
{ {
c3_w rad_w[8]; c3_w rad_w[8];
_sist_rand(rad_w); c3_rand(rad_w);
sal_l = (0x7fffffff & rad_w[0]); sal_l = (0x7fffffff & rad_w[0]);
} }
@ -599,7 +599,7 @@ _sist_zest()
c3_w rad_w[8]; c3_w rad_w[8];
u3_noun pas; u3_noun pas;
_sist_rand(rad_w); c3_rand(rad_w);
pas = u3i_words(2, rad_w); pas = u3i_words(2, rad_w);
u3A->key = _sist_fatt(sal_l, u3k(pas)); u3A->key = _sist_fatt(sal_l, u3k(pas));
@ -1201,7 +1201,7 @@ _sist_zen()
{ {
c3_w rad_w[8]; c3_w rad_w[8];
_sist_rand(rad_w); c3_rand(rad_w);
return u3i_words(8, rad_w); return u3i_words(8, rad_w);
} }