Changeset View
Changeset View
Standalone View
Standalone View
lib/libcasper/services/cap_random/cap_random.c
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
int | int | ||||
cap_random_buf(cap_channel_t *chan, void *buf, size_t nbytes) | cap_random_buf(cap_channel_t *chan, void *buf, size_t nbytes) | ||||
{ | { | ||||
nvlist_t *nvl; | nvlist_t *nvl; | ||||
const void *randbuf; | const void *randbuf; | ||||
uint8_t *ptr; | uint8_t *ptr; | ||||
size_t left, randbufsize; | size_t left, randbufsize; | ||||
if (!cap_enable(chan)) { | |||||
arc4random_buf(buf, nbytes); | |||||
return (0); | |||||
} | |||||
left = nbytes; | left = nbytes; | ||||
ptr = buf; | ptr = buf; | ||||
while (left > 0) { | while (left > 0) { | ||||
nvl = nvlist_create(0); | nvl = nvlist_create(0); | ||||
nvlist_add_string(nvl, "cmd", "generate"); | nvlist_add_string(nvl, "cmd", "generate"); | ||||
nvlist_add_number(nvl, "size", | nvlist_add_number(nvl, "size", | ||||
(uint64_t)(left > MAXSIZE ? MAXSIZE : left)); | (uint64_t)(left > MAXSIZE ? MAXSIZE : left)); | ||||
▲ Show 20 Lines • Show All 54 Lines • Show Last 20 Lines |