wolfSSL SSL/TLS library, support up to TLS1.3

Dependents:   CyaSSL-Twitter-OAuth4Tw Example-client-tls-cert TwitterReader TweetTest ... more

Committer:
wolfSSL
Date:
Fri Jun 26 00:39:20 2015 +0000
Revision:
0:d92f9d21154c
wolfSSL 3.6.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 0:d92f9d21154c 1 /* random.h
wolfSSL 0:d92f9d21154c 2 *
wolfSSL 0:d92f9d21154c 3 * Copyright (C) 2006-2015 wolfSSL Inc.
wolfSSL 0:d92f9d21154c 4 *
wolfSSL 0:d92f9d21154c 5 * This file is part of wolfSSL. (formerly known as CyaSSL)
wolfSSL 0:d92f9d21154c 6 *
wolfSSL 0:d92f9d21154c 7 * wolfSSL is free software; you can redistribute it and/or modify
wolfSSL 0:d92f9d21154c 8 * it under the terms of the GNU General Public License as published by
wolfSSL 0:d92f9d21154c 9 * the Free Software Foundation; either version 2 of the License, or
wolfSSL 0:d92f9d21154c 10 * (at your option) any later version.
wolfSSL 0:d92f9d21154c 11 *
wolfSSL 0:d92f9d21154c 12 * wolfSSL is distributed in the hope that it will be useful,
wolfSSL 0:d92f9d21154c 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wolfSSL 0:d92f9d21154c 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wolfSSL 0:d92f9d21154c 15 * GNU General Public License for more details.
wolfSSL 0:d92f9d21154c 16 *
wolfSSL 0:d92f9d21154c 17 * You should have received a copy of the GNU General Public License
wolfSSL 0:d92f9d21154c 18 * along with this program; if not, write to the Free Software
wolfSSL 0:d92f9d21154c 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
wolfSSL 0:d92f9d21154c 20 */
wolfSSL 0:d92f9d21154c 21
wolfSSL 0:d92f9d21154c 22
wolfSSL 0:d92f9d21154c 23 #ifndef WOLF_CRYPT_RANDOM_H
wolfSSL 0:d92f9d21154c 24 #define WOLF_CRYPT_RANDOM_H
wolfSSL 0:d92f9d21154c 25
wolfSSL 0:d92f9d21154c 26 #include <wolfssl/wolfcrypt/types.h>
wolfSSL 0:d92f9d21154c 27
wolfSSL 0:d92f9d21154c 28 #ifdef HAVE_FIPS
wolfSSL 0:d92f9d21154c 29 /* for fips @wc_fips */
wolfSSL 0:d92f9d21154c 30 #include <cyassl/ctaocrypt/random.h>
wolfSSL 0:d92f9d21154c 31 #endif
wolfSSL 0:d92f9d21154c 32
wolfSSL 0:d92f9d21154c 33 #ifdef __cplusplus
wolfSSL 0:d92f9d21154c 34 extern "C" {
wolfSSL 0:d92f9d21154c 35 #endif
wolfSSL 0:d92f9d21154c 36
wolfSSL 0:d92f9d21154c 37 #ifndef HAVE_FIPS /* avoid redefining structs and macros */
wolfSSL 0:d92f9d21154c 38 #if defined(HAVE_HASHDRBG) || defined(NO_RC4)
wolfSSL 0:d92f9d21154c 39 #ifdef NO_SHA256
wolfSSL 0:d92f9d21154c 40 #error "Hash DRBG requires SHA-256."
wolfSSL 0:d92f9d21154c 41 #endif /* NO_SHA256 */
wolfSSL 0:d92f9d21154c 42
wolfSSL 0:d92f9d21154c 43 #include <wolfssl/wolfcrypt/sha256.h>
wolfSSL 0:d92f9d21154c 44 #else /* HAVE_HASHDRBG || NO_RC4 */
wolfSSL 0:d92f9d21154c 45 #include <wolfssl/wolfcrypt/arc4.h>
wolfSSL 0:d92f9d21154c 46 #endif /* HAVE_HASHDRBG || NO_RC4 */
wolfSSL 0:d92f9d21154c 47
wolfSSL 0:d92f9d21154c 48 #if defined(USE_WINDOWS_API)
wolfSSL 0:d92f9d21154c 49 #if defined(_WIN64)
wolfSSL 0:d92f9d21154c 50 typedef unsigned __int64 ProviderHandle;
wolfSSL 0:d92f9d21154c 51 /* type HCRYPTPROV, avoid #include <windows.h> */
wolfSSL 0:d92f9d21154c 52 #else
wolfSSL 0:d92f9d21154c 53 typedef unsigned long ProviderHandle;
wolfSSL 0:d92f9d21154c 54 #endif
wolfSSL 0:d92f9d21154c 55 #endif
wolfSSL 0:d92f9d21154c 56
wolfSSL 0:d92f9d21154c 57
wolfSSL 0:d92f9d21154c 58 /* OS specific seeder */
wolfSSL 0:d92f9d21154c 59 typedef struct OS_Seed {
wolfSSL 0:d92f9d21154c 60 #if defined(USE_WINDOWS_API)
wolfSSL 0:d92f9d21154c 61 ProviderHandle handle;
wolfSSL 0:d92f9d21154c 62 #else
wolfSSL 0:d92f9d21154c 63 int fd;
wolfSSL 0:d92f9d21154c 64 #endif
wolfSSL 0:d92f9d21154c 65 } OS_Seed;
wolfSSL 0:d92f9d21154c 66
wolfSSL 0:d92f9d21154c 67
wolfSSL 0:d92f9d21154c 68 #if defined(WOLFSSL_MDK_ARM)
wolfSSL 0:d92f9d21154c 69 #undef RNG
wolfSSL 0:d92f9d21154c 70 #define RNG wolfSSL_RNG /* for avoiding name conflict in "stm32f2xx.h" */
wolfSSL 0:d92f9d21154c 71 #endif
wolfSSL 0:d92f9d21154c 72
wolfSSL 0:d92f9d21154c 73
wolfSSL 0:d92f9d21154c 74 #if defined(HAVE_HASHDRBG) || defined(NO_RC4)
wolfSSL 0:d92f9d21154c 75
wolfSSL 0:d92f9d21154c 76
wolfSSL 0:d92f9d21154c 77 #define DRBG_SEED_LEN (440/8)
wolfSSL 0:d92f9d21154c 78
wolfSSL 0:d92f9d21154c 79
wolfSSL 0:d92f9d21154c 80 struct DRBG; /* Private DRBG state */
wolfSSL 0:d92f9d21154c 81
wolfSSL 0:d92f9d21154c 82
wolfSSL 0:d92f9d21154c 83 /* Hash-based Deterministic Random Bit Generator */
wolfSSL 0:d92f9d21154c 84 typedef struct RNG {
wolfSSL 0:d92f9d21154c 85 struct DRBG* drbg;
wolfSSL 0:d92f9d21154c 86 OS_Seed seed;
wolfSSL 0:d92f9d21154c 87 byte status;
wolfSSL 0:d92f9d21154c 88 } RNG;
wolfSSL 0:d92f9d21154c 89
wolfSSL 0:d92f9d21154c 90
wolfSSL 0:d92f9d21154c 91 #else /* HAVE_HASHDRBG || NO_RC4 */
wolfSSL 0:d92f9d21154c 92
wolfSSL 0:d92f9d21154c 93
wolfSSL 0:d92f9d21154c 94 #define WOLFSSL_RNG_CAVIUM_MAGIC 0xBEEF0004
wolfSSL 0:d92f9d21154c 95
wolfSSL 0:d92f9d21154c 96 /* secure Random Number Generator */
wolfSSL 0:d92f9d21154c 97
wolfSSL 0:d92f9d21154c 98
wolfSSL 0:d92f9d21154c 99 typedef struct RNG {
wolfSSL 0:d92f9d21154c 100 OS_Seed seed;
wolfSSL 0:d92f9d21154c 101 Arc4 cipher;
wolfSSL 0:d92f9d21154c 102 #ifdef HAVE_CAVIUM
wolfSSL 0:d92f9d21154c 103 int devId; /* nitrox device id */
wolfSSL 0:d92f9d21154c 104 word32 magic; /* using cavium magic */
wolfSSL 0:d92f9d21154c 105 #endif
wolfSSL 0:d92f9d21154c 106 } RNG;
wolfSSL 0:d92f9d21154c 107
wolfSSL 0:d92f9d21154c 108
wolfSSL 0:d92f9d21154c 109 #endif /* HAVE_HASH_DRBG || NO_RC4 */
wolfSSL 0:d92f9d21154c 110
wolfSSL 0:d92f9d21154c 111 #endif /* HAVE_FIPS */
wolfSSL 0:d92f9d21154c 112
wolfSSL 0:d92f9d21154c 113 WOLFSSL_LOCAL
wolfSSL 0:d92f9d21154c 114 int wc_GenerateSeed(OS_Seed* os, byte* seed, word32 sz);
wolfSSL 0:d92f9d21154c 115
wolfSSL 0:d92f9d21154c 116 #if defined(HAVE_HASHDRBG) || defined(NO_RC4)
wolfSSL 0:d92f9d21154c 117
wolfSSL 0:d92f9d21154c 118 #ifdef HAVE_CAVIUM
wolfSSL 0:d92f9d21154c 119 WOLFSSL_API int wc_InitRngCavium(RNG*, int);
wolfSSL 0:d92f9d21154c 120 #endif
wolfSSL 0:d92f9d21154c 121
wolfSSL 0:d92f9d21154c 122 #endif /* HAVE_HASH_DRBG || NO_RC4 */
wolfSSL 0:d92f9d21154c 123
wolfSSL 0:d92f9d21154c 124
wolfSSL 0:d92f9d21154c 125 WOLFSSL_API int wc_InitRng(RNG*);
wolfSSL 0:d92f9d21154c 126 WOLFSSL_API int wc_RNG_GenerateBlock(RNG*, byte*, word32 sz);
wolfSSL 0:d92f9d21154c 127 WOLFSSL_API int wc_RNG_GenerateByte(RNG*, byte*);
wolfSSL 0:d92f9d21154c 128 WOLFSSL_API int wc_FreeRng(RNG*);
wolfSSL 0:d92f9d21154c 129
wolfSSL 0:d92f9d21154c 130
wolfSSL 0:d92f9d21154c 131 #if defined(HAVE_HASHDRBG) || defined(NO_RC4)
wolfSSL 0:d92f9d21154c 132 WOLFSSL_API int wc_RNG_HealthTest(int reseed,
wolfSSL 0:d92f9d21154c 133 const byte* entropyA, word32 entropyASz,
wolfSSL 0:d92f9d21154c 134 const byte* entropyB, word32 entropyBSz,
wolfSSL 0:d92f9d21154c 135 byte* output, word32 outputSz);
wolfSSL 0:d92f9d21154c 136 #endif /* HAVE_HASHDRBG || NO_RC4 */
wolfSSL 0:d92f9d21154c 137
wolfSSL 0:d92f9d21154c 138 #ifdef __cplusplus
wolfSSL 0:d92f9d21154c 139 } /* extern "C" */
wolfSSL 0:d92f9d21154c 140 #endif
wolfSSL 0:d92f9d21154c 141
wolfSSL 0:d92f9d21154c 142 #endif /* WOLF_CRYPT_RANDOM_H */
wolfSSL 0:d92f9d21154c 143
wolfSSL 0:d92f9d21154c 144