From owner-svn-src-all@FreeBSD.ORG Wed Apr 1 15:07:35 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id CF788C89; Wed, 1 Apr 2015 15:07:35 +0000 (UTC) Received: from vps1.elischer.org (vps1.elischer.org [204.109.63.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "vps1.elischer.org", Issuer "CA Cert Signing Authority" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 31E54AC3; Wed, 1 Apr 2015 15:07:35 +0000 (UTC) Received: from Julian-MBP3.local (ppp121-45-255-201.lns20.per4.internode.on.net [121.45.255.201]) (authenticated bits=0) by vps1.elischer.org (8.14.9/8.14.9) with ESMTP id t31F7RdS025543 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Wed, 1 Apr 2015 08:07:30 -0700 (PDT) (envelope-from julian@freebsd.org) Message-ID: <551C09A9.1030005@freebsd.org> Date: Wed, 01 Apr 2015 23:07:21 +0800 From: Julian Elischer User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: Andrew Turner , Mateusz Guzik Subject: Re: svn commit: r280955 - in head/sys: modules/notrandom dev/notrandom References: <20150401113628.GA16649@dft-labs.eu> <20150401133114.16e7d7ba@bender> In-Reply-To: <20150401133114.16e7d7ba@bender> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Apr 2015 15:07:35 -0000 On 4/1/15 8:31 PM, Andrew Turner wrote: > On Wed, 1 Apr 2015 13:36:28 +0200 > Mateusz Guzik wrote: > >> Author: mjg >> Date: Wed Apr 1 13:37:00 2015 >> New Revision: 280955 >> URL: https://svnweb.freebsd.org/changeset/base/280955 >> >> Log: >> Add /dev/notrandom >> >> notrandom provides fast and reliable not random numbers. >> >> This was added in an effort to increase feature-compatiblity with >> Solaris 10. >> >> See http://www.brendangregg.com/Specials/notrandom.c for Solaris >> implementation. the not-random write- side code should have a sysctl that decides whether it rejects data that is too random. >> >> Reviewed-by: Bruce Schneier (ok, not really) >> MFC after: 1 week > I've been thinking about adding something similar for some time. I do > have one question, should it accept data for the notrandom number > generator? It would only need to accept up until the first notrandom > number. I was thinking something like the following patch (untested). > > Andrew > > diff --git a/sys/dev/notrandom/notrandom.c > b/sys/dev/notrandom/notrandom.c index c09eaf3..9e5f523 100644 > --- a/sys/dev/notrandom/notrandom.c > +++ b/sys/dev/notrandom/notrandom.c > @@ -41,10 +41,12 @@ static struct cdev *notrandom_dev; > > static d_ioctl_t notrandom_ioctl; > static d_read_t notrandom_read; > +static d_read_t notrandom_write; > > static struct cdevsw notrandom_cdevsw = { > .d_version = D_VERSION, > .d_read = notrandom_read, > + .d_write = notrandom_write, > .d_ioctl = notrandom_ioctl, > .d_name = "notrandom", > .d_flags = D_MMAP_ANON, > @@ -91,6 +93,30 @@ notrandom_read(struct cdev *dev __unused, struct uio > *uio, int flags __unused) > /* ARGSUSED */ > static int > +notrandom_write(struct cdev *dev __unused, struct uio *uio, int flags > __unused) > +{ > + size_t pos; > + ssize_t len; > + int error = 0; > + char buf; > + > + pos = 0; > + while (uio->uio_resid > 0) { > + len = uio->uio_resid; > + error = uiomove(&buf, 1, uio); > + if (error != 0) > + break; > + if (buf != 7) > + return (EIO); > + notrandom_buf[pos++] = buf; > + pos %= sizeof(notrandom_buf); > + } > + > + return (error); > +} > + > +/* ARGSUSED */ > +static int > notrandom_modevent(module_t mod __unused, int type, void *data > __unused) { > int error = 0; > > >