View | Details | Raw Unified | Return to bug 194204 | Differences between
and this patch

Collapse All | Expand All

(-)b/include/unistd.h (+1 lines)
Lines 581-586 off_t __syscall(quad_t, ...); Link Here
581
int	 undelete(const char *);
581
int	 undelete(const char *);
582
int	 unwhiteout(const char *);
582
int	 unwhiteout(const char *);
583
void	*valloc(size_t);			/* obsoleted by malloc() */
583
void	*valloc(size_t);			/* obsoleted by malloc() */
584
int	 getentropy(void *, size_t);
584
585
585
#ifndef _OPTRESET_DECLARED
586
#ifndef _OPTRESET_DECLARED
586
#define	_OPTRESET_DECLARED
587
#define	_OPTRESET_DECLARED
(-)b/lib/libc/sys/Makefile.inc (+1 lines)
Lines 123-128 MAN+= abort2.2 \ Link Here
123
	fsync.2 \
123
	fsync.2 \
124
	getdirentries.2 \
124
	getdirentries.2 \
125
	getdtablesize.2 \
125
	getdtablesize.2 \
126
	getentropy.2 \
126
	getfh.2 \
127
	getfh.2 \
127
	getfsstat.2 \
128
	getfsstat.2 \
128
	getgid.2 \
129
	getgid.2 \
(-)b/lib/libc/sys/Symbol.map (+3 lines)
Lines 393-398 FBSD_1.3 { Link Here
393
	ffclock_getcounter;
393
	ffclock_getcounter;
394
	ffclock_getestimate;
394
	ffclock_getestimate;
395
	ffclock_setestimate;
395
	ffclock_setestimate;
396
	getentropy;
396
	pipe2;
397
	pipe2;
397
	posix_fadvise;
398
	posix_fadvise;
398
	procctl;
399
	procctl;
Lines 612-617 FBSDprivate_1.0 { Link Here
612
	_getegid;
613
	_getegid;
613
	__sys_getegid;
614
	__sys_getegid;
614
	_geteuid;
615
	_geteuid;
616
	__sys_getentropy;
617
	_getentropy;
615
	__sys_geteuid;
618
	__sys_geteuid;
616
	_getfh;
619
	_getfh;
617
	__sys_getfh;
620
	__sys_getfh;
(-)b/lib/libc/sys/getentropy.2 (+63 lines)
Added Link Here
1
.\"	$OpenBSD: getentropy.2,v 1.6 2014/07/18 18:20:17 deraadt Exp $
2
.\"
3
.\" Copyright (c) 2014 Theo de Raadt
4
.\"
5
.\" Permission to use, copy, modify, and distribute this software for any
6
.\" purpose with or without fee is hereby granted, provided that the above
7
.\" copyright notice and this permission notice appear in all copies.
8
.\"
9
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
.\"
17
.Dd $Mdocdate: July 18 2014 $
18
.Dt GETENTROPY 2
19
.Os
20
.Sh NAME
21
.Nm getentropy
22
.Nd get entropy
23
.Sh SYNOPSIS
24
.Fd #include <unistd.h>
25
.Ft int
26
.Fn getentropy "void *buf" "size_t buflen"
27
.Sh DESCRIPTION
28
.Nm
29
fills a buffer with high-quality entropy, which can be used
30
as input for process-context pseudorandom generators like
31
.Xr arc4random 3 .
32
.Pp
33
The maximum buffer size permitted is 256 bytes.
34
Even if
35
.Va buflen
36
exceeds this.
37
.Pp
38
.Nm
39
is not intended for regular code; please use the
40
.Xr arc4random 3
41
family of functions instead.
42
.Sh RETURN VALUES
43
Upon successful completion, a value of 0 is returned.
44
Otherwise, a value of \-1 is returned and
45
.Va errno
46
is set to indicate the error.
47
.Sh ERRORS
48
.Fn getentropy
49
will succeed unless:
50
.Bl -tag -width Er
51
.It Bq Er EFAULT
52
The
53
.Fa buf
54
parameter points to an
55
invalid address.
56
.El
57
.Sh SEE ALSO
58
.Xr arc4random 3
59
.Sh HISTORY
60
The
61
.Nm
62
function appeared in
63
.Ox 5.6 .
(-)b/sys/compat/freebsd32/syscalls.master (+2 lines)
Lines 1066-1068 Link Here
1066
				    uint32_t id1, uint32_t id2, int com, \
1066
				    uint32_t id1, uint32_t id2, int com, \
1067
				    void *data); }
1067
				    void *data); }
1068
#endif
1068
#endif
1069
545	AUE_NULL	NOPROTO	{ int getentropy(void *ptr, \
1070
				    size_t len); }
(-)b/sys/conf/files (+1 lines)
Lines 3067-3072 kern/sys_pipe.c standard Link Here
3067
kern/sys_procdesc.c		standard
3067
kern/sys_procdesc.c		standard
3068
kern/sys_process.c		standard
3068
kern/sys_process.c		standard
3069
kern/sys_socket.c		standard
3069
kern/sys_socket.c		standard
3070
kern/sys_random.c		standard
3070
kern/syscalls.c			standard
3071
kern/syscalls.c			standard
3071
kern/sysv_ipc.c			standard
3072
kern/sysv_ipc.c			standard
3072
kern/sysv_msg.c			optional sysvmsg
3073
kern/sysv_msg.c			optional sysvmsg
(-)b/sys/kern/sys_random.c (+60 lines)
Added Link Here
1
/*-
2
 * Copyright (c) 2014, by Theo de Raadt
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 * 3. The name of the author may not be used to endorse or promote products
14
 *    derived from this software without specific prior written permission.
15
 *
16
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 *
27
 * $FreeBSD$
28
 */
29
30
#include <sys/cdefs.h>
31
__FBSDID("$FreeBSD$");
32
33
#include <sys/sysent.h>
34
#include <sys/sysproto.h>
35
#include <sys/libkern.h>
36
#include <sys/proc.h>
37
38
#ifndef	_SYS_SYSPROTO_H_
39
struct getentropy_args {
40
	void	*ptr;
41
	size_t	len;
42
};
43
#endif
44
45
int
46
sys_getentropy(struct thread *td, struct getentropy_args *uap)
47
{
48
	char buf[256];
49
	size_t len;
50
	int error;
51
52
	len = MIN(sizeof(buf), uap->len);
53
	arc4rand(buf, len, 1);
54
	if ((error = copyout(buf, uap->ptr, len)) != 0)	
55
		return (error);
56
57
	memset(buf, 0, sizeof(buf));
58
59
	return (0);
60
}
(-)b/sys/kern/syscalls.master (+1 lines)
Lines 980-984 Link Here
980
543	AUE_NULL	NOSTD	{ int aio_mlock(struct aiocb *aiocbp); }
980
543	AUE_NULL	NOSTD	{ int aio_mlock(struct aiocb *aiocbp); }
981
544	AUE_NULL	STD	{ int procctl(idtype_t idtype, id_t id, \
981
544	AUE_NULL	STD	{ int procctl(idtype_t idtype, id_t id, \
982
				    int com, void *data); }
982
				    int com, void *data); }
983
545	AUE_NULL	STD	{ int getentropy(void *ptr, size_t len); }
983
; Please copy any additions and changes to the following compatability tables:
984
; Please copy any additions and changes to the following compatability tables:
984
; sys/compat/freebsd32/syscalls.master
985
; sys/compat/freebsd32/syscalls.master

Return to bug 194204