Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
CAP_RANDOM(3)		 BSD Library Functions Manual		 CAP_RANDOM(3)

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 function cap_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 en-
     tropy.

     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
     cap_enter(2), arc4random_buf(3), err(3), capsicum(4), nv(9)

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

BSD			       February	26, 2018			   BSD

NAME | LIBRARY | SYNOPSIS | DESCRIPTION | EXAMPLES | SEE ALSO | AUTHORS

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=cap_random&sektion=3&manpath=FreeBSD+12.0-RELEASE+and+Ports>

home | help