1 /* $MirOS: contrib/hosted/fwcf/sys_bsd.c,v 1.4 2007/03/13 18:14:30 tg Exp $ */
4 * Copyright (c) 2006, 2007
5 * Thorsten Glaser <tg@mirbsd.de>
7 * Provided that these terms and disclaimer and all copyright notices
8 * are retained or reproduced in an accompanying document, permission
9 * is granted to deal in this work without restriction, including un-
10 * limited rights to use, publicly perform, distribute, sell, modify,
11 * merge, give away, or sublicence.
13 * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
14 * the utmost extent permitted by applicable law, neither express nor
15 * implied; without malicious intent or gross negligence. In no event
16 * may a licensor, author or contributor be held liable for indirect,
17 * direct, other damage, loss, or other issues arising in any way out
18 * of dealing in the work, even if advised of the possibility of such
19 * damage or existence of a defect, except proven that it results out
20 * of said person's immediate fault when using the work as intended.
30 __RCSID("$MirOS: contrib/hosted/fwcf/sys_bsd.c,v 1.4 2007/03/13 18:14:30 tg Exp $");
33 pull_rndata(uint8_t *buf
, size_t n
)
41 fprintf(stderr
, "writing %ld bytes of entropy\n", n
);
46 *(uint32_t *)buf
= arc4random();
57 *buf
++ = arc4random() & 0xFF;
68 push_rndata(uint8_t *buf
, size_t n
)
74 arc4random_pushb(buf
, n
);
79 arc4random_addrandom(buf
, n
);
81 if ((fd
= open("/dev/arandom", O_WRONLY
)) >= 0) {
85 warn("cannot write to /dev/arandom");
88 printf("reading %ld bytes of entropy\n", n
);
89 for (i
= 0; i
< n
; ++i
) {
90 printf(" %02X", buf
[i
]);