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 /* 22*73556491SAnthony Scarpino * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _SYS_RANDOM_H 277c478bd9Sstevel@tonic-gate #define _SYS_RANDOM_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <sys/types.h> 307c478bd9Sstevel@tonic-gate #include <sys/atomic.h> 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #ifdef __cplusplus 337c478bd9Sstevel@tonic-gate extern "C" { 347c478bd9Sstevel@tonic-gate #endif 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate /* stats for the random number devices, /dev/random and /dev/urandom. */ 377c478bd9Sstevel@tonic-gate typedef struct rnd_stats { 387c478bd9Sstevel@tonic-gate uint64_t rs_rndOut; /* Bytes generated for /dev/random */ 397c478bd9Sstevel@tonic-gate uint64_t rs_rndcOut; /* Bytes read from /dev/random cache */ 407c478bd9Sstevel@tonic-gate uint64_t rs_urndOut; /* Bytes generated for /dev/urandom */ 417c478bd9Sstevel@tonic-gate } rnd_stats_t; 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate /* stats for the kernel random number provider, swrand. */ 447c478bd9Sstevel@tonic-gate typedef struct swrand_stats { 457c478bd9Sstevel@tonic-gate uint32_t ss_entEst; /* Entropy estimate in bits */ 467c478bd9Sstevel@tonic-gate uint64_t ss_entIn; /* Entropy bits added to pool */ 477c478bd9Sstevel@tonic-gate uint64_t ss_entOut; /* Entropy bits extracted from pool */ 487c478bd9Sstevel@tonic-gate uint64_t ss_bytesIn; /* Total data bytes added to pool */ 497c478bd9Sstevel@tonic-gate uint64_t ss_bytesOut; /* Total data bytes extracted from */ 507c478bd9Sstevel@tonic-gate /* the pool */ 517c478bd9Sstevel@tonic-gate } swrand_stats_t; 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate #ifdef _KERNEL 547c478bd9Sstevel@tonic-gate 55fe54a78eSHai-May Chao #define BUMP_CPU_RND_STATS(rm, x, v) (((rm)->rm_mag.rm_stats).x += (v)) 567c478bd9Sstevel@tonic-gate #define BUMP_RND_STATS(x, v) atomic_add_64(&(rnd_stats).x, (v)) 577c478bd9Sstevel@tonic-gate #define BUMP_SWRAND_STATS(x, v) atomic_add_64(&(swrand_stats).x, (v)) 587c478bd9Sstevel@tonic-gate 598047c9fbSmcpowers extern int random_add_entropy(uint8_t *, size_t, uint_t); 607c478bd9Sstevel@tonic-gate extern int random_get_bytes(uint8_t *, size_t); 617c478bd9Sstevel@tonic-gate extern int random_get_pseudo_bytes(uint8_t *, size_t); 627c478bd9Sstevel@tonic-gate 63*73556491SAnthony Scarpino /* 64*73556491SAnthony Scarpino * Functions for FIPS 140 validated random. Thesse functions should not be used 65*73556491SAnthony Scarpino * for early booting kernel modules as modules in a FIPS 140 boundary must wait 66*73556491SAnthony Scarpino * until the SMF service "cryptosvc" to run. 67*73556491SAnthony Scarpino */ 68*73556491SAnthony Scarpino extern int random_get_bytes_fips140(uint8_t *, size_t); 69*73556491SAnthony Scarpino extern int random_get_pseudo_bytes_fips140(uint8_t *, size_t); 70*73556491SAnthony Scarpino 717c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate #ifdef __cplusplus 747c478bd9Sstevel@tonic-gate } 757c478bd9Sstevel@tonic-gate #endif 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate #endif /* _SYS_RANDOM_H */ 78