NAME
cap_random_buf
—
library for getting entropy in
capability mode
LIBRARY
library “libcap_random”
SYNOPSIS
#include
<sys/nv.h>
#include <libcasper.h>
#include
<casper/cap_random.h>
int
cap_random_buf
(cap_channel_t
*chan, void *buf,
size_t nbytes);
DESCRIPTION
The functioncap_random_buf
()
is equivalent to
arc4random_buf(3) except that the connection to the
system.random
service needs to be provided.
EXAMPLES
The following example first opens a capability to casper and then
uses this capability to create the system.random
casper service to obtain entropy.
cap_channel_t *capcas, *caprandom; unsigned char buf[16]; int i; /* Open capability to Casper. */ capcas = cap_init(); if (capcas == NULL) err(1, "Unable to contact Casper"); /* Enter capability mode sandbox. */ if (cap_enter() < 0 && errno != ENOSYS) err(1, "Unable to enter capability mode"); /* Use Casper capability to create capability to the system.random service. */ caprandom = cap_service_open(capcas, "system.random"); if (caprandom == NULL) err(1, "Unable to open system.random service"); /* Close Casper capability, we don't need it anymore. */ cap_close(capcas); /* Obtain entropy. */ if (cap_random_buf(caprandom, buf, sizeof(buf)) < 0) err(1, "Unable to obtain entropy"); for (i = 0; i < sizeof(buf); i++) printf("%.2x ", buf[i]); printf("\n");
SEE ALSO
AUTHORS
The cap_random
service was implemented by
Pawel Jakub Dawidek
<pawel@dawidek.net>
under sponsorship from the FreeBSD Foundation.
This manual page was written by
Mariusz Zaborski
<oshogbo@FreeBSD.org>.