xref: /titanic_51/usr/src/uts/common/sys/random.h (revision 48bc00d6814e04ff3edb32cafe7d1bc580baff68)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_RANDOM_H
27 #define	_SYS_RANDOM_H
28 
29 #include <sys/types.h>
30 #include <sys/atomic.h>
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 /* stats for the random number devices, /dev/random and /dev/urandom. */
37 typedef struct rnd_stats {
38 	uint64_t	rs_rndOut;	/* Bytes generated for /dev/random */
39 	uint64_t	rs_rndcOut;	/* Bytes read from /dev/random cache */
40 	uint64_t	rs_urndOut;	/* Bytes generated for /dev/urandom */
41 } rnd_stats_t;
42 
43 /* stats for the kernel random number provider, swrand. */
44 typedef struct swrand_stats {
45 	uint32_t	ss_entEst;	/* Entropy estimate in bits */
46 	uint64_t	ss_entIn;	/* Entropy bits added to pool */
47 	uint64_t	ss_entOut;	/* Entropy bits extracted from pool */
48 	uint64_t	ss_bytesIn;	/* Total data bytes added to pool */
49 	uint64_t	ss_bytesOut;	/* Total data bytes extracted from */
50 					/* the pool */
51 } swrand_stats_t;
52 
53 #ifdef	_KERNEL
54 
55 #define	BUMP_CPU_RND_STATS(rm, x, v)    (((rm)->rm_mag.rm_stats).x += (v))
56 #define	BUMP_RND_STATS(x, v)	atomic_add_64(&(rnd_stats).x, (v))
57 #define	BUMP_SWRAND_STATS(x, v)	atomic_add_64(&(swrand_stats).x, (v))
58 
59 extern int random_add_entropy(uint8_t *, size_t, uint_t);
60 extern int random_get_bytes(uint8_t *, size_t);
61 extern int random_get_pseudo_bytes(uint8_t *, size_t);
62 
63 /*
64  * Functions for FIPS 140 validated random. Thesse functions should not be used
65  * for early booting kernel modules as modules in a FIPS 140 boundary must wait
66  * until the SMF service "cryptosvc" to run.
67  */
68 extern int random_get_bytes_fips140(uint8_t *, size_t);
69 extern int random_get_pseudo_bytes_fips140(uint8_t *, size_t);
70 
71 #endif /* _KERNEL */
72 
73 #ifdef	__cplusplus
74 }
75 #endif
76 
77 #endif /* _SYS_RANDOM_H */
78