ASCON Suite
ascon-select-trng.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 Southern Storm Software, Pty Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef ASCON_SELECT_TRNG_H
24 #define ASCON_SELECT_TRNG_H
25 
26 #if defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) || \
27  defined(__CYGWIN__) || defined(__CYGWIN32__)
28 
29 /* Use the Windows CryptGenRandom() function */
30 #define ASCON_TRNG_WINDOWS 1
31 #define ASCON_TRNG_MIXER 1
32 
33 #elif defined(__linux__) || defined(__APPLE__) || defined(__MACH__) || \
34  defined(__FreeBSD__) || defined(__unix__) || defined(__ANDROID__) || \
35  defined(__OpenBSD__)
36 
37 /* Unix-like system with access to a /dev/urandom or /dev/random device */
38 #define ASCON_TRNG_DEV_RANDOM 1
39 #define ASCON_TRNG_MIXER 1
40 
41 #elif defined(__zephyr__)
42 
43 /* Zephyr RTOS. Use the sys_csrand_get() function if it is
44  * available, or use bt_rand() if Bluetooth is enabled. */
45 #include <zephyr/kernel.h>
46 #if defined(CONFIG_CTR_DRBG_CSPRNG_GENERATOR) || \
47  defined(CONFIG_HARDWARE_DEVICE_CS_GENERATOR)
48 #define ASCON_TRNG_ZEPHYR_CSRAND 1
49 #elif defined(CONFIG_BT)
50 #define ASCON_TRNG_ZEPHYR_BTRAND 1
51 #else
52 /* Zephyr does not have a cryptographically secure RNG enabled */
53 #define ASCON_TRNG_NONE 1
54 #endif
55 #define ASCON_TRNG_MIXER 1
56 
57 #elif defined(USE_HAL_DRIVER)
58 
59 /* STM32 platform with HAL libraries. Detecting the TRNG is complicated. */
60 #include "ascon-trng-stm32.h"
61 
62 #elif defined(__arm__) && defined(__SAM3X8E__) && defined(ARDUINO)
63 
64 /* TRNG on the Arduino Due */
65 #define ASCON_TRNG_DUE 1
66 
67 #elif defined(ESP8266) || defined(ESP32)
68 
69 /* TRNG on ESP8266 and ESP32 modules */
70 #define ASCON_TRNG_ESP 1
71 
72 #else
73 
74 /* No idea how to generate random numbers on this device yet */
75 #define ASCON_TRNG_NONE 1
76 #define ASCON_TRNG_MIXER 1
77 
78 #endif
79 
80 #endif