Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
random.h
00001 /* random.h 00002 * 00003 * Copyright (C) 2006-2016 wolfSSL Inc. 00004 * 00005 * This file is part of wolfSSL. 00006 * 00007 * wolfSSL is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * wolfSSL is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 00020 */ 00021 00022 00023 00024 #ifndef WOLF_CRYPT_RANDOM_H 00025 #define WOLF_CRYPT_RANDOM_H 00026 00027 #include <wolfssl/wolfcrypt/types.h> 00028 00029 #ifdef HAVE_FIPS 00030 /* for fips @wc_fips */ 00031 #include <cyassl/ctaocrypt/random.h> 00032 #endif 00033 00034 #ifdef __cplusplus 00035 extern "C" { 00036 #endif 00037 00038 #ifndef HAVE_FIPS /* avoid redefining structs and macros */ 00039 #if defined(WOLFSSL_FORCE_RC4_DRBG) && defined(NO_RC4) 00040 #error Cannot have WOLFSSL_FORCE_RC4_DRBG and NO_RC4 defined. 00041 #endif /* WOLFSSL_FORCE_RC4_DRBG && NO_RC4 */ 00042 #if defined(HAVE_HASHDRBG) || defined(NO_RC4) 00043 #ifdef NO_SHA256 00044 #error "Hash DRBG requires SHA-256." 00045 #endif /* NO_SHA256 */ 00046 00047 #include <wolfssl/wolfcrypt/sha256.h> 00048 #else /* HAVE_HASHDRBG || NO_RC4 */ 00049 #include <wolfssl/wolfcrypt/arc4.h> 00050 #endif /* HAVE_HASHDRBG || NO_RC4 */ 00051 00052 #if defined(USE_WINDOWS_API) 00053 #if defined(_WIN64) 00054 typedef unsigned __int64 ProviderHandle; 00055 /* type HCRYPTPROV, avoid #include <windows.h> */ 00056 #else 00057 typedef unsigned long ProviderHandle; 00058 #endif 00059 #endif 00060 00061 00062 /* OS specific seeder */ 00063 typedef struct OS_Seed { 00064 #if defined(USE_WINDOWS_API) 00065 ProviderHandle handle; 00066 #else 00067 int fd; 00068 #endif 00069 } OS_Seed; 00070 00071 00072 #if (defined(HAVE_HASHDRBG) || defined(NO_RC4)) && !defined(CUSTOM_RAND_GENERATE_BLOCK) 00073 00074 #define DRBG_SEED_LEN (440/8) 00075 00076 00077 struct DRBG; /* Private DRBG state */ 00078 00079 00080 /* Hash-based Deterministic Random Bit Generator */ 00081 typedef struct WC_RNG { 00082 struct DRBG* drbg; 00083 OS_Seed seed; 00084 byte status; 00085 } WC_RNG; 00086 00087 00088 00089 #else /* (HAVE_HASHDRBG || NO_RC4) && !CUSTOM_RAND_GENERATE_BLOCK */ 00090 00091 #define WOLFSSL_RNG_CAVIUM_MAGIC 0xBEEF0004 00092 00093 /* secure Random Number Generator */ 00094 00095 00096 typedef struct WC_RNG { 00097 OS_Seed seed; 00098 #ifndef NO_RC4 00099 Arc4 cipher; 00100 #endif 00101 #ifdef HAVE_CAVIUM 00102 int devId; /* nitrox device id */ 00103 word32 magic; /* using cavium magic */ 00104 #endif 00105 } WC_RNG; 00106 00107 00108 00109 #endif /* (HAVE_HASHDRBG || NO_RC4) && !CUSTOM_RAND_GENERATE_BLOCK */ 00110 #endif /* HAVE_FIPS */ 00111 00112 /* NO_OLD_RNGNAME removes RNG struct name to prevent possible type conflicts, 00113 * can't be used with CTaoCrypt FIPS */ 00114 #if !defined(NO_OLD_RNGNAME) && !defined(HAVE_FIPS) 00115 #define RNG WC_RNG 00116 #endif 00117 00118 WOLFSSL_LOCAL 00119 int wc_GenerateSeed(OS_Seed* os, byte* seed, word32 sz); 00120 00121 #if defined(HAVE_HASHDRBG) || defined(NO_RC4) 00122 00123 #ifdef HAVE_CAVIUM 00124 WOLFSSL_API int wc_InitRngCavium(WC_RNG*, int); 00125 #endif 00126 00127 #endif /* HAVE_HASH_DRBG || NO_RC4 */ 00128 00129 00130 WOLFSSL_API int wc_InitRng(WC_RNG*); 00131 WOLFSSL_API int wc_RNG_GenerateBlock(WC_RNG*, byte*, word32 sz); 00132 WOLFSSL_API int wc_RNG_GenerateByte(WC_RNG*, byte*); 00133 WOLFSSL_API int wc_FreeRng(WC_RNG*); 00134 00135 00136 #if defined(HAVE_HASHDRBG) || defined(NO_RC4) 00137 WOLFSSL_API int wc_RNG_HealthTest(int reseed, 00138 const byte* entropyA, word32 entropyASz, 00139 const byte* entropyB, word32 entropyBSz, 00140 byte* output, word32 outputSz); 00141 #endif /* HAVE_HASHDRBG || NO_RC4 */ 00142 00143 #ifdef __cplusplus 00144 } /* extern "C" */ 00145 #endif 00146 00147 #endif /* WOLF_CRYPT_RANDOM_H */ 00148 00149
Generated on Tue Jul 12 2022 15:55:20 by
1.7.2