This is a port of cyaSSL 2.7.0.
Dependents: CyaSSL_DTLS_Cellular CyaSSL_DTLS_Ethernet
evp.h
00001 /* evp.h 00002 * 00003 * Copyright (C) 2013 wolfSSL Inc. 00004 * 00005 * This file is part of CyaSSL. 00006 * 00007 * CyaSSL is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * CyaSSL is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 00020 */ 00021 00022 00023 /* evp.h defines mini evp openssl compatibility layer 00024 * 00025 */ 00026 00027 00028 #ifndef CYASSL_EVP_H_ 00029 #define CYASSL_EVP_H_ 00030 00031 #include <cyassl/ctaocrypt/settings.h> 00032 00033 #ifdef YASSL_PREFIX 00034 #include "prefix_evp.h" 00035 #endif 00036 00037 #include <cyassl/openssl/md5.h> 00038 #include <cyassl/openssl/sha.h> 00039 #include <cyassl/openssl/ripemd.h> 00040 #include <cyassl/openssl/rsa.h> 00041 #include <cyassl/openssl/dsa.h> 00042 00043 #include <cyassl/ctaocrypt/aes.h> 00044 #include <cyassl/ctaocrypt/des3.h> 00045 #include <cyassl/ctaocrypt/arc4.h> 00046 00047 00048 #ifdef __cplusplus 00049 extern "C" { 00050 #endif 00051 00052 typedef char CYASSL_EVP_MD; 00053 typedef char CYASSL_EVP_CIPHER; 00054 00055 CYASSL_API const CYASSL_EVP_MD* CyaSSL_EVP_md5(void); 00056 CYASSL_API const CYASSL_EVP_MD* CyaSSL_EVP_sha1(void); 00057 CYASSL_API const CYASSL_EVP_MD* CyaSSL_EVP_sha256(void); 00058 CYASSL_API const CYASSL_EVP_MD* CyaSSL_EVP_sha384(void); 00059 CYASSL_API const CYASSL_EVP_MD* CyaSSL_EVP_sha512(void); 00060 CYASSL_API const CYASSL_EVP_MD* CyaSSL_EVP_ripemd160(void); 00061 00062 CYASSL_API const CYASSL_EVP_CIPHER* CyaSSL_EVP_aes_128_cbc(void); 00063 CYASSL_API const CYASSL_EVP_CIPHER* CyaSSL_EVP_aes_192_cbc(void); 00064 CYASSL_API const CYASSL_EVP_CIPHER* CyaSSL_EVP_aes_256_cbc(void); 00065 CYASSL_API const CYASSL_EVP_CIPHER* CyaSSL_EVP_aes_128_ctr(void); 00066 CYASSL_API const CYASSL_EVP_CIPHER* CyaSSL_EVP_aes_192_ctr(void); 00067 CYASSL_API const CYASSL_EVP_CIPHER* CyaSSL_EVP_aes_256_ctr(void); 00068 CYASSL_API const CYASSL_EVP_CIPHER* CyaSSL_EVP_des_cbc(void); 00069 CYASSL_API const CYASSL_EVP_CIPHER* CyaSSL_EVP_des_ede3_cbc(void); 00070 CYASSL_API const CYASSL_EVP_CIPHER* CyaSSL_EVP_rc4(void); 00071 CYASSL_API const CYASSL_EVP_CIPHER* CyaSSL_EVP_enc_null(void); 00072 00073 00074 typedef union { 00075 CYASSL_MD5_CTX md5; 00076 CYASSL_SHA_CTX sha; 00077 CYASSL_SHA256_CTX sha256; 00078 #ifdef CYASSL_SHA384 00079 CYASSL_SHA384_CTX sha384; 00080 #endif 00081 #ifdef CYASSL_SHA512 00082 CYASSL_SHA512_CTX sha512; 00083 #endif 00084 #ifdef CYASSL_RIPEMD 00085 CYASSL_RIPEMD_CTX ripemd; 00086 #endif 00087 } CYASSL_Hasher; 00088 00089 00090 typedef struct CYASSL_EVP_MD_CTX { 00091 unsigned char macType; 00092 CYASSL_Hasher hash; 00093 } CYASSL_EVP_MD_CTX; 00094 00095 00096 typedef union { 00097 Aes aes; 00098 #ifndef NO_DES3 00099 Des des; 00100 Des3 des3; 00101 #endif 00102 Arc4 arc4; 00103 } CYASSL_Cipher; 00104 00105 00106 enum { 00107 AES_128_CBC_TYPE = 1, 00108 AES_192_CBC_TYPE = 2, 00109 AES_256_CBC_TYPE = 3, 00110 AES_128_CTR_TYPE = 4, 00111 AES_192_CTR_TYPE = 5, 00112 AES_256_CTR_TYPE = 6, 00113 DES_CBC_TYPE = 7, 00114 DES_EDE3_CBC_TYPE = 8, 00115 ARC4_TYPE = 9, 00116 NULL_CIPHER_TYPE = 10, 00117 EVP_PKEY_RSA = 11, 00118 EVP_PKEY_DSA = 12, 00119 NID_sha1 = 64, 00120 NID_md5 = 4 00121 }; 00122 00123 00124 typedef struct CYASSL_EVP_CIPHER_CTX { 00125 int keyLen; /* user may set for variable */ 00126 unsigned char enc; /* if encrypt side, then true */ 00127 unsigned char cipherType; 00128 unsigned char iv[AES_BLOCK_SIZE]; /* working iv pointer into cipher */ 00129 CYASSL_Cipher cipher; 00130 } CYASSL_EVP_CIPHER_CTX; 00131 00132 00133 CYASSL_API int CyaSSL_EVP_MD_size(const CYASSL_EVP_MD* md); 00134 CYASSL_API void CyaSSL_EVP_MD_CTX_init(CYASSL_EVP_MD_CTX* ctx); 00135 CYASSL_API int CyaSSL_EVP_MD_CTX_cleanup(CYASSL_EVP_MD_CTX* ctx); 00136 00137 CYASSL_API int CyaSSL_EVP_DigestInit(CYASSL_EVP_MD_CTX* ctx, 00138 const CYASSL_EVP_MD* type); 00139 CYASSL_API int CyaSSL_EVP_DigestUpdate(CYASSL_EVP_MD_CTX* ctx, const void* data, 00140 unsigned long sz); 00141 CYASSL_API int CyaSSL_EVP_DigestFinal(CYASSL_EVP_MD_CTX* ctx, unsigned char* md, 00142 unsigned int* s); 00143 CYASSL_API int CyaSSL_EVP_DigestFinal_ex(CYASSL_EVP_MD_CTX* ctx, 00144 unsigned char* md, unsigned int* s); 00145 CYASSL_API int CyaSSL_EVP_BytesToKey(const CYASSL_EVP_CIPHER*, 00146 const CYASSL_EVP_MD*, const unsigned char*, 00147 const unsigned char*, int, int, unsigned char*, 00148 unsigned char*); 00149 00150 CYASSL_API void CyaSSL_EVP_CIPHER_CTX_init(CYASSL_EVP_CIPHER_CTX* ctx); 00151 CYASSL_API int CyaSSL_EVP_CIPHER_CTX_cleanup(CYASSL_EVP_CIPHER_CTX* ctx); 00152 00153 CYASSL_API int CyaSSL_EVP_CIPHER_CTX_iv_length(const CYASSL_EVP_CIPHER_CTX*); 00154 00155 00156 CYASSL_API int CyaSSL_EVP_CipherInit(CYASSL_EVP_CIPHER_CTX* ctx, 00157 const CYASSL_EVP_CIPHER* type, 00158 unsigned char* key, unsigned char* iv, 00159 int enc); 00160 CYASSL_API int CyaSSL_EVP_CIPHER_CTX_key_length(CYASSL_EVP_CIPHER_CTX* ctx); 00161 CYASSL_API int CyaSSL_EVP_CIPHER_CTX_set_key_length(CYASSL_EVP_CIPHER_CTX* ctx, 00162 int keylen); 00163 CYASSL_API int CyaSSL_EVP_Cipher(CYASSL_EVP_CIPHER_CTX* ctx, 00164 unsigned char* dst, unsigned char* src, 00165 unsigned int len); 00166 00167 CYASSL_API const CYASSL_EVP_MD* CyaSSL_EVP_get_digestbynid(int); 00168 00169 CYASSL_API CYASSL_RSA* CyaSSL_EVP_PKEY_get1_RSA(CYASSL_EVP_PKEY*); 00170 CYASSL_API CYASSL_DSA* CyaSSL_EVP_PKEY_get1_DSA(CYASSL_EVP_PKEY*); 00171 00172 /* these next ones don't need real OpenSSL type, for OpenSSH compat only */ 00173 CYASSL_API void* CyaSSL_EVP_X_STATE(const CYASSL_EVP_CIPHER_CTX* ctx); 00174 CYASSL_API int CyaSSL_EVP_X_STATE_LEN(const CYASSL_EVP_CIPHER_CTX* ctx); 00175 00176 CYASSL_API void CyaSSL_3des_iv(CYASSL_EVP_CIPHER_CTX* ctx, int doset, 00177 unsigned char* iv, int len); 00178 CYASSL_API void CyaSSL_aes_ctr_iv(CYASSL_EVP_CIPHER_CTX* ctx, int doset, 00179 unsigned char* iv, int len); 00180 00181 CYASSL_API int CyaSSL_StoreExternalIV(CYASSL_EVP_CIPHER_CTX* ctx); 00182 CYASSL_API int CyaSSL_SetInternalIV(CYASSL_EVP_CIPHER_CTX* ctx); 00183 00184 00185 /* end OpenSSH compat */ 00186 00187 typedef CYASSL_EVP_MD EVP_MD; 00188 typedef CYASSL_EVP_CIPHER EVP_CIPHER; 00189 typedef CYASSL_EVP_MD_CTX EVP_MD_CTX; 00190 typedef CYASSL_EVP_CIPHER_CTX EVP_CIPHER_CTX; 00191 00192 #define EVP_md5 CyaSSL_EVP_md5 00193 #define EVP_sha1 CyaSSL_EVP_sha1 00194 #define EVP_sha256 CyaSSL_EVP_sha256 00195 #define EVP_sha384 CyaSSL_EVP_sha384 00196 #define EVP_sha512 CyaSSL_EVP_sha512 00197 #define EVP_ripemd160 CyaSSL_EVP_ripemd160 00198 00199 #define EVP_aes_128_cbc CyaSSL_EVP_aes_128_cbc 00200 #define EVP_aes_192_cbc CyaSSL_EVP_aes_192_cbc 00201 #define EVP_aes_256_cbc CyaSSL_EVP_aes_256_cbc 00202 #define EVP_aes_128_ctr CyaSSL_EVP_aes_128_ctr 00203 #define EVP_aes_192_ctr CyaSSL_EVP_aes_192_ctr 00204 #define EVP_aes_256_ctr CyaSSL_EVP_aes_256_ctr 00205 #define EVP_des_cbc CyaSSL_EVP_des_cbc 00206 #define EVP_des_ede3_cbc CyaSSL_EVP_des_ede3_cbc 00207 #define EVP_rc4 CyaSSL_EVP_rc4 00208 #define EVP_enc_null CyaSSL_EVP_enc_null 00209 00210 #define EVP_MD_size CyaSSL_EVP_MD_size 00211 #define EVP_MD_CTX_init CyaSSL_EVP_MD_CTX_init 00212 #define EVP_MD_CTX_cleanup CyaSSL_EVP_MD_CTX_cleanup 00213 #define EVP_DigestInit CyaSSL_EVP_DigestInit 00214 #define EVP_DigestUpdate CyaSSL_EVP_DigestUpdate 00215 #define EVP_DigestFinal CyaSSL_EVP_DigestFinal 00216 #define EVP_DigestFinal_ex CyaSSL_EVP_DigestFinal_ex 00217 #define EVP_BytesToKey CyaSSL_EVP_BytesToKey 00218 00219 #define EVP_CIPHER_CTX_init CyaSSL_EVP_CIPHER_CTX_init 00220 #define EVP_CIPHER_CTX_cleanup CyaSSL_EVP_CIPHER_CTX_cleanup 00221 #define EVP_CIPHER_CTX_iv_length CyaSSL_EVP_CIPHER_CTX_iv_length 00222 #define EVP_CIPHER_CTX_key_length CyaSSL_EVP_CIPHER_CTX_key_length 00223 #define EVP_CIPHER_CTX_set_key_length CyaSSL_EVP_CIPHER_CTX_set_key_length 00224 #define EVP_CipherInit CyaSSL_EVP_CipherInit 00225 #define EVP_Cipher CyaSSL_EVP_Cipher 00226 00227 #define EVP_get_digestbynid CyaSSL_EVP_get_digestbynid 00228 00229 #define EVP_PKEY_get1_RSA CyaSSL_EVP_PKEY_get1_RSA 00230 #define EVP_PKEY_get1_DSA CyaSSL_EVP_PKEY_get1_DSA 00231 00232 #ifndef EVP_MAX_MD_SIZE 00233 #define EVP_MAX_MD_SIZE 64 /* sha512 */ 00234 #endif 00235 00236 #ifdef __cplusplus 00237 } /* extern "C" */ 00238 #endif 00239 00240 00241 #endif /* CYASSL_EVP_H_ */
Generated on Tue Jul 12 2022 20:44:50 by 1.7.2