A library for setting up Secure Socket Layer (SSL) connections and verifying remote hosts using certificates. Contains only the source files for mbed platform implementation of the library.
Dependents: HTTPClient-SSL HTTPClient-SSL HTTPClient-SSL HTTPClient-SSL
cyassl/ctaocrypt/random.h@6:cf58d49e1a86, 2015-03-23 (annotated)
- Committer:
- Mike Fiore
- Date:
- Mon Mar 23 16:51:07 2015 -0500
- Revision:
- 6:cf58d49e1a86
- Parent:
- 0:b86d15c6ba29
fix whitespace in sha512.c
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Vanger | 0:b86d15c6ba29 | 1 | /* random.h |
Vanger | 0:b86d15c6ba29 | 2 | * |
Vanger | 0:b86d15c6ba29 | 3 | * Copyright (C) 2006-2014 wolfSSL Inc. |
Vanger | 0:b86d15c6ba29 | 4 | * |
Vanger | 0:b86d15c6ba29 | 5 | * This file is part of CyaSSL. |
Vanger | 0:b86d15c6ba29 | 6 | * |
Vanger | 0:b86d15c6ba29 | 7 | * CyaSSL is free software; you can redistribute it and/or modify |
Vanger | 0:b86d15c6ba29 | 8 | * it under the terms of the GNU General Public License as published by |
Vanger | 0:b86d15c6ba29 | 9 | * the Free Software Foundation; either version 2 of the License, or |
Vanger | 0:b86d15c6ba29 | 10 | * (at your option) any later version. |
Vanger | 0:b86d15c6ba29 | 11 | * |
Vanger | 0:b86d15c6ba29 | 12 | * CyaSSL is distributed in the hope that it will be useful, |
Vanger | 0:b86d15c6ba29 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Vanger | 0:b86d15c6ba29 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Vanger | 0:b86d15c6ba29 | 15 | * GNU General Public License for more details. |
Vanger | 0:b86d15c6ba29 | 16 | * |
Vanger | 0:b86d15c6ba29 | 17 | * You should have received a copy of the GNU General Public License |
Vanger | 0:b86d15c6ba29 | 18 | * along with this program; if not, write to the Free Software |
Vanger | 0:b86d15c6ba29 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
Vanger | 0:b86d15c6ba29 | 20 | */ |
Vanger | 0:b86d15c6ba29 | 21 | |
Vanger | 0:b86d15c6ba29 | 22 | |
Vanger | 0:b86d15c6ba29 | 23 | #ifndef CTAO_CRYPT_RANDOM_H |
Vanger | 0:b86d15c6ba29 | 24 | #define CTAO_CRYPT_RANDOM_H |
Vanger | 0:b86d15c6ba29 | 25 | |
Vanger | 0:b86d15c6ba29 | 26 | #include <cyassl/ctaocrypt/types.h> |
Vanger | 0:b86d15c6ba29 | 27 | |
Vanger | 0:b86d15c6ba29 | 28 | #if defined(HAVE_HASHDRBG) || defined(NO_RC4) |
Vanger | 0:b86d15c6ba29 | 29 | #ifdef NO_SHA256 |
Vanger | 0:b86d15c6ba29 | 30 | #error "Hash DRBG requires SHA-256." |
Vanger | 0:b86d15c6ba29 | 31 | #endif /* NO_SHA256 */ |
Vanger | 0:b86d15c6ba29 | 32 | |
Vanger | 0:b86d15c6ba29 | 33 | #include <cyassl/ctaocrypt/sha256.h> |
Vanger | 0:b86d15c6ba29 | 34 | #else /* HAVE_HASHDRBG || NO_RC4 */ |
Vanger | 0:b86d15c6ba29 | 35 | #include <cyassl/ctaocrypt/arc4.h> |
Vanger | 0:b86d15c6ba29 | 36 | #endif /* HAVE_HASHDRBG || NO_RC4 */ |
Vanger | 0:b86d15c6ba29 | 37 | |
Vanger | 0:b86d15c6ba29 | 38 | #ifdef __cplusplus |
Vanger | 0:b86d15c6ba29 | 39 | extern "C" { |
Vanger | 0:b86d15c6ba29 | 40 | #endif |
Vanger | 0:b86d15c6ba29 | 41 | |
Vanger | 0:b86d15c6ba29 | 42 | |
Vanger | 0:b86d15c6ba29 | 43 | #if defined(USE_WINDOWS_API) |
Vanger | 0:b86d15c6ba29 | 44 | #if defined(_WIN64) |
Vanger | 0:b86d15c6ba29 | 45 | typedef unsigned __int64 ProviderHandle; |
Vanger | 0:b86d15c6ba29 | 46 | /* type HCRYPTPROV, avoid #include <windows.h> */ |
Vanger | 0:b86d15c6ba29 | 47 | #else |
Vanger | 0:b86d15c6ba29 | 48 | typedef unsigned long ProviderHandle; |
Vanger | 0:b86d15c6ba29 | 49 | #endif |
Vanger | 0:b86d15c6ba29 | 50 | #endif |
Vanger | 0:b86d15c6ba29 | 51 | |
Vanger | 0:b86d15c6ba29 | 52 | |
Vanger | 0:b86d15c6ba29 | 53 | /* OS specific seeder */ |
Vanger | 0:b86d15c6ba29 | 54 | typedef struct OS_Seed { |
Vanger | 0:b86d15c6ba29 | 55 | #if defined(USE_WINDOWS_API) |
Vanger | 0:b86d15c6ba29 | 56 | ProviderHandle handle; |
Vanger | 0:b86d15c6ba29 | 57 | #else |
Vanger | 0:b86d15c6ba29 | 58 | int fd; |
Vanger | 0:b86d15c6ba29 | 59 | #endif |
Vanger | 0:b86d15c6ba29 | 60 | } OS_Seed; |
Vanger | 0:b86d15c6ba29 | 61 | |
Vanger | 0:b86d15c6ba29 | 62 | |
Vanger | 0:b86d15c6ba29 | 63 | CYASSL_LOCAL |
Vanger | 0:b86d15c6ba29 | 64 | int GenerateSeed(OS_Seed* os, byte* seed, word32 sz); |
Vanger | 0:b86d15c6ba29 | 65 | |
Vanger | 0:b86d15c6ba29 | 66 | #if defined(CYASSL_MDK_ARM) |
Vanger | 0:b86d15c6ba29 | 67 | #undef RNG |
Vanger | 0:b86d15c6ba29 | 68 | #define RNG CyaSSL_RNG /* for avoiding name conflict in "stm32f2xx.h" */ |
Vanger | 0:b86d15c6ba29 | 69 | #endif |
Vanger | 0:b86d15c6ba29 | 70 | |
Vanger | 0:b86d15c6ba29 | 71 | |
Vanger | 0:b86d15c6ba29 | 72 | #if defined(HAVE_HASHDRBG) || defined(NO_RC4) |
Vanger | 0:b86d15c6ba29 | 73 | |
Vanger | 0:b86d15c6ba29 | 74 | |
Vanger | 0:b86d15c6ba29 | 75 | #define DRBG_SEED_LEN (440/8) |
Vanger | 0:b86d15c6ba29 | 76 | |
Vanger | 0:b86d15c6ba29 | 77 | |
Vanger | 0:b86d15c6ba29 | 78 | struct DRBG; /* Private DRBG state */ |
Vanger | 0:b86d15c6ba29 | 79 | |
Vanger | 0:b86d15c6ba29 | 80 | |
Vanger | 0:b86d15c6ba29 | 81 | /* Hash-based Deterministic Random Bit Generator */ |
Vanger | 0:b86d15c6ba29 | 82 | typedef struct RNG { |
Vanger | 0:b86d15c6ba29 | 83 | OS_Seed seed; |
Vanger | 0:b86d15c6ba29 | 84 | struct DRBG* drbg; |
Vanger | 0:b86d15c6ba29 | 85 | byte status; |
Vanger | 0:b86d15c6ba29 | 86 | } RNG; |
Vanger | 0:b86d15c6ba29 | 87 | |
Vanger | 0:b86d15c6ba29 | 88 | |
Vanger | 0:b86d15c6ba29 | 89 | #else /* HAVE_HASHDRBG || NO_RC4 */ |
Vanger | 0:b86d15c6ba29 | 90 | |
Vanger | 0:b86d15c6ba29 | 91 | |
Vanger | 0:b86d15c6ba29 | 92 | #define CYASSL_RNG_CAVIUM_MAGIC 0xBEEF0004 |
Vanger | 0:b86d15c6ba29 | 93 | |
Vanger | 0:b86d15c6ba29 | 94 | /* secure Random Number Generator */ |
Vanger | 0:b86d15c6ba29 | 95 | |
Vanger | 0:b86d15c6ba29 | 96 | |
Vanger | 0:b86d15c6ba29 | 97 | typedef struct RNG { |
Vanger | 0:b86d15c6ba29 | 98 | OS_Seed seed; |
Vanger | 0:b86d15c6ba29 | 99 | Arc4 cipher; |
Vanger | 0:b86d15c6ba29 | 100 | #ifdef HAVE_CAVIUM |
Vanger | 0:b86d15c6ba29 | 101 | int devId; /* nitrox device id */ |
Vanger | 0:b86d15c6ba29 | 102 | word32 magic; /* using cavium magic */ |
Vanger | 0:b86d15c6ba29 | 103 | #endif |
Vanger | 0:b86d15c6ba29 | 104 | } RNG; |
Vanger | 0:b86d15c6ba29 | 105 | |
Vanger | 0:b86d15c6ba29 | 106 | |
Vanger | 0:b86d15c6ba29 | 107 | #ifdef HAVE_CAVIUM |
Vanger | 0:b86d15c6ba29 | 108 | CYASSL_API int InitRngCavium(RNG*, int); |
Vanger | 0:b86d15c6ba29 | 109 | #endif |
Vanger | 0:b86d15c6ba29 | 110 | |
Vanger | 0:b86d15c6ba29 | 111 | |
Vanger | 0:b86d15c6ba29 | 112 | #endif /* HAVE_HASH_DRBG || NO_RC4 */ |
Vanger | 0:b86d15c6ba29 | 113 | |
Vanger | 0:b86d15c6ba29 | 114 | |
Vanger | 0:b86d15c6ba29 | 115 | CYASSL_API int InitRng(RNG*); |
Vanger | 0:b86d15c6ba29 | 116 | CYASSL_API int RNG_GenerateBlock(RNG*, byte*, word32 sz); |
Vanger | 0:b86d15c6ba29 | 117 | CYASSL_API int RNG_GenerateByte(RNG*, byte*); |
Vanger | 0:b86d15c6ba29 | 118 | |
Vanger | 0:b86d15c6ba29 | 119 | |
Vanger | 0:b86d15c6ba29 | 120 | #if defined(HAVE_HASHDRBG) || defined(NO_RC4) |
Vanger | 0:b86d15c6ba29 | 121 | CYASSL_API int FreeRng(RNG*); |
Vanger | 0:b86d15c6ba29 | 122 | CYASSL_API int RNG_HealthTest(int reseed, |
Vanger | 0:b86d15c6ba29 | 123 | const byte* entropyA, word32 entropyASz, |
Vanger | 0:b86d15c6ba29 | 124 | const byte* entropyB, word32 entropyBSz, |
Vanger | 0:b86d15c6ba29 | 125 | byte* output, word32 outputSz); |
Vanger | 0:b86d15c6ba29 | 126 | #endif /* HAVE_HASHDRBG || NO_RC4 */ |
Vanger | 0:b86d15c6ba29 | 127 | |
Vanger | 0:b86d15c6ba29 | 128 | |
Vanger | 0:b86d15c6ba29 | 129 | #ifdef HAVE_FIPS |
Vanger | 0:b86d15c6ba29 | 130 | /* fips wrapper calls, user can call direct */ |
Vanger | 0:b86d15c6ba29 | 131 | CYASSL_API int InitRng_fips(RNG* rng); |
Vanger | 0:b86d15c6ba29 | 132 | CYASSL_API int FreeRng_fips(RNG* rng); |
Vanger | 0:b86d15c6ba29 | 133 | CYASSL_API int RNG_GenerateBlock_fips(RNG* rng, byte* buf, word32 bufSz); |
Vanger | 0:b86d15c6ba29 | 134 | CYASSL_API int RNG_HealthTest_fips(int reseed, |
Vanger | 0:b86d15c6ba29 | 135 | const byte* entropyA, word32 entropyASz, |
Vanger | 0:b86d15c6ba29 | 136 | const byte* entropyB, word32 entropyBSz, |
Vanger | 0:b86d15c6ba29 | 137 | byte* output, word32 outputSz); |
Vanger | 0:b86d15c6ba29 | 138 | #ifndef FIPS_NO_WRAPPERS |
Vanger | 0:b86d15c6ba29 | 139 | /* if not impl or fips.c impl wrapper force fips calls if fips build */ |
Vanger | 0:b86d15c6ba29 | 140 | #define InitRng InitRng_fips |
Vanger | 0:b86d15c6ba29 | 141 | #define FreeRng FreeRng_fips |
Vanger | 0:b86d15c6ba29 | 142 | #define RNG_GenerateBlock RNG_GenerateBlock_fips |
Vanger | 0:b86d15c6ba29 | 143 | #define RNG_HealthTest RNG_HealthTest_fips |
Vanger | 0:b86d15c6ba29 | 144 | #endif /* FIPS_NO_WRAPPERS */ |
Vanger | 0:b86d15c6ba29 | 145 | #endif /* HAVE_FIPS */ |
Vanger | 0:b86d15c6ba29 | 146 | |
Vanger | 0:b86d15c6ba29 | 147 | |
Vanger | 0:b86d15c6ba29 | 148 | #ifdef __cplusplus |
Vanger | 0:b86d15c6ba29 | 149 | } /* extern "C" */ |
Vanger | 0:b86d15c6ba29 | 150 | #endif |
Vanger | 0:b86d15c6ba29 | 151 | |
Vanger | 0:b86d15c6ba29 | 152 | #endif /* CTAO_CRYPT_RANDOM_H */ |
Vanger | 0:b86d15c6ba29 | 153 |