stevel@tonic-gate | 7c478bd | 2005-06-14 00:00:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * CDDL HEADER START |
| 3 | * |
| 4 | * The contents of this file are subject to the terms of the |
mcpowers | 8047c9f | 2006-05-01 16:17:15 -0700 | [diff] [blame] | 5 | * Common Development and Distribution License (the "License"). |
| 6 | * You may not use this file except in compliance with the License. |
stevel@tonic-gate | 7c478bd | 2005-06-14 00:00:00 -0700 | [diff] [blame] | 7 | * |
| 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
| 9 | * or http://www.opensolaris.org/os/licensing. |
| 10 | * See the License for the specific language governing permissions |
| 11 | * and limitations under the License. |
| 12 | * |
| 13 | * When distributing Covered Code, include this CDDL HEADER in each |
| 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
| 15 | * If applicable, add the following below this CDDL HEADER, with the |
| 16 | * fields enclosed by brackets "[]" replaced with your own identifying |
| 17 | * information: Portions Copyright [yyyy] [name of copyright owner] |
| 18 | * |
| 19 | * CDDL HEADER END |
| 20 | */ |
| 21 | /* |
Anthony Scarpino | 7355649 | 2009-10-07 14:16:17 -0700 | [diff] [blame] | 22 | * Copyright 2009 Sun Microsystems, Inc. All rights reserved. |
stevel@tonic-gate | 7c478bd | 2005-06-14 00:00:00 -0700 | [diff] [blame] | 23 | * Use is subject to license terms. |
| 24 | */ |
Garrett D'Amore | 6ea3c06 | 2010-09-12 10:25:50 -0700 | [diff] [blame] | 25 | /* |
Jason King | de6af22 | 2018-12-13 10:43:17 -0800 | [diff] [blame^] | 26 | * Copyright (c) 2018, Joyent, Inc. |
Gordon Ross | b819cea | 2013-06-17 10:34:00 -0400 | [diff] [blame] | 27 | * Copyright 2013 Nexenta Systems, Inc. All rights reserved. |
Garrett D'Amore | 6ea3c06 | 2010-09-12 10:25:50 -0700 | [diff] [blame] | 28 | */ |
stevel@tonic-gate | 7c478bd | 2005-06-14 00:00:00 -0700 | [diff] [blame] | 29 | |
| 30 | #ifndef _SYS_RANDOM_H |
| 31 | #define _SYS_RANDOM_H |
| 32 | |
stevel@tonic-gate | 7c478bd | 2005-06-14 00:00:00 -0700 | [diff] [blame] | 33 | #include <sys/types.h> |
| 34 | #include <sys/atomic.h> |
| 35 | |
| 36 | #ifdef __cplusplus |
| 37 | extern "C" { |
| 38 | #endif |
| 39 | |
| 40 | /* stats for the random number devices, /dev/random and /dev/urandom. */ |
| 41 | typedef struct rnd_stats { |
| 42 | uint64_t rs_rndOut; /* Bytes generated for /dev/random */ |
| 43 | uint64_t rs_rndcOut; /* Bytes read from /dev/random cache */ |
| 44 | uint64_t rs_urndOut; /* Bytes generated for /dev/urandom */ |
| 45 | } rnd_stats_t; |
| 46 | |
| 47 | /* stats for the kernel random number provider, swrand. */ |
| 48 | typedef struct swrand_stats { |
| 49 | uint32_t ss_entEst; /* Entropy estimate in bits */ |
| 50 | uint64_t ss_entIn; /* Entropy bits added to pool */ |
| 51 | uint64_t ss_entOut; /* Entropy bits extracted from pool */ |
| 52 | uint64_t ss_bytesIn; /* Total data bytes added to pool */ |
| 53 | uint64_t ss_bytesOut; /* Total data bytes extracted from */ |
| 54 | /* the pool */ |
| 55 | } swrand_stats_t; |
| 56 | |
Gordon Ross | b819cea | 2013-06-17 10:34:00 -0400 | [diff] [blame] | 57 | #if defined(_KERNEL) || defined(_FAKE_KERNEL) |
stevel@tonic-gate | 7c478bd | 2005-06-14 00:00:00 -0700 | [diff] [blame] | 58 | |
Hai-May Chao | fe54a78 | 2008-11-06 16:52:01 -0800 | [diff] [blame] | 59 | #define BUMP_CPU_RND_STATS(rm, x, v) (((rm)->rm_mag.rm_stats).x += (v)) |
stevel@tonic-gate | 7c478bd | 2005-06-14 00:00:00 -0700 | [diff] [blame] | 60 | #define BUMP_RND_STATS(x, v) atomic_add_64(&(rnd_stats).x, (v)) |
| 61 | #define BUMP_SWRAND_STATS(x, v) atomic_add_64(&(swrand_stats).x, (v)) |
| 62 | |
mcpowers | 8047c9f | 2006-05-01 16:17:15 -0700 | [diff] [blame] | 63 | extern int random_add_entropy(uint8_t *, size_t, uint_t); |
stevel@tonic-gate | 7c478bd | 2005-06-14 00:00:00 -0700 | [diff] [blame] | 64 | extern int random_get_bytes(uint8_t *, size_t); |
Robert Mustacchi | 9d12795 | 2015-04-07 09:59:42 -0700 | [diff] [blame] | 65 | extern int random_get_blocking_bytes(uint8_t *, size_t); |
stevel@tonic-gate | 7c478bd | 2005-06-14 00:00:00 -0700 | [diff] [blame] | 66 | extern int random_get_pseudo_bytes(uint8_t *, size_t); |
| 67 | |
stevel@tonic-gate | 7c478bd | 2005-06-14 00:00:00 -0700 | [diff] [blame] | 68 | #endif /* _KERNEL */ |
| 69 | |
Robert Mustacchi | 9d12795 | 2015-04-07 09:59:42 -0700 | [diff] [blame] | 70 | /* |
Jason King | de6af22 | 2018-12-13 10:43:17 -0800 | [diff] [blame^] | 71 | * Flags for the getrandom(2) system call. |
Robert Mustacchi | 9d12795 | 2015-04-07 09:59:42 -0700 | [diff] [blame] | 72 | */ |
| 73 | #define GRND_NONBLOCK 0x0001 /* O_NONBLOCK equiv */ |
| 74 | #define GRND_RANDOM 0x0002 /* Use /dev/random, not /dev/urandom */ |
Jason King | de6af22 | 2018-12-13 10:43:17 -0800 | [diff] [blame^] | 75 | extern ssize_t getrandom(void *, size_t, unsigned int); |
Robert Mustacchi | 9d12795 | 2015-04-07 09:59:42 -0700 | [diff] [blame] | 76 | |
stevel@tonic-gate | 7c478bd | 2005-06-14 00:00:00 -0700 | [diff] [blame] | 77 | #ifdef __cplusplus |
| 78 | } |
| 79 | #endif |
| 80 | |
| 81 | #endif /* _SYS_RANDOM_H */ |