17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 58047c9fbSmcpowers * Common Development and Distribution License (the "License"). 68047c9fbSmcpowers * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 2273556491SAnthony Scarpino * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 25*6ea3c060SGarrett D'Amore /* 26*6ea3c060SGarrett D'Amore * Copyright 2010 Nexenta Systems, Inc. All rights reserved. 27*6ea3c060SGarrett D'Amore */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #ifndef _SYS_RANDOM_H 307c478bd9Sstevel@tonic-gate #define _SYS_RANDOM_H 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include <sys/types.h> 337c478bd9Sstevel@tonic-gate #include <sys/atomic.h> 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #ifdef __cplusplus 367c478bd9Sstevel@tonic-gate extern "C" { 377c478bd9Sstevel@tonic-gate #endif 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate /* stats for the random number devices, /dev/random and /dev/urandom. */ 407c478bd9Sstevel@tonic-gate typedef struct rnd_stats { 417c478bd9Sstevel@tonic-gate uint64_t rs_rndOut; /* Bytes generated for /dev/random */ 427c478bd9Sstevel@tonic-gate uint64_t rs_rndcOut; /* Bytes read from /dev/random cache */ 437c478bd9Sstevel@tonic-gate uint64_t rs_urndOut; /* Bytes generated for /dev/urandom */ 447c478bd9Sstevel@tonic-gate } rnd_stats_t; 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate /* stats for the kernel random number provider, swrand. */ 477c478bd9Sstevel@tonic-gate typedef struct swrand_stats { 487c478bd9Sstevel@tonic-gate uint32_t ss_entEst; /* Entropy estimate in bits */ 497c478bd9Sstevel@tonic-gate uint64_t ss_entIn; /* Entropy bits added to pool */ 507c478bd9Sstevel@tonic-gate uint64_t ss_entOut; /* Entropy bits extracted from pool */ 517c478bd9Sstevel@tonic-gate uint64_t ss_bytesIn; /* Total data bytes added to pool */ 527c478bd9Sstevel@tonic-gate uint64_t ss_bytesOut; /* Total data bytes extracted from */ 537c478bd9Sstevel@tonic-gate /* the pool */ 547c478bd9Sstevel@tonic-gate } swrand_stats_t; 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate #ifdef _KERNEL 577c478bd9Sstevel@tonic-gate 58fe54a78eSHai-May Chao #define BUMP_CPU_RND_STATS(rm, x, v) (((rm)->rm_mag.rm_stats).x += (v)) 597c478bd9Sstevel@tonic-gate #define BUMP_RND_STATS(x, v) atomic_add_64(&(rnd_stats).x, (v)) 607c478bd9Sstevel@tonic-gate #define BUMP_SWRAND_STATS(x, v) atomic_add_64(&(swrand_stats).x, (v)) 617c478bd9Sstevel@tonic-gate 628047c9fbSmcpowers extern int random_add_entropy(uint8_t *, size_t, uint_t); 637c478bd9Sstevel@tonic-gate extern int random_get_bytes(uint8_t *, size_t); 647c478bd9Sstevel@tonic-gate extern int random_get_pseudo_bytes(uint8_t *, size_t); 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate #ifdef __cplusplus 697c478bd9Sstevel@tonic-gate } 707c478bd9Sstevel@tonic-gate #endif 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate #endif /* _SYS_RANDOM_H */ 73