source: azure_iot_hub_f767zi/trunk/wolfssl-4.7.0/wolfssl/wolfcrypt/cryptocb.h@ 464

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

WolfSSLとAzure IoT SDKを更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 8.9 KB
Line 
1/* cryptocb.h
2 *
3 * Copyright (C) 2006-2020 wolfSSL Inc.
4 *
5 * This file is part of wolfSSL.
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, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef _WOLF_CRYPTO_CB_H_
22#define _WOLF_CRYPTO_CB_H_
23
24#include <wolfssl/wolfcrypt/types.h>
25
26#ifdef __cplusplus
27 extern "C" {
28#endif
29
30/* Defines the Crypto Callback interface version, for compatibility */
31/* Increment this when Crypto Callback interface changes are made */
32#define CRYPTO_CB_VER 2
33
34
35#ifdef WOLF_CRYPTO_CB
36
37#ifndef NO_RSA
38 #include <wolfssl/wolfcrypt/rsa.h>
39#endif
40#ifdef HAVE_ECC
41 #include <wolfssl/wolfcrypt/ecc.h>
42#endif
43#ifndef NO_AES
44 #include <wolfssl/wolfcrypt/aes.h>
45#endif
46#ifndef NO_SHA
47 #include <wolfssl/wolfcrypt/sha.h>
48#endif
49#ifndef NO_SHA256
50 #include <wolfssl/wolfcrypt/sha256.h>
51#endif
52#ifndef NO_HMAC
53 #include <wolfssl/wolfcrypt/hmac.h>
54#endif
55#ifndef WC_NO_RNG
56 #include <wolfssl/wolfcrypt/random.h>
57#endif
58#ifndef NO_DES3
59 #include <wolfssl/wolfcrypt/des3.h>
60#endif
61
62
63/* Crypto Information Structure for callbacks */
64typedef struct wc_CryptoInfo {
65 int algo_type; /* enum wc_AlgoType */
66#if !defined(NO_RSA) || defined(HAVE_ECC)
67 struct {
68 int type; /* enum wc_PkType */
69 union {
70 #ifndef NO_RSA
71 struct {
72 const byte* in;
73 word32 inLen;
74 byte* out;
75 word32* outLen;
76 int type;
77 RsaKey* key;
78 WC_RNG* rng;
79 } rsa;
80 #ifdef WOLFSSL_KEY_GEN
81 struct {
82 RsaKey* key;
83 int size;
84 long e;
85 WC_RNG* rng;
86 } rsakg;
87 #endif
88 struct {
89 RsaKey* key;
90 const byte* pubKey;
91 word32 pubKeySz;
92 } rsa_check;
93 #endif
94 #ifdef HAVE_ECC
95 struct {
96 WC_RNG* rng;
97 int size;
98 ecc_key* key;
99 int curveId;
100 } eckg;
101 struct {
102 ecc_key* private_key;
103 ecc_key* public_key;
104 byte* out;
105 word32* outlen;
106 } ecdh;
107 struct {
108 const byte* in;
109 word32 inlen;
110 byte* out;
111 word32* outlen;
112 WC_RNG* rng;
113 ecc_key* key;
114 } eccsign;
115 struct {
116 const byte* sig;
117 word32 siglen;
118 const byte* hash;
119 word32 hashlen;
120 int* res;
121 ecc_key* key;
122 } eccverify;
123 struct {
124 ecc_key* key;
125 const byte* pubKey;
126 word32 pubKeySz;
127 } ecc_check;
128 #endif
129 };
130 } pk;
131#endif /* !NO_RSA || HAVE_ECC */
132#if !defined(NO_AES) || !defined(NO_DES3)
133 struct {
134 int type; /* enum wc_CipherType */
135 int enc;
136 union {
137 #ifdef HAVE_AESGCM
138 struct {
139 Aes* aes;
140 byte* out;
141 const byte* in;
142 word32 sz;
143 const byte* iv;
144 word32 ivSz;
145 byte* authTag;
146 word32 authTagSz;
147 const byte* authIn;
148 word32 authInSz;
149 } aesgcm_enc;
150 struct {
151 Aes* aes;
152 byte* out;
153 const byte* in;
154 word32 sz;
155 const byte* iv;
156 word32 ivSz;
157 const byte* authTag;
158 word32 authTagSz;
159 const byte* authIn;
160 word32 authInSz;
161 } aesgcm_dec;
162 #endif /* HAVE_AESGCM */
163 #ifdef HAVE_AES_CBC
164 struct {
165 Aes* aes;
166 byte* out;
167 const byte* in;
168 word32 sz;
169 } aescbc;
170 #endif /* HAVE_AES_CBC */
171 #ifndef NO_DES3
172 struct {
173 Des3* des;
174 byte* out;
175 const byte* in;
176 word32 sz;
177 } des3;
178 #endif
179 };
180 } cipher;
181#endif /* !NO_AES || !NO_DES3 */
182#if !defined(NO_SHA) || !defined(NO_SHA256)
183 struct {
184 int type; /* enum wc_HashType */
185 const byte* in;
186 word32 inSz;
187 byte* digest;
188 union {
189 #ifndef NO_SHA
190 wc_Sha* sha1;
191 #endif
192 #ifndef NO_SHA256
193 wc_Sha256* sha256;
194 #endif
195 };
196 } hash;
197#endif /* !NO_SHA || !NO_SHA256 */
198#ifndef NO_HMAC
199 struct {
200 int macType; /* enum wc_HashType */
201 const byte* in;
202 word32 inSz;
203 byte* digest;
204 Hmac* hmac;
205 } hmac;
206#endif
207#ifndef WC_NO_RNG
208 struct {
209 WC_RNG* rng;
210 byte* out;
211 word32 sz;
212 } rng;
213 struct {
214 OS_Seed* os;
215 byte* seed;
216 word32 sz;
217 } seed;
218#endif
219} wc_CryptoInfo;
220
221
222typedef int (*CryptoDevCallbackFunc)(int devId, wc_CryptoInfo* info, void* ctx);
223
224WOLFSSL_LOCAL void wc_CryptoCb_Init(void);
225WOLFSSL_LOCAL int wc_CryptoCb_GetDevIdAtIndex(int startIdx);
226WOLFSSL_API int wc_CryptoCb_RegisterDevice(int devId, CryptoDevCallbackFunc cb, void* ctx);
227WOLFSSL_API void wc_CryptoCb_UnRegisterDevice(int devId);
228
229/* old function names */
230#define wc_CryptoDev_RegisterDevice wc_CryptoCb_RegisterDevice
231#define wc_CryptoDev_UnRegisterDevice wc_CryptoCb_UnRegisterDevice
232
233
234#ifndef NO_RSA
235WOLFSSL_LOCAL int wc_CryptoCb_Rsa(const byte* in, word32 inLen, byte* out,
236 word32* outLen, int type, RsaKey* key, WC_RNG* rng);
237
238#ifdef WOLFSSL_KEY_GEN
239WOLFSSL_LOCAL int wc_CryptoCb_MakeRsaKey(RsaKey* key, int size, long e,
240 WC_RNG* rng);
241#endif /* WOLFSSL_KEY_GEN */
242
243WOLFSSL_LOCAL int wc_CryptoCb_RsaCheckPrivKey(RsaKey* key, const byte* pubKey,
244 word32 pubKeySz);
245#endif /* !NO_RSA */
246
247#ifdef HAVE_ECC
248WOLFSSL_LOCAL int wc_CryptoCb_MakeEccKey(WC_RNG* rng, int keySize,
249 ecc_key* key, int curveId);
250
251WOLFSSL_LOCAL int wc_CryptoCb_Ecdh(ecc_key* private_key, ecc_key* public_key,
252 byte* out, word32* outlen);
253
254WOLFSSL_LOCAL int wc_CryptoCb_EccSign(const byte* in, word32 inlen, byte* out,
255 word32 *outlen, WC_RNG* rng, ecc_key* key);
256
257WOLFSSL_LOCAL int wc_CryptoCb_EccVerify(const byte* sig, word32 siglen,
258 const byte* hash, word32 hashlen, int* res, ecc_key* key);
259
260WOLFSSL_LOCAL int wc_CryptoCb_EccCheckPrivKey(ecc_key* key, const byte* pubKey,
261 word32 pubKeySz);
262#endif /* HAVE_ECC */
263
264#ifndef NO_AES
265#ifdef HAVE_AESGCM
266WOLFSSL_LOCAL int wc_CryptoCb_AesGcmEncrypt(Aes* aes, byte* out,
267 const byte* in, word32 sz, const byte* iv, word32 ivSz,
268 byte* authTag, word32 authTagSz, const byte* authIn, word32 authInSz);
269
270WOLFSSL_LOCAL int wc_CryptoCb_AesGcmDecrypt(Aes* aes, byte* out,
271 const byte* in, word32 sz, const byte* iv, word32 ivSz,
272 const byte* authTag, word32 authTagSz,
273 const byte* authIn, word32 authInSz);
274#endif /* HAVE_AESGCM */
275#ifdef HAVE_AES_CBC
276WOLFSSL_LOCAL int wc_CryptoCb_AesCbcEncrypt(Aes* aes, byte* out,
277 const byte* in, word32 sz);
278WOLFSSL_LOCAL int wc_CryptoCb_AesCbcDecrypt(Aes* aes, byte* out,
279 const byte* in, word32 sz);
280#endif /* HAVE_AES_CBC */
281#endif /* !NO_AES */
282
283#ifndef NO_DES3
284WOLFSSL_LOCAL int wc_CryptoCb_Des3Encrypt(Des3* des3, byte* out,
285 const byte* in, word32 sz);
286WOLFSSL_LOCAL int wc_CryptoCb_Des3Decrypt(Des3* des3, byte* out,
287 const byte* in, word32 sz);
288#endif /* !NO_DES3 */
289
290#ifndef NO_SHA
291WOLFSSL_LOCAL int wc_CryptoCb_ShaHash(wc_Sha* sha, const byte* in,
292 word32 inSz, byte* digest);
293#endif /* !NO_SHA */
294
295#ifndef NO_SHA256
296WOLFSSL_LOCAL int wc_CryptoCb_Sha256Hash(wc_Sha256* sha256, const byte* in,
297 word32 inSz, byte* digest);
298#endif /* !NO_SHA256 */
299#ifndef NO_HMAC
300WOLFSSL_LOCAL int wc_CryptoCb_Hmac(Hmac* hmac, int macType, const byte* in,
301 word32 inSz, byte* digest);
302#endif /* !NO_HMAC */
303
304#ifndef WC_NO_RNG
305WOLFSSL_LOCAL int wc_CryptoCb_RandomBlock(WC_RNG* rng, byte* out, word32 sz);
306WOLFSSL_LOCAL int wc_CryptoCb_RandomSeed(OS_Seed* os, byte* seed, word32 sz);
307#endif
308
309#endif /* WOLF_CRYPTO_CB */
310
311#ifdef __cplusplus
312 } /* extern "C" */
313#endif
314
315#endif /* _WOLF_CRYPTO_CB_H_ */
Note: See TracBrowser for help on using the repository browser.