random.9 (5203edcdc553fda6caa1da8826a89b1a02dad1bf) | random.9 (67297998c85fb277917b924283c86d715989d0b5) |
---|---|
1.\" 2.\" Copyright (c) 2000 3.\" The Regents of the University of California. All rights reserved. 4.\" 5.\" All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions --- 16 unchanged lines hidden (view full) --- 25.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26.\" 27.\" $FreeBSD$ 28.\" " 29.Dd September 25, 2000 30.Os 31.Dt RANDOM 9 32.Sh NAME | 1.\" 2.\" Copyright (c) 2000 3.\" The Regents of the University of California. All rights reserved. 4.\" 5.\" All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions --- 16 unchanged lines hidden (view full) --- 25.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26.\" 27.\" $FreeBSD$ 28.\" " 29.Dd September 25, 2000 30.Os 31.Dt RANDOM 9 32.Sh NAME |
33.Nm arc4rand , 34.Nm arc4random , 35.Nm random , 36.Nm read_random , 37.Nm srandom 38.Nd supply pseudo-random numbers | 33.Nm srandom, 34.Nm random, 35.Nm arc4random, 36.Nm read_random 37.Nd supply pseudo-random numbers. |
39.Sh SYNOPSIS | 38.Sh SYNOPSIS |
40.In sys/libkern.h | 39.Fd #include <sys/libkern.h> |
41.Ft void 42.Fn srandom "u_long seed" 43.Ft u_long 44.Fn random "void" | 40.Ft void 41.Fn srandom "u_long seed" 42.Ft u_long 43.Fn random "void" |
45.Ft void 46.Fn arc4rand "void *ptr" "u_int length" "int reseed" | |
47.Ft u_int32_t 48.Fn arc4random "void" 49.Pp | 44.Ft u_int32_t 45.Fn arc4random "void" 46.Pp |
50.In sys/random.h 51.Ft int 52.Fn read_random "void *buffer" "int count" | 47.Fd #include <sys/random.h> 48.Ft u_int 49.Fn read_random "void *buffer" "u_int count" |
53.Sh DESCRIPTION 54The 55.Fn random 56function will by default produce a sequence of numbers that can be duplicated 57by calling 58.Fn srandom | 50.Sh DESCRIPTION 51The 52.Fn random 53function will by default produce a sequence of numbers that can be duplicated 54by calling 55.Fn srandom |
59with | 56with |
60.Ql 1 61as the | 57.Ql 1 58as the |
62.Fa seed . | 59.Ar seed . |
63The 64.Fn srandom 65function may be called with any arbitrary | 60The 61.Fn srandom 62function may be called with any arbitrary |
66.Fa seed 67value to get slightly more unpredictable numbers. | 63.Ar seed 64value to get slightly more unpredictable numbers. |
68It is important to remember that the 69.Fn random 70function is entirely predictable, and is therefore not of use where 71knowledge of the sequence of numbers may be of benefit to an attacker. 72.Pp 73The | 65It is important to remember that the 66.Fn random 67function is entirely predictable, and is therefore not of use where 68knowledge of the sequence of numbers may be of benefit to an attacker. 69.Pp 70The |
74.Fn arc4rand | 71.Fn arc4random |
75function will return very good quality random numbers, slightly better 76suited for security-related purposes. 77The random numbers from | 72function will return very good quality random numbers, slightly better 73suited for security-related purposes. 74The random numbers from |
78.Fn arc4rand | 75.Fn arc4random |
79are seeded from the entropy device if it is available. | 76are seeded from the entropy device if it is available. |
80Automatic reseeds happen after a certain timeinterval and after a 81certain number of bytes have been delivered. 82A forced reseed can be forced by passing a non-zero value in the 83.Fa reseed 84argument. | |
85.Pp 86The 87.Fn read_random 88function is used to return entropy directly from the entropy device | 77.Pp 78The 79.Fn read_random 80function is used to return entropy directly from the entropy device |
89if it has been loaded. 90If the entropy device is not loaded, then | 81if it has been loaded. If the entropy device is not loaded, then |
91the | 82the |
92.Fa buffer | 83.Ar buffer |
93is filled with output generated by 94.Fn random . 95The | 84is filled with output generated by 85.Fn random . 86The |
96.Fa buffer | 87.Ar buffer |
97is filled with no more than | 88is filled with no more than |
98.Fa count 99bytes. 100It is advised that | 89.Ar count 90bytes. It is advised that |
101.Fn read_random 102is not used; instead use | 91.Fn read_random 92is not used; instead use |
103.Fn arc4rand | 93.Fn arc4random . |
104.Pp 105All the bits generated by 106.Fn random , | 94.Pp 95All the bits generated by 96.Fn random , |
107.Fn arc4rand | 97.Fn arc4random |
108and 109.Fn read_random | 98and 99.Fn read_random |
110are usable. 111For example, | 100are usable. For example, |
112.Sq Li random()&01 113will produce a random binary value. | 101.Sq Li random()&01 102will produce a random binary value. |
114.Pp 115The 116.Fn arc4random 117is a convenience function which calls 118.Fn arc4rand 119to return a 32 bit pseudo-random integer. | |
120.Sh RETURN VALUES 121The 122.Fn random 123function 124uses a non-linear additive feedback random number generator employing a 125default table of size 31 long integers to return successive pseudo-random 126numbers in the range from 0 to 127.if t 2\u\s731\s10\d\(mi1. 128.if n (2**31)\(mi1. 129The period of this random number generator is very large, approximately 130.if t 16\(mu(2\u\s731\s10\d\(mi1). 131.if n 16*((2**31)\(mi1). 132.Pp 133The | 103.Sh RETURN VALUES 104The 105.Fn random 106function 107uses a non-linear additive feedback random number generator employing a 108default table of size 31 long integers to return successive pseudo-random 109numbers in the range from 0 to 110.if t 2\u\s731\s10\d\(mi1. 111.if n (2**31)\(mi1. 112The period of this random number generator is very large, approximately 113.if t 16\(mu(2\u\s731\s10\d\(mi1). 114.if n 16*((2**31)\(mi1). 115.Pp 116The |
134.Fn arc4rand 135function uses the RC4 algorithm to generate successive pseudo-random 136bytes. 137The | |
138.Fn arc4random 139function | 117.Fn arc4random 118function |
140uses 141.Fn arc4rand 142to generate pseudo-random numbers in the range from 0 to | 119uses the RC4 algorithm to generate successive pseudo-random 120numbers in the range from 0 to |
143.if t 2\u\s732\s10\d\(mi1. 144.if n (2**32)\(mi1. 145.Pp 146The 147.Fn read_random 148function returns the number of bytes placed in | 121.if t 2\u\s732\s10\d\(mi1. 122.if n (2**32)\(mi1. 123.Pp 124The 125.Fn read_random 126function returns the number of bytes placed in |
149.Fa buffer . | 127.Ar buffer . 128.Pp |
150.Sh AUTHORS 151.An Dan Moschuk 152wrote 153.Fn arc4random . 154.An Mark R V Murray 155wrote 156.Fn read_random . | 129.Sh AUTHORS 130.An Dan Moschuk 131wrote 132.Fn arc4random . 133.An Mark R V Murray 134wrote 135.Fn read_random . |