X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/fe8ab488e9161c46dd9885d58fc52996dc0249ff..a39ff7e25e19b3a8c3020042a3872ca9ec9659f1:/bsd/dev/random/randomdev.c?ds=inline diff --git a/bsd/dev/random/randomdev.c b/bsd/dev/random/randomdev.c index 1b96f774c..6482f6094 100644 --- a/bsd/dev/random/randomdev.c +++ b/bsd/dev/random/randomdev.c @@ -2,7 +2,7 @@ * Copyright (c) 1999-2009 Apple, Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ - * + * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in @@ -11,10 +11,10 @@ * unlawful or unlicensed copies of an Apple operating system, or to * circumvent, violate, or enable the circumvention or violation of, any * terms of an Apple operating system software license agreement. - * + * * Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this file. - * + * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, @@ -22,7 +22,7 @@ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. - * + * * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -96,7 +97,7 @@ random_init(void) UID_ROOT, GID_WHEEL, 0666, "random", 0); /* - * also make urandom + * also make urandom * (which is exactly the same thing in our context) */ devfs_make_node(makedev (ret, URANDOM_MINOR), DEVFS_CHAR, @@ -105,7 +106,7 @@ random_init(void) } int -random_ioctl( __unused dev_t dev, u_long cmd, __unused caddr_t data, +random_ioctl( __unused dev_t dev, u_long cmd, __unused caddr_t data, __unused int flag, __unused struct proc *p ) { switch (cmd) { @@ -123,7 +124,7 @@ random_ioctl( __unused dev_t dev, u_long cmd, __unused caddr_t data, * Open the device. Make sure init happened, and make sure the caller is * authorized. */ - + int random_open(__unused dev_t dev, int flags, __unused int devtype, __unused struct proc *p) { @@ -147,7 +148,7 @@ random_open(__unused dev_t dev, int flags, __unused int devtype, __unused struct /* * close the device. */ - + int random_close(__unused dev_t dev, __unused int flags, __unused int mode, __unused struct proc *p) { @@ -187,7 +188,7 @@ random_write (dev_t dev, struct uio *uio, __unused int ioflag) /* * return data to the caller. Results unpredictable. - */ + */ int random_read(__unused dev_t dev, struct uio *uio, __unused int ioflag) { @@ -199,14 +200,14 @@ random_read(__unused dev_t dev, struct uio *uio, __unused int ioflag) int bytesToRead = MIN(bytes_remaining, (user_ssize_t) sizeof(buffer)); read_random(buffer, bytesToRead); - + retCode = uiomove(buffer, bytesToRead, uio); if (retCode != 0) break; - + bytes_remaining = uio_resid(uio); } - + return retCode; } @@ -221,3 +222,21 @@ RandomULong(void) return (buf); } + +int +getentropy(__unused struct proc * p, struct getentropy_args *gap, __unused int * ret) { + user_addr_t user_addr; + uint32_t user_size; + char buffer[256]; + + user_addr = (vm_map_offset_t)gap->buffer; + user_size = gap->size; + /* Can't request more than 256 random bytes + * at once. Complying with openbsd getentropy() + */ + if (user_size > sizeof(buffer)) { + return EINVAL; + } + read_random(buffer, user_size); + return copyout(buffer, user_addr, user_size); +}