My Project
Loading...
Searching...
No Matches
crypto.h
1/* crypto.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, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20 */
21
22
23
24/* Defines Microchip CRYPTO API layer */
25
26
27#ifndef MC_CRYPTO_API_H
28#define MC_CRYPTO_API_H
29
30
31#ifdef __cplusplus
32 extern "C" {
33#endif
34
35/* MD5 */
36typedef struct CRYPT_MD5_CTX {
37 int holder[28]; /* big enough to hold internal, but check on init */
38} CRYPT_MD5_CTX;
39
40int CRYPT_MD5_Initialize(CRYPT_MD5_CTX*);
41int CRYPT_MD5_DataAdd(CRYPT_MD5_CTX*, const unsigned char*, unsigned int);
42int CRYPT_MD5_Finalize(CRYPT_MD5_CTX*, unsigned char*);
43int CRYPT_MD5_DataSizeSet(CRYPT_MD5_CTX* md5, unsigned int sz);
44
45enum {
46 CRYPT_MD5_DIGEST_SIZE = 16
47};
48
49
50/* SHA */
51typedef struct CRYPT_SHA_CTX {
52 int holder[29]; /* big enough to hold internal, but check on init */
54
55int CRYPT_SHA_Initialize(CRYPT_SHA_CTX*);
56int CRYPT_SHA_DataAdd(CRYPT_SHA_CTX*, const unsigned char*, unsigned int);
57int CRYPT_SHA_Finalize(CRYPT_SHA_CTX*, unsigned char*);
58int CRYPT_SHA_DataSizeSet(CRYPT_SHA_CTX* sha, unsigned int sz);
59
60enum {
61 CRYPT_SHA_DIGEST_SIZE = 20
62};
63
64
65/* SHA-256 */
66typedef struct CRYPT_SHA256_CTX {
67 int holder[32]; /* big enough to hold internal, but check on init */
69
70int CRYPT_SHA256_Initialize(CRYPT_SHA256_CTX*);
71int CRYPT_SHA256_DataAdd(CRYPT_SHA256_CTX*, const unsigned char*, unsigned int);
72int CRYPT_SHA256_Finalize(CRYPT_SHA256_CTX*, unsigned char*);
73int CRYPT_SHA256_DataSizeSet(CRYPT_SHA256_CTX* sha256, unsigned int sz);
74
75enum {
76 CRYPT_SHA256_DIGEST_SIZE = 32
77};
78
79
80/* SHA-384 */
81typedef struct CRYPT_SHA384_CTX {
82 long long holder[36]; /* big enough to hold internal, but check on init */
84
85int CRYPT_SHA384_Initialize(CRYPT_SHA384_CTX*);
86int CRYPT_SHA384_DataAdd(CRYPT_SHA384_CTX*, const unsigned char*, unsigned int);
87int CRYPT_SHA384_Finalize(CRYPT_SHA384_CTX*, unsigned char*);
88
89enum {
90 CRYPT_SHA384_DIGEST_SIZE = 48
91};
92
93
94/* SHA-512 */
95typedef struct CRYPT_SHA512_CTX {
96 long long holder[36]; /* big enough to hold internal, but check on init */
98
99int CRYPT_SHA512_Initialize(CRYPT_SHA512_CTX*);
100int CRYPT_SHA512_DataAdd(CRYPT_SHA512_CTX*, const unsigned char*, unsigned int);
101int CRYPT_SHA512_Finalize(CRYPT_SHA512_CTX*, unsigned char*);
102
103enum {
104 CRYPT_SHA512_DIGEST_SIZE = 64
105};
106
107
108/* HMAC */
109typedef struct CRYPT_HMAC_CTX {
110 long long holder[98]; /* big enough to hold internal, but check on init */
112
113int CRYPT_HMAC_SetKey(CRYPT_HMAC_CTX*, int, const unsigned char*, unsigned int);
114int CRYPT_HMAC_DataAdd(CRYPT_HMAC_CTX*, const unsigned char*, unsigned int);
115int CRYPT_HMAC_Finalize(CRYPT_HMAC_CTX*, unsigned char*);
116
117/* HMAC types */
118enum {
119 CRYPT_HMAC_SHA = 4,
120 CRYPT_HMAC_SHA256 = 6,
121 CRYPT_HMAC_SHA384 = 7,
122 CRYPT_HMAC_SHA512 = 8
123};
124
125
126/* Huffman */
127int CRYPT_HUFFMAN_Compress(unsigned char*, unsigned int, const unsigned char*,
128 unsigned int, unsigned int);
129int CRYPT_HUFFMAN_DeCompress(unsigned char*, unsigned int, const unsigned char*,
130 unsigned int);
131
132/* flag to use static huffman */
133enum {
134 CRYPT_HUFFMAN_COMPRESS_STATIC = 1
135};
136
137
138/* RNG */
139typedef struct CRYPT_RNG_CTX {
140 int holder[66]; /* big enough to hold internal, but check on init */
142
143int CRYPT_RNG_Initialize(CRYPT_RNG_CTX*);
144int CRYPT_RNG_Get(CRYPT_RNG_CTX*, unsigned char*);
145int CRYPT_RNG_BlockGenerate(CRYPT_RNG_CTX*, unsigned char*, unsigned int);
146
147
148/* TDES */
149typedef struct CRYPT_TDES_CTX {
150 int holder[104]; /* big enough to hold internal, but check on init */
152
153int CRYPT_TDES_KeySet(CRYPT_TDES_CTX*, const unsigned char*,
154 const unsigned char*, int);
155int CRYPT_TDES_IvSet(CRYPT_TDES_CTX*, const unsigned char*);
156int CRYPT_TDES_CBC_Encrypt(CRYPT_TDES_CTX*, unsigned char*,
157 const unsigned char*, unsigned int);
158int CRYPT_TDES_CBC_Decrypt(CRYPT_TDES_CTX*, unsigned char*,
159 const unsigned char*, unsigned int);
160
161/* key direction flags for setup */
162enum {
163 CRYPT_TDES_ENCRYPTION = 0,
164 CRYPT_TDES_DECRYPTION = 1
165};
166
167
168/* AES */
169typedef struct CRYPT_AES_CTX {
170 int holder[90]; /* big enough to hold internal, but check on init */
172
173/* key */
174int CRYPT_AES_KeySet(CRYPT_AES_CTX*, const unsigned char*, unsigned int,
175 const unsigned char*, int);
176int CRYPT_AES_IvSet(CRYPT_AES_CTX*, const unsigned char*);
177
178/* cbc */
179int CRYPT_AES_CBC_Encrypt(CRYPT_AES_CTX*, unsigned char*,
180 const unsigned char*, unsigned int);
181int CRYPT_AES_CBC_Decrypt(CRYPT_AES_CTX*, unsigned char*,
182 const unsigned char*, unsigned int);
183
184/* ctr (counter), use Encrypt both ways with ENCRYPT key setup */
185int CRYPT_AES_CTR_Encrypt(CRYPT_AES_CTX*, unsigned char*,
186 const unsigned char*, unsigned int);
187
188/* direct, one block at a time */
189int CRYPT_AES_DIRECT_Encrypt(CRYPT_AES_CTX*, unsigned char*,
190 const unsigned char*);
191int CRYPT_AES_DIRECT_Decrypt(CRYPT_AES_CTX*, unsigned char*,
192 const unsigned char*);
193
194/* key direction flags for setup, ctr always uses ENCRYPT flag */
195enum {
196 CRYPT_AES_ENCRYPTION = 0,
197 CRYPT_AES_DECRYPTION = 1,
198 CRYPT_AES_BLOCK_SIZE = 16
199};
200
201
202
203/* RSA */
204typedef struct CRYPT_RSA_CTX {
205 void* holder;
207
208/* init/free */
209int CRYPT_RSA_Initialize(CRYPT_RSA_CTX*);
210int CRYPT_RSA_Free(CRYPT_RSA_CTX*);
211
212/* key decode */
213int CRYPT_RSA_PublicKeyDecode(CRYPT_RSA_CTX*, const unsigned char*,
214 unsigned int);
215int CRYPT_RSA_PrivateKeyDecode(CRYPT_RSA_CTX*, const unsigned char*,
216 unsigned int);
217
218/* encrypt/decrypt */
219int CRYPT_RSA_PublicEncrypt(CRYPT_RSA_CTX*, unsigned char*,
220 unsigned int, const unsigned char*, unsigned int,
222int CRYPT_RSA_PrivateDecrypt(CRYPT_RSA_CTX*, unsigned char*,
223 unsigned int, const unsigned char*, unsigned int);
224
225/* helpers */
226int CRYPT_RSA_EncryptSizeGet(CRYPT_RSA_CTX*);
227int CRYPT_RSA_SetRng(CRYPT_RSA_CTX*, CRYPT_RNG_CTX*);
228
229
230
231/* ECC */
232typedef struct CRYPT_ECC_CTX {
233 void* holder;
235
236/* init/free */
237int CRYPT_ECC_Initialize(CRYPT_ECC_CTX*);
238int CRYPT_ECC_Free(CRYPT_ECC_CTX*);
239
240/* key coders */
241int CRYPT_ECC_PublicExport(CRYPT_ECC_CTX*, unsigned char*, unsigned int,
242 unsigned int*);
243int CRYPT_ECC_PublicImport(CRYPT_ECC_CTX*, const unsigned char*, unsigned int);
244int CRYPT_ECC_PrivateImport(CRYPT_ECC_CTX*, const unsigned char*, unsigned int,
245 const unsigned char*, unsigned int);
246
247/* dhe */
248int CRYPT_ECC_DHE_KeyMake(CRYPT_ECC_CTX*, CRYPT_RNG_CTX*, int);
249int CRYPT_ECC_DHE_SharedSecretMake(CRYPT_ECC_CTX*, CRYPT_ECC_CTX*,
250 unsigned char*, unsigned int, unsigned int*);
251
252/* dsa */
253int CRYPT_ECC_DSA_HashSign(CRYPT_ECC_CTX*, CRYPT_RNG_CTX*, unsigned char*,
254 unsigned int, unsigned int*, const unsigned char*, unsigned int);
255int CRYPT_ECC_DSA_HashVerify(CRYPT_ECC_CTX*, const unsigned char*,
256 unsigned int, unsigned char*, unsigned int, int*);
257
258/* helpers */
259int CRYPT_ECC_KeySizeGet(CRYPT_ECC_CTX*);
260int CRYPT_ECC_SignatureSizeGet(CRYPT_ECC_CTX*);
261
262
263/* Error string helper, string needs to be >= 80 chars */
264int CRYPT_ERROR_StringGet(int, char*);
265
266
267#ifdef __cplusplus
268 } /* extern "C" */
269#endif
270
271
272#endif /* MC_CRYPTO_API_H */
273
Definition crypto.h:169
Definition crypto.h:232
Definition crypto.h:109
Definition crypto.h:139
Definition crypto.h:204
Definition crypto.h:66
Definition crypto.h:81
Definition crypto.h:95
Definition crypto.h:51
Definition crypto.h:149