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 */ 256ea3c060SGarrett D'Amore /* 269d12795fSRobert Mustacchi * Copyright (c) 2015, Joyent, Inc. 27*b819cea2SGordon Ross * Copyright 2013 Nexenta Systems, Inc. All rights reserved. 286ea3c060SGarrett D'Amore */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #ifndef _SYS_RANDOM_H 317c478bd9Sstevel@tonic-gate #define _SYS_RANDOM_H 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #include <sys/types.h> 347c478bd9Sstevel@tonic-gate #include <sys/atomic.h> 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate #ifdef __cplusplus 377c478bd9Sstevel@tonic-gate extern "C" { 387c478bd9Sstevel@tonic-gate #endif 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate /* stats for the random number devices, /dev/random and /dev/urandom. */ 417c478bd9Sstevel@tonic-gate typedef struct rnd_stats { 427c478bd9Sstevel@tonic-gate uint64_t rs_rndOut; /* Bytes generated for /dev/random */ 437c478bd9Sstevel@tonic-gate uint64_t rs_rndcOut; /* Bytes read from /dev/random cache */ 447c478bd9Sstevel@tonic-gate uint64_t rs_urndOut; /* Bytes generated for /dev/urandom */ 457c478bd9Sstevel@tonic-gate } rnd_stats_t; 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate /* stats for the kernel random number provider, swrand. */ 487c478bd9Sstevel@tonic-gate typedef struct swrand_stats { 497c478bd9Sstevel@tonic-gate uint32_t ss_entEst; /* Entropy estimate in bits */ 507c478bd9Sstevel@tonic-gate uint64_t ss_entIn; /* Entropy bits added to pool */ 517c478bd9Sstevel@tonic-gate uint64_t ss_entOut; /* Entropy bits extracted from pool */ 527c478bd9Sstevel@tonic-gate uint64_t ss_bytesIn; /* Total data bytes added to pool */ 537c478bd9Sstevel@tonic-gate uint64_t ss_bytesOut; /* Total data bytes extracted from */ 547c478bd9Sstevel@tonic-gate /* the pool */ 557c478bd9Sstevel@tonic-gate } swrand_stats_t; 567c478bd9Sstevel@tonic-gate 57*b819cea2SGordon Ross #if defined(_KERNEL) || defined(_FAKE_KERNEL) 587c478bd9Sstevel@tonic-gate 59fe54a78eSHai-May Chao #define BUMP_CPU_RND_STATS(rm, x, v) (((rm)->rm_mag.rm_stats).x += (v)) 607c478bd9Sstevel@tonic-gate #define BUMP_RND_STATS(x, v) atomic_add_64(&(rnd_stats).x, (v)) 617c478bd9Sstevel@tonic-gate #define BUMP_SWRAND_STATS(x, v) atomic_add_64(&(swrand_stats).x, (v)) 627c478bd9Sstevel@tonic-gate 638047c9fbSmcpowers extern int random_add_entropy(uint8_t *, size_t, uint_t); 647c478bd9Sstevel@tonic-gate extern int random_get_bytes(uint8_t *, size_t); 659d12795fSRobert Mustacchi extern int random_get_blocking_bytes(uint8_t *, size_t); 667c478bd9Sstevel@tonic-gate extern int random_get_pseudo_bytes(uint8_t *, size_t); 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 697c478bd9Sstevel@tonic-gate 709d12795fSRobert Mustacchi /* 719d12795fSRobert Mustacchi * Flags for the getrandom system call. Note, we may want to move these 729d12795fSRobert Mustacchi * definitions if we expose getrandom(2) into a public system call. 739d12795fSRobert Mustacchi */ 749d12795fSRobert Mustacchi #define GRND_NONBLOCK 0x0001 /* O_NONBLOCK equiv */ 759d12795fSRobert Mustacchi #define GRND_RANDOM 0x0002 /* Use /dev/random, not /dev/urandom */ 769d12795fSRobert Mustacchi extern int getrandom(void *, size_t, int); 779d12795fSRobert Mustacchi 787c478bd9Sstevel@tonic-gate #ifdef __cplusplus 797c478bd9Sstevel@tonic-gate } 807c478bd9Sstevel@tonic-gate #endif 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate #endif /* _SYS_RANDOM_H */ 83