source: UsbWattMeter/trunk/wolfssl-3.7.0/wolfssl/wolfcrypt/random.h@ 164

Last change on this file since 164 was 164, checked in by coas-nagasima, 6 years ago

TOPPERS/ECNLサンプルアプリ「USB充電器電力計」を追加

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