man.bsd.lv manual page server

Manual Page Search Parameters

CAP_RANDOM(3) Library Functions Manual CAP_RANDOM(3)

cap_random_buflibrary for getting entropy in capability mode

library “libcap_random”

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

The function () is equivalent to arc4random_buf(3) except that the connection to the system.random service needs to be provided.

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

cap_enter(2), arc4random_buf(3), err(3), capsicum(4), nv(9)

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>.

February 26, 2018 FreeBSD-12.0