10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51920Smcpowers * Common Development and Distribution License (the "License"). 61920Smcpowers * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*10732SAnthony.Scarpino@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _SYS_RANDOM_H 270Sstevel@tonic-gate #define _SYS_RANDOM_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <sys/types.h> 300Sstevel@tonic-gate #include <sys/atomic.h> 310Sstevel@tonic-gate 320Sstevel@tonic-gate #ifdef __cplusplus 330Sstevel@tonic-gate extern "C" { 340Sstevel@tonic-gate #endif 350Sstevel@tonic-gate 360Sstevel@tonic-gate /* stats for the random number devices, /dev/random and /dev/urandom. */ 370Sstevel@tonic-gate typedef struct rnd_stats { 380Sstevel@tonic-gate uint64_t rs_rndOut; /* Bytes generated for /dev/random */ 390Sstevel@tonic-gate uint64_t rs_rndcOut; /* Bytes read from /dev/random cache */ 400Sstevel@tonic-gate uint64_t rs_urndOut; /* Bytes generated for /dev/urandom */ 410Sstevel@tonic-gate } rnd_stats_t; 420Sstevel@tonic-gate 430Sstevel@tonic-gate /* stats for the kernel random number provider, swrand. */ 440Sstevel@tonic-gate typedef struct swrand_stats { 450Sstevel@tonic-gate uint32_t ss_entEst; /* Entropy estimate in bits */ 460Sstevel@tonic-gate uint64_t ss_entIn; /* Entropy bits added to pool */ 470Sstevel@tonic-gate uint64_t ss_entOut; /* Entropy bits extracted from pool */ 480Sstevel@tonic-gate uint64_t ss_bytesIn; /* Total data bytes added to pool */ 490Sstevel@tonic-gate uint64_t ss_bytesOut; /* Total data bytes extracted from */ 500Sstevel@tonic-gate /* the pool */ 510Sstevel@tonic-gate } swrand_stats_t; 520Sstevel@tonic-gate 530Sstevel@tonic-gate #ifdef _KERNEL 540Sstevel@tonic-gate 558029SHai-May.Chao@Sun.COM #define BUMP_CPU_RND_STATS(rm, x, v) (((rm)->rm_mag.rm_stats).x += (v)) 560Sstevel@tonic-gate #define BUMP_RND_STATS(x, v) atomic_add_64(&(rnd_stats).x, (v)) 570Sstevel@tonic-gate #define BUMP_SWRAND_STATS(x, v) atomic_add_64(&(swrand_stats).x, (v)) 580Sstevel@tonic-gate 591920Smcpowers extern int random_add_entropy(uint8_t *, size_t, uint_t); 600Sstevel@tonic-gate extern int random_get_bytes(uint8_t *, size_t); 610Sstevel@tonic-gate extern int random_get_pseudo_bytes(uint8_t *, size_t); 620Sstevel@tonic-gate 63*10732SAnthony.Scarpino@Sun.COM /* 64*10732SAnthony.Scarpino@Sun.COM * Functions for FIPS 140 validated random. Thesse functions should not be used 65*10732SAnthony.Scarpino@Sun.COM * for early booting kernel modules as modules in a FIPS 140 boundary must wait 66*10732SAnthony.Scarpino@Sun.COM * until the SMF service "cryptosvc" to run. 67*10732SAnthony.Scarpino@Sun.COM */ 68*10732SAnthony.Scarpino@Sun.COM extern int random_get_bytes_fips140(uint8_t *, size_t); 69*10732SAnthony.Scarpino@Sun.COM extern int random_get_pseudo_bytes_fips140(uint8_t *, size_t); 70*10732SAnthony.Scarpino@Sun.COM 710Sstevel@tonic-gate #endif /* _KERNEL */ 720Sstevel@tonic-gate 730Sstevel@tonic-gate #ifdef __cplusplus 740Sstevel@tonic-gate } 750Sstevel@tonic-gate #endif 760Sstevel@tonic-gate 770Sstevel@tonic-gate #endif /* _SYS_RANDOM_H */ 78