Page MenuHomeFreeBSD

D3053.id6871.diff
No OneTemporary

D3053.id6871.diff

Index: share/man/man9/random.9
===================================================================
--- share/man/man9/random.9
+++ share/man/man9/random.9
@@ -26,7 +26,7 @@
.\"
.\" $FreeBSD$
.\" "
-.Dd June 30, 2015
+.Dd July 12, 2015
.Dt RANDOM 9
.Os
.Sh NAME
@@ -34,6 +34,7 @@
.Nm arc4random ,
.Nm random ,
.Nm read_random ,
+.Nm read_random_uio ,
.Nm srandom
.Nd supply pseudo-random numbers
.Sh SYNOPSIS
@@ -50,6 +51,8 @@
.In sys/random.h
.Ft int
.Fn read_random "void *buffer" "int count"
+.Ft int
+.Fn read_random_uio "struct uio *uio" "int flags"
.Sh DESCRIPTION
The
.Fn random
@@ -117,11 +120,26 @@
that no entropy
has been returned.
.Pp
+The
+.Fn read_random_uio
+function behaves identical to
+.Xr read 2
+on
+.Pa /dev/random .
+The
+.Fa uio
+argument points to a buffer where random data should be stored.
+If the random device is unseeded, this function shall block, unless the
+.Fa flags
+argument is equal to
+.Dv O_NONBLOCK .
+.Pp
All the bits returned by
.Fn random ,
-.Fn arc4rand
-and
+.Fn arc4rand ,
.Fn read_random
+and
+.Fn read_random_uio
are usable.
For example,
.Sq Li random()&01
@@ -168,6 +186,11 @@
function returns
the number of bytes placed in
.Fa buffer .
+.Pp
+If successful, the
+.Fn read_random_uio
+function returns zero.
+It returns an error number on failure.
.Sh AUTHORS
.An Dan Moschuk
wrote
Index: sys/compat/cloudabi/cloudabi_random.c
===================================================================
--- sys/compat/cloudabi/cloudabi_random.c
+++ sys/compat/cloudabi/cloudabi_random.c
@@ -26,13 +26,28 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <sys/types.h>
+#include <sys/random.h>
+#include <sys/uio.h>
+
#include <compat/cloudabi/cloudabi_proto.h>
int
cloudabi_sys_random_get(struct thread *td,
struct cloudabi_sys_random_get_args *uap)
{
+ struct iovec iov = {
+ .iov_base = uap->buf,
+ .iov_len = uap->nbyte
+ };
+ struct uio uio = {
+ .uio_iov = &iov,
+ .uio_iovcnt = 1,
+ .uio_resid = iov.iov_len,
+ .uio_segflg = UIO_USERSPACE,
+ .uio_rw = UIO_READ,
+ .uio_td = td
+ };
- /* Not implemented. */
- return (ENOSYS);
+ return (read_random_uio(&uio, 0));
}
Index: sys/dev/random/randomdev.c
===================================================================
--- sys/dev/random/randomdev.c
+++ sys/dev/random/randomdev.c
@@ -134,6 +134,13 @@
static int
randomdev_read(struct cdev *dev __unused, struct uio *uio, int flags)
{
+
+ return (read_random_uio(uio, flags));
+}
+
+int
+read_random_uio(struct uio *uio, int flags)
+{
uint8_t *random_buf;
int c, error;
ssize_t nbytes;
Index: sys/sys/random.h
===================================================================
--- sys/sys/random.h
+++ sys/sys/random.h
@@ -31,7 +31,10 @@
#ifdef _KERNEL
+struct uio;
+
u_int read_random(void *, u_int);
+int read_random_uio(struct uio *, int);
/*
* Note: if you add or remove members of random_entropy_source, remember to also update the

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 15, 4:47 AM (6 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
25316093
Default Alt Text
D3053.id6871.diff (2 KB)

Event Timeline