static void _rs_random_buf(void *_buf, size_t n) { unsigned char *buf = (unsigned char *)_buf; size_t m; _rs_stir_if_needed(n); while (n > 0) { if (rs_have > 0) { if (n < rs_have) { m = n; } else { m = rs_have; } memcpy(buf, rs_buf + RSBUFSZ - rs_have, m); pure_memzero(rs_buf + RSBUFSZ - rs_have, m); buf += m; n -= m; rs_have -= m; } if (rs_have == 0) { _rs_rekey(NULL, 0); } } }
void arc4random_addrandom(unsigned char *dat, int datlen) { _ARC4_LOCK(); _rs_stir_if_needed(datlen); _rs_rekey(dat, datlen); _ARC4_UNLOCK(); }
static inline void _rs_random_u32(crypto_uint4 *val) { _rs_stir_if_needed(sizeof(*val)); if (rs_have < sizeof(*val)) { _rs_rekey(NULL, 0); } memcpy(val, rs_buf + RSBUFSZ - rs_have, sizeof(*val)); pure_memzero(rs_buf + RSBUFSZ - rs_have, sizeof(*val)); rs_have -= sizeof(*val); }
static inline void _rs_random_u32(uint32_t *val) { _rs_stir_if_needed(sizeof(*val)); if (rs_have < sizeof(*val)) _rs_rekey(NULL, 0); memcpy(val, rs_buf + RSBUFSZ - rs_have, sizeof(*val)); memset(rs_buf + RSBUFSZ - rs_have, 0, sizeof(*val)); rs_have -= sizeof(*val); return; }
static inline void _rs_random_u32(uint32_t *val) { u_char *keystream; _rs_stir_if_needed(sizeof(*val)); if (rs->rs_have < sizeof(*val)) _rs_rekey(NULL, 0); keystream = rsx->rs_buf + sizeof(rsx->rs_buf) - rs->rs_have; memcpy(val, keystream, sizeof(*val)); memset(keystream, 0, sizeof(*val)); rs->rs_have -= sizeof(*val); }
static inline void _rs_random_buf(void *_buf, size_t n) { unsigned char *buf = (unsigned char *)_buf; size_t m; _rs_stir_if_needed(n); while (n > 0) { if (rs_have > 0) { m = MIN(n, rs_have); memcpy(buf, rs_buf + RSBUFSZ - rs_have, m); memset(rs_buf + RSBUFSZ - rs_have, 0, m); buf += m; n -= m; rs_have -= m; } if (rs_have == 0) _rs_rekey(NULL, 0); } }
static inline void _rs_random_buf(void *_buf, size_t n) { u_char *buf = (u_char *)_buf; u_char *keystream; size_t m; _rs_stir_if_needed(n); while (n > 0) { if (rs->rs_have > 0) { m = arc4_min(n, rs->rs_have); keystream = rsx->rs_buf + sizeof(rsx->rs_buf) - rs->rs_have; memcpy(buf, keystream, m); memset(keystream, 0, m); buf += m; n -= m; rs->rs_have -= m; } if (rs->rs_have == 0) _rs_rekey(NULL, 0); } }