xref: /titanic_51/usr/src/uts/common/sys/random.h (revision 06e46062ef4f5f4b687cbafb4518fb123fe23920)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_RANDOM_H
28 #define	_SYS_RANDOM_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <sys/atomic.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 /* stats for the random number devices, /dev/random and /dev/urandom. */
40 typedef struct rnd_stats {
41 	uint64_t	rs_rndOut;	/* Bytes generated for /dev/random */
42 	uint64_t	rs_rndcOut;	/* Bytes read from /dev/random cache */
43 	uint64_t	rs_urndOut;	/* Bytes generated for /dev/urandom */
44 } rnd_stats_t;
45 
46 /* stats for the kernel random number provider, swrand. */
47 typedef struct swrand_stats {
48 	uint32_t	ss_entEst;	/* Entropy estimate in bits */
49 	uint64_t	ss_entIn;	/* Entropy bits added to pool */
50 	uint64_t	ss_entOut;	/* Entropy bits extracted from pool */
51 	uint64_t	ss_bytesIn;	/* Total data bytes added to pool */
52 	uint64_t	ss_bytesOut;	/* Total data bytes extracted from */
53 					/* the pool */
54 } swrand_stats_t;
55 
56 #ifdef	_KERNEL
57 
58 #define	BUMP_CPU_RND_STATS(rm, x, v)    (((rm)->rm_stats).x += (v))
59 #define	BUMP_RND_STATS(x, v)	atomic_add_64(&(rnd_stats).x, (v))
60 #define	BUMP_SWRAND_STATS(x, v)	atomic_add_64(&(swrand_stats).x, (v))
61 
62 extern int random_add_entropy(uint8_t *, size_t, uint16_t);
63 extern int random_get_bytes(uint8_t *, size_t);
64 extern int random_get_pseudo_bytes(uint8_t *, size_t);
65 
66 #endif /* _KERNEL */
67 
68 #ifdef	__cplusplus
69 }
70 #endif
71 
72 #endif /* _SYS_RANDOM_H */
73