1 /*
   2  * This file and its contents are supplied under the terms of the
   3  * Common Development and Distribution License ("CDDL"), version 1.0.
   4  * You may only use this file in accordance with the terms of version
   5  * 1.0 of the CDDL.
   6  *
   7  * A full copy of the text of the CDDL should have accompanied this
   8  * source.  A copy of the CDDL is also available via the Internet at
   9  * http://www.illumos.org/license/CDDL.
  10  */
  11 
  12 /*
  13  * Copyright 2014 Jason King.  All rights reserved.
  14  */
  15 
  16 #ifndef _RANDOM_H
  17 #define _RANDOM_H
  18 
  19 #ifdef __cplusplus
  20 extern "C" {
  21 #endif
  22 
  23 #include <inttypes.h>
  24 
  25 extern void random_init(void);
  26 extern void random_high(void *, size_t);
  27 extern void random_low(void *, size_t);
  28 extern uint64_t random_high_64(void);
  29 extern uint64_t random_low_64(void);
  30 
  31 inline uint32_t
  32 random_high_32(void)
  33 {
  34         return ((uint32_t)random_high_64() & (uint64_t)0xffffffff);
  35 }
  36 
  37 inline uint16_t
  38 random_high_16(void)
  39 {
  40         return ((uint16_t)random_high_64() & (uint64_t)0xffff);
  41 }
  42 
  43 inline uint8_t
  44 random_high_8(void)
  45 {
  46         return ((uint8_t)random_high_8() & (uint64_t)0xff);
  47 }
  48 
  49 inline uint32_t
  50 random_low_32(void)
  51 {
  52         return ((uint32_t)random_low_64() & (uint64_t)0xffffffff);
  53 }
  54 
  55 inline uint16_t
  56 random_low_16(void)
  57 {
  58         return ((uint16_t)random_low_64() & (uint64_t)0xffff);
  59 }
  60 
  61 inline uint8_t
  62 random_low_8(void)
  63 {
  64         return ((uint8_t)random_low_8() & (uint64_t)0xff);
  65 }
  66 
  67 #ifdef __cplusplus
  68 }
  69 #endif
  70 
  71 #endif /* _RANDOM_H */