summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/arc4random/getentropy_freebsd.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lib/libcrypto/arc4random/getentropy_freebsd.c60
1 files changed, 0 insertions, 60 deletions
diff --git a/src/lib/libcrypto/arc4random/getentropy_freebsd.c b/src/lib/libcrypto/arc4random/getentropy_freebsd.c
deleted file mode 100644
index ea90ffe202..0000000000
--- a/src/lib/libcrypto/arc4random/getentropy_freebsd.c
+++ /dev/null
@@ -1,60 +0,0 @@
1/* $OpenBSD: getentropy_freebsd.c,v 1.4 2020/10/12 22:08:33 deraadt Exp $ */
2
3/*
4 * Copyright (c) 2014 Pawel Jakub Dawidek <pjd@FreeBSD.org>
5 * Copyright (c) 2014 Brent Cook <bcook@openbsd.org>
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 *
19 * Emulation of getentropy(2) as documented at:
20 * http://man.openbsd.org/getentropy.2
21 */
22
23#include <sys/types.h>
24#include <sys/sysctl.h>
25
26#include <errno.h>
27#include <stddef.h>
28
29/*
30 * Derived from lib/libc/gen/arc4random.c from FreeBSD.
31 */
32static size_t
33getentropy_sysctl(u_char *buf, size_t size)
34{
35 const int mib[2] = { CTL_KERN, KERN_ARND };
36 size_t len, done;
37
38 done = 0;
39
40 do {
41 len = size;
42 if (sysctl(mib, 2, buf, &len, NULL, 0) == -1)
43 return (done);
44 done += len;
45 buf += len;
46 size -= len;
47 } while (size > 0);
48
49 return (done);
50}
51
52int
53getentropy(void *buf, size_t len)
54{
55 if (len <= 256 && getentropy_sysctl(buf, len) == len)
56 return (0);
57
58 errno = EIO;
59 return (-1);
60}