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 5*1920Smcpowers * Common Development and Distribution License (the "License"). 6*1920Smcpowers * 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*1920Smcpowers * Copyright 2006 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 #pragma ident "%Z%%M% %I% %E% SMI" 300Sstevel@tonic-gate 310Sstevel@tonic-gate #include <sys/types.h> 320Sstevel@tonic-gate #include <sys/atomic.h> 330Sstevel@tonic-gate 340Sstevel@tonic-gate #ifdef __cplusplus 350Sstevel@tonic-gate extern "C" { 360Sstevel@tonic-gate #endif 370Sstevel@tonic-gate 380Sstevel@tonic-gate /* stats for the random number devices, /dev/random and /dev/urandom. */ 390Sstevel@tonic-gate typedef struct rnd_stats { 400Sstevel@tonic-gate uint64_t rs_rndOut; /* Bytes generated for /dev/random */ 410Sstevel@tonic-gate uint64_t rs_rndcOut; /* Bytes read from /dev/random cache */ 420Sstevel@tonic-gate uint64_t rs_urndOut; /* Bytes generated for /dev/urandom */ 430Sstevel@tonic-gate } rnd_stats_t; 440Sstevel@tonic-gate 450Sstevel@tonic-gate /* stats for the kernel random number provider, swrand. */ 460Sstevel@tonic-gate typedef struct swrand_stats { 470Sstevel@tonic-gate uint32_t ss_entEst; /* Entropy estimate in bits */ 480Sstevel@tonic-gate uint64_t ss_entIn; /* Entropy bits added to pool */ 490Sstevel@tonic-gate uint64_t ss_entOut; /* Entropy bits extracted from pool */ 500Sstevel@tonic-gate uint64_t ss_bytesIn; /* Total data bytes added to pool */ 510Sstevel@tonic-gate uint64_t ss_bytesOut; /* Total data bytes extracted from */ 520Sstevel@tonic-gate /* the pool */ 530Sstevel@tonic-gate } swrand_stats_t; 540Sstevel@tonic-gate 550Sstevel@tonic-gate #ifdef _KERNEL 560Sstevel@tonic-gate 570Sstevel@tonic-gate #define BUMP_CPU_RND_STATS(rm, x, v) (((rm)->rm_stats).x += (v)) 580Sstevel@tonic-gate #define BUMP_RND_STATS(x, v) atomic_add_64(&(rnd_stats).x, (v)) 590Sstevel@tonic-gate #define BUMP_SWRAND_STATS(x, v) atomic_add_64(&(swrand_stats).x, (v)) 600Sstevel@tonic-gate 61*1920Smcpowers extern int random_add_entropy(uint8_t *, size_t, uint_t); 620Sstevel@tonic-gate extern int random_get_bytes(uint8_t *, size_t); 630Sstevel@tonic-gate extern int random_get_pseudo_bytes(uint8_t *, size_t); 640Sstevel@tonic-gate 650Sstevel@tonic-gate #endif /* _KERNEL */ 660Sstevel@tonic-gate 670Sstevel@tonic-gate #ifdef __cplusplus 680Sstevel@tonic-gate } 690Sstevel@tonic-gate #endif 700Sstevel@tonic-gate 710Sstevel@tonic-gate #endif /* _SYS_RANDOM_H */ 72