source: UsbWattMeter/trunk/wolfssl-3.7.0/wolfssl/openssl/evp.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: 9.1 KB
Line 
1/* evp.h
2 *
3 * Copyright (C) 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/* evp.h defines mini evp openssl compatibility layer
24 *
25 */
26
27
28#ifndef WOLFSSL_EVP_H_
29#define WOLFSSL_EVP_H_
30
31#include <wolfssl/wolfcrypt/settings.h>
32
33#ifdef WOLFSSL_PREFIX
34#include "prefix_evp.h"
35#endif
36
37#ifndef NO_MD5
38 #include <wolfssl/openssl/md5.h>
39#endif
40#include <wolfssl/openssl/sha.h>
41#include <wolfssl/openssl/ripemd.h>
42#include <wolfssl/openssl/rsa.h>
43#include <wolfssl/openssl/dsa.h>
44#include <wolfssl/openssl/ec.h>
45
46#include <wolfssl/wolfcrypt/aes.h>
47#include <wolfssl/wolfcrypt/des3.h>
48#include <wolfssl/wolfcrypt/arc4.h>
49
50
51#ifdef __cplusplus
52 extern "C" {
53#endif
54
55typedef char WOLFSSL_EVP_MD;
56typedef char WOLFSSL_EVP_CIPHER;
57
58#ifndef NO_MD5
59 WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_md5(void);
60#endif
61WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha1(void);
62WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha256(void);
63WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha384(void);
64WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha512(void);
65WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_ripemd160(void);
66
67WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_128_cbc(void);
68WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_192_cbc(void);
69WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_256_cbc(void);
70WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_128_ctr(void);
71WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_192_ctr(void);
72WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_256_ctr(void);
73WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_des_cbc(void);
74WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_des_ede3_cbc(void);
75WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_rc4(void);
76WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_idea_cbc(void);
77WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_enc_null(void);
78
79
80typedef union {
81 #ifndef NO_MD5
82 WOLFSSL_MD5_CTX md5;
83 #endif
84 WOLFSSL_SHA_CTX sha;
85 WOLFSSL_SHA256_CTX sha256;
86 #ifdef WOLFSSL_SHA384
87 WOLFSSL_SHA384_CTX sha384;
88 #endif
89 #ifdef WOLFSSL_SHA512
90 WOLFSSL_SHA512_CTX sha512;
91 #endif
92 #ifdef WOLFSSL_RIPEMD
93 WOLFSSL_RIPEMD_CTX ripemd;
94 #endif
95} WOLFSSL_Hasher;
96
97
98typedef struct WOLFSSL_EVP_MD_CTX {
99 unsigned char macType;
100 WOLFSSL_Hasher hash;
101} WOLFSSL_EVP_MD_CTX;
102
103
104typedef union {
105#ifndef NO_AES
106 Aes aes;
107#endif
108#ifndef NO_DES3
109 Des des;
110 Des3 des3;
111#endif
112 Arc4 arc4;
113#ifdef HAVE_IDEA
114 Idea idea;
115#endif
116} WOLFSSL_Cipher;
117
118
119enum {
120 AES_128_CBC_TYPE = 1,
121 AES_192_CBC_TYPE = 2,
122 AES_256_CBC_TYPE = 3,
123 AES_128_CTR_TYPE = 4,
124 AES_192_CTR_TYPE = 5,
125 AES_256_CTR_TYPE = 6,
126 DES_CBC_TYPE = 7,
127 DES_EDE3_CBC_TYPE = 8,
128 ARC4_TYPE = 9,
129 NULL_CIPHER_TYPE = 10,
130 EVP_PKEY_RSA = 11,
131 EVP_PKEY_DSA = 12,
132 EVP_PKEY_EC = 13,
133 IDEA_CBC_TYPE = 14,
134 NID_sha1 = 64,
135 NID_md5 = 4
136};
137
138
139typedef struct WOLFSSL_EVP_CIPHER_CTX {
140 int keyLen; /* user may set for variable */
141 unsigned char enc; /* if encrypt side, then true */
142 unsigned char cipherType;
143#ifndef NO_AES
144 unsigned char iv[AES_BLOCK_SIZE]; /* working iv pointer into cipher */
145#elif !defined(NO_DES3)
146 unsigned char iv[DES_BLOCK_SIZE]; /* working iv pointer into cipher */
147#endif
148 WOLFSSL_Cipher cipher;
149} WOLFSSL_EVP_CIPHER_CTX;
150
151
152WOLFSSL_API int wolfSSL_EVP_MD_size(const WOLFSSL_EVP_MD* md);
153WOLFSSL_API void wolfSSL_EVP_MD_CTX_init(WOLFSSL_EVP_MD_CTX* ctx);
154WOLFSSL_API int wolfSSL_EVP_MD_CTX_cleanup(WOLFSSL_EVP_MD_CTX* ctx);
155
156WOLFSSL_API int wolfSSL_EVP_DigestInit(WOLFSSL_EVP_MD_CTX* ctx,
157 const WOLFSSL_EVP_MD* type);
158WOLFSSL_API int wolfSSL_EVP_DigestUpdate(WOLFSSL_EVP_MD_CTX* ctx, const void* data,
159 unsigned long sz);
160WOLFSSL_API int wolfSSL_EVP_DigestFinal(WOLFSSL_EVP_MD_CTX* ctx, unsigned char* md,
161 unsigned int* s);
162WOLFSSL_API int wolfSSL_EVP_DigestFinal_ex(WOLFSSL_EVP_MD_CTX* ctx,
163 unsigned char* md, unsigned int* s);
164#ifndef NO_MD5
165WOLFSSL_API int wolfSSL_EVP_BytesToKey(const WOLFSSL_EVP_CIPHER*,
166 const WOLFSSL_EVP_MD*, const unsigned char*,
167 const unsigned char*, int, int, unsigned char*,
168 unsigned char*);
169#endif
170
171WOLFSSL_API void wolfSSL_EVP_CIPHER_CTX_init(WOLFSSL_EVP_CIPHER_CTX* ctx);
172WOLFSSL_API int wolfSSL_EVP_CIPHER_CTX_cleanup(WOLFSSL_EVP_CIPHER_CTX* ctx);
173
174WOLFSSL_API int wolfSSL_EVP_CIPHER_CTX_iv_length(const WOLFSSL_EVP_CIPHER_CTX*);
175
176
177WOLFSSL_API int wolfSSL_EVP_CipherInit(WOLFSSL_EVP_CIPHER_CTX* ctx,
178 const WOLFSSL_EVP_CIPHER* type,
179 unsigned char* key, unsigned char* iv,
180 int enc);
181WOLFSSL_API int wolfSSL_EVP_CIPHER_CTX_key_length(WOLFSSL_EVP_CIPHER_CTX* ctx);
182WOLFSSL_API int wolfSSL_EVP_CIPHER_CTX_set_key_length(WOLFSSL_EVP_CIPHER_CTX* ctx,
183 int keylen);
184WOLFSSL_API int wolfSSL_EVP_Cipher(WOLFSSL_EVP_CIPHER_CTX* ctx,
185 unsigned char* dst, unsigned char* src,
186 unsigned int len);
187
188WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_get_digestbynid(int);
189
190WOLFSSL_API WOLFSSL_RSA* wolfSSL_EVP_PKEY_get1_RSA(WOLFSSL_EVP_PKEY*);
191WOLFSSL_API WOLFSSL_DSA* wolfSSL_EVP_PKEY_get1_DSA(WOLFSSL_EVP_PKEY*);
192WOLFSSL_API WOLFSSL_EC_KEY *wolfSSL_EVP_PKEY_get1_EC_KEY(WOLFSSL_EVP_PKEY *key);
193
194/* these next ones don't need real OpenSSL type, for OpenSSH compat only */
195WOLFSSL_API void* wolfSSL_EVP_X_STATE(const WOLFSSL_EVP_CIPHER_CTX* ctx);
196WOLFSSL_API int wolfSSL_EVP_X_STATE_LEN(const WOLFSSL_EVP_CIPHER_CTX* ctx);
197
198WOLFSSL_API void wolfSSL_3des_iv(WOLFSSL_EVP_CIPHER_CTX* ctx, int doset,
199 unsigned char* iv, int len);
200WOLFSSL_API void wolfSSL_aes_ctr_iv(WOLFSSL_EVP_CIPHER_CTX* ctx, int doset,
201 unsigned char* iv, int len);
202
203WOLFSSL_API int wolfSSL_StoreExternalIV(WOLFSSL_EVP_CIPHER_CTX* ctx);
204WOLFSSL_API int wolfSSL_SetInternalIV(WOLFSSL_EVP_CIPHER_CTX* ctx);
205
206
207/* end OpenSSH compat */
208
209typedef WOLFSSL_EVP_MD EVP_MD;
210typedef WOLFSSL_EVP_CIPHER EVP_CIPHER;
211typedef WOLFSSL_EVP_MD_CTX EVP_MD_CTX;
212typedef WOLFSSL_EVP_CIPHER_CTX EVP_CIPHER_CTX;
213
214#ifndef NO_MD5
215 #define EVP_md5 wolfSSL_EVP_md5
216#endif
217#define EVP_sha1 wolfSSL_EVP_sha1
218#define EVP_sha256 wolfSSL_EVP_sha256
219#define EVP_sha384 wolfSSL_EVP_sha384
220#define EVP_sha512 wolfSSL_EVP_sha512
221#define EVP_ripemd160 wolfSSL_EVP_ripemd160
222
223#define EVP_aes_128_cbc wolfSSL_EVP_aes_128_cbc
224#define EVP_aes_192_cbc wolfSSL_EVP_aes_192_cbc
225#define EVP_aes_256_cbc wolfSSL_EVP_aes_256_cbc
226#define EVP_aes_128_ctr wolfSSL_EVP_aes_128_ctr
227#define EVP_aes_192_ctr wolfSSL_EVP_aes_192_ctr
228#define EVP_aes_256_ctr wolfSSL_EVP_aes_256_ctr
229#define EVP_des_cbc wolfSSL_EVP_des_cbc
230#define EVP_des_ede3_cbc wolfSSL_EVP_des_ede3_cbc
231#define EVP_rc4 wolfSSL_EVP_rc4
232#define EVP_idea_cbc wolfSSL_EVP_idea_cbc
233#define EVP_enc_null wolfSSL_EVP_enc_null
234
235#define EVP_MD_size wolfSSL_EVP_MD_size
236#define EVP_MD_CTX_init wolfSSL_EVP_MD_CTX_init
237#define EVP_MD_CTX_cleanup wolfSSL_EVP_MD_CTX_cleanup
238#define EVP_DigestInit wolfSSL_EVP_DigestInit
239#define EVP_DigestUpdate wolfSSL_EVP_DigestUpdate
240#define EVP_DigestFinal wolfSSL_EVP_DigestFinal
241#define EVP_DigestFinal_ex wolfSSL_EVP_DigestFinal_ex
242#define EVP_BytesToKey wolfSSL_EVP_BytesToKey
243
244#define EVP_CIPHER_CTX_init wolfSSL_EVP_CIPHER_CTX_init
245#define EVP_CIPHER_CTX_cleanup wolfSSL_EVP_CIPHER_CTX_cleanup
246#define EVP_CIPHER_CTX_iv_length wolfSSL_EVP_CIPHER_CTX_iv_length
247#define EVP_CIPHER_CTX_key_length wolfSSL_EVP_CIPHER_CTX_key_length
248#define EVP_CIPHER_CTX_set_key_length wolfSSL_EVP_CIPHER_CTX_set_key_length
249#define EVP_CipherInit wolfSSL_EVP_CipherInit
250#define EVP_Cipher wolfSSL_EVP_Cipher
251
252#define EVP_get_digestbynid wolfSSL_EVP_get_digestbynid
253
254#define EVP_PKEY_get1_RSA wolfSSL_EVP_PKEY_get1_RSA
255#define EVP_PKEY_get1_DSA wolfSSL_EVP_PKEY_get1_DSA
256#define EVP_PKEY_get1_EC_KEY wolfSSL_EVP_PKEY_get1_EC_KEY
257
258
259#ifndef EVP_MAX_MD_SIZE
260 #define EVP_MAX_MD_SIZE 64 /* sha512 */
261#endif
262
263#ifdef __cplusplus
264 } /* extern "C" */
265#endif
266
267
268#endif /* WOLFSSL_EVP_H_ */
Note: See TracBrowser for help on using the repository browser.