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.\" $FreeBSD$ 27.\" 28.Dd July 13, 2015 29.Dt RANDOM_HARVEST 9 30.Os 31.Sh NAME 32.Nm random_harvest 33.Nd gather entropy from the kernel for the entropy device 34.Sh SYNOPSIS 35.In sys/types.h 36.In sys/random.h 37.Ft void 38.Fo random_harvest_direct 39.Fa "void *entropy" 40.Fa "u_int size" 41.Fa "u_int bits" 42.Fa "enum esource source" 43.Fc 44.Ft void 45.Fo random_harvest_fast 46.Fa "void *entropy" 47.Fa "u_int size" 48.Fa "u_int bits" 49.Fa "enum esource source" 50.Fc 51.Ft void 52.Fo random_harvest_queue 53.Fa "void *entropy" 54.Fa "u_int size" 55.Fa "u_int bits" 56.Fa "enum esource source" 57.Fc 58.Sh DESCRIPTION 59The 60.Fn random_harvest_* 61functions are used by device drivers 62and other kernel processes to pass data 63that is considered (at least partially) stochastic 64to the entropy device. 65.Pp 66The caller should pass 67a pointer pointing to the 68.Dq random 69data in 70.Fa entropy . 71The argument 72.Fa size 73contains the number of bytes pointed to. 74The 75.Fa source 76is chosen from one of 77the values enumerated in 78.Pa sys/dev/random.h . 79and is used to indicate the source of the entropy. 80.Pp 81The 82.Fo random_harvest_direct 83.Fc 84variant is used 85for early harvesting 86before any multitasking 87is enabled. 88.Pp 89The 90.Fn random_harvest_fast 91variant is used 92by sources that 93should not take 94a performance hit 95from harvesting, 96as they are high-rate 97sources. 98Some entropy is sacrificed, 99but the high rate of supply 100will compensate for this. 101.Pp 102The 103.Fn random_harvest_queue 104variant is used 105for general harvesting 106and is the default 107choice for most entropy sources 108such as interrupts 109or console events. 110.Pp 111The 112.Fa bits 113argument is only used 114by the deprecated Yarrow algorithm. 115For compatibility, 116the caller should 117.Em "very conservatively" 118estimate the number of random bits 119in the sample, 120and pass this in 121.Fa bits . 122.Pp 123Interrupt harvesting has been 124in part simplified 125for the kernel programmer. 126If a device driver registers an interrupt handler 127with 128.Xr BUS_SETUP_INTR 9 129or 130.Xr bus_setup_intr 9 , 131then it is only necessary to 132include the 133.Dv INTR_ENTROPY 134bit in the 135.Fa flags 136argument to have that interrupt source 137be used for entropy harvesting. 138This should be done wherever practicable. 139.Sh SEE ALSO 140.Xr random 4 , 141.Xr BUS_SETUP_INTR 9 142.Sh AUTHORS 143The 144.Fx 145.Xr random 4 146entropy device and supporting documentation was written by 147.An Mark R V Murray . 148