1.\" 2.\" Copyright (c) 2002-2015 Mark R V Murray 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.\" 14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 19.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 21.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24.\" SUCH DAMAGE. 25.\" 26.Dd August 26, 2018 27.Dt RANDOM_HARVEST 9 28.Os 29.Sh NAME 30.Nm random_harvest 31.Nd gather entropy from the kernel for the entropy device 32.Sh SYNOPSIS 33.In sys/types.h 34.In sys/random.h 35.Ft void 36.Fo random_harvest_direct 37.Fa "void *entropy" 38.Fa "u_int size" 39.Fa "enum esource source" 40.Fc 41.Ft void 42.Fo random_harvest_fast 43.Fa "void *entropy" 44.Fa "u_int size" 45.Fa "enum esource source" 46.Fc 47.Ft void 48.Fo random_harvest_queue 49.Fa "void *entropy" 50.Fa "u_int size" 51.Fa "enum esource source" 52.Fc 53.Sh DESCRIPTION 54The 55.Fn random_harvest_* 56functions are used by device drivers 57and other kernel processes to pass data 58that is considered (at least partially) stochastic 59to the entropy device. 60.Pp 61The caller should pass 62a pointer pointing to the 63.Dq random 64data in 65.Fa entropy . 66The argument 67.Fa size 68contains the number of bytes pointed to. 69The 70.Fa source 71is chosen from one of 72the values enumerated in 73.Pa sys/dev/random.h . 74and is used to indicate the source of the entropy. 75.Pp 76The 77.Fo random_harvest_direct 78.Fc 79variant is used 80for early harvesting 81before any multitasking 82is enabled. 83.Pp 84The 85.Fn random_harvest_fast 86variant is used 87by sources that 88should not take 89a performance hit 90from harvesting, 91as they are high-rate 92sources. 93Some entropy is sacrificed, 94but the high rate of supply 95will compensate for this. 96.Pp 97The 98.Fn random_harvest_queue 99variant is used 100for general harvesting 101and is the default 102choice for most entropy sources 103such as interrupts 104or console events. 105.Pp 106Interrupt harvesting has been 107in part simplified 108for the kernel programmer. 109If a device driver registers an interrupt handler 110with 111.Xr BUS_SETUP_INTR 9 112or 113.Xr bus_setup_intr 9 , 114then it is only necessary to 115include the 116.Dv INTR_ENTROPY 117bit in the 118.Fa flags 119argument to have that interrupt source 120be used for entropy harvesting. 121This should be done wherever practicable. 122.Sh SEE ALSO 123.Xr random 4 , 124.Xr BUS_SETUP_INTR 9 125.Sh AUTHORS 126The 127.Fx 128.Xr random 4 129entropy device and supporting documentation was written by 130.An Mark R V Murray . 131