From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:60431) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Slksq-0007Mc-Mw for qemu-devel@nongnu.org; Mon, 02 Jul 2012 13:58:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Slksn-0007T8-Py for qemu-devel@nongnu.org; Mon, 02 Jul 2012 13:58:00 -0400 Received: from e37.co.us.ibm.com ([32.97.110.158]:43620) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Slksn-0007RW-Gp for qemu-devel@nongnu.org; Mon, 02 Jul 2012 13:57:57 -0400 Received: from /spool/local by e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 2 Jul 2012 11:57:50 -0600 Received: from d03relay03.boulder.ibm.com (d03relay03.boulder.ibm.com [9.17.195.228]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id 810703E4008F for ; Mon, 2 Jul 2012 17:56:31 +0000 (WET) Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by d03relay03.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q62HuQg5203332 for ; Mon, 2 Jul 2012 11:56:28 -0600 Received: from d03av04.boulder.ibm.com (loopback [127.0.0.1]) by d03av04.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q62HuPfA003348 for ; Mon, 2 Jul 2012 11:56:25 -0600 Message-ID: <4FF1E0C8.50705@linux.vnet.ibm.com> Date: Mon, 02 Jul 2012 13:56:24 -0400 From: Stefan Berger MIME-Version: 1.0 References: <4FE240B2.4070907@codemonkey.ws> <20120622110601.GB24801@amit.redhat.com> In-Reply-To: <20120622110601.GB24801@amit.redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v3 1/1] virtio-rng: hardware random number generator device List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Amit Shah Cc: qemu list , Anthony Liguori On 06/22/2012 07:06 AM, Amit Shah wrote: > On (Wed) 20 Jun 2012 [16:29:22], Anthony Liguori wrote: >> On 06/20/2012 01:59 AM, Amit Shah wrote: >>> The Linux kernel already has a virtio-rng driver, this is the device >>> implementation. >>> >>> When the guest asks for entropy from the virtio hwrng, it puts a buffer >>> in the vq. We then put entropy into that buffer, and push it back to >>> the guest. >>> >>> The chardev connected to this device is fed the data to be sent to the >>> guest. >>> >>> Invocation is simple: >>> >>> $ qemu ... -device virtio-rng-pci,chardev=foo >>> >>> In the guest, we see >>> >>> $ cat /sys/devices/virtual/misc/hw_random/rng_available >>> virtio >>> >>> $ cat /sys/devices/virtual/misc/hw_random/rng_current >>> virtio >>> >>> # cat /dev/hwrng >>> >>> Simply feeding /dev/urandom from the host to the chardev is sufficient: >>> >>> $ qemu ... -chardev socket,path=/tmp/foo,server,nowait,id=foo \ >>> -device virtio-rng,chardev=foo >>> >>> $ nc -U /tmp/foo< /dev/urandom >>> >>> A QMP event is sent for interested apps to monitor activity and send the >>> appropriate number of bytes that get asked by the guest: >>> >>> {"timestamp": {"seconds": 1337966878, "microseconds": 517009}, \ >>> "event": "ENTROPY_NEEDED", "data": {"bytes": 64}} >> Nack. >> >> Use a protocol. > How does one write a program on Linux to get random numbers? > > He uses /dev/random, of course. You could also use the nss freebl crypto library that provides a random number generator that for example seeds itself from /dev/urandom and then uses hash operations on the seed before it goes back to getting random numbers from /dev/urandom again. So, another idea: call RNG_GenerateGlobalRandomBytes() to get the entropy. Stefan