xref: /unit/src/nxt_random.h (revision 0:a63ceefd6ab0)
1 
2 /*
3  * Copyright (C) Igor Sysoev
4  * Copyright (C) NGINX, Inc.
5  */
6 
7 #ifndef _NXT_RANDOM_H_INCLUDED_
8 #define _NXT_RANDOM_H_INCLUDED_
9 
10 
11 #if (NXT_HAVE_ARC4RANDOM)
12 
13 /*
14  * arc4random() has been introduced in OpenBSD 2.1 and then was ported
15  * to FreeBSD 2.2.6, NetBSD 2.0, MacOSX and SmartOS.
16  *
17  * arc4random() automatically initializes itself in the first call and
18  * then reinitializes itself in the first call in every forked processes.
19  */
20 
21 typedef void  *nxt_random_t;
22 
23 
24 #define nxt_random_init(r)
25 #define nxt_random(r)       arc4random()
26 
27 #else
28 
29 typedef struct {
30     uint8_t  i;
31     uint8_t  j;
32     uint8_t  s[256];
33     int32_t  count;
34 } nxt_random_t;
35 
36 
37 void nxt_random_init(nxt_random_t *r);
38 uint32_t nxt_random(nxt_random_t *r);
39 
40 #if (NXT_LIB_UNIT_TEST)
41 nxt_int_t nxt_random_unit_test(nxt_thread_t *thr);
42 #endif
43 
44 #endif
45 
46 
47 #endif /* _NXT_RANDOM_H_INCLUDED_ */
48