CyaSSL 3.0.0

Dependents:   HTTPClient-SSL HTTPClient HTTPClient-SSL http_access ... more

Committer:
wolfSSL
Date:
Wed Dec 03 05:24:18 2014 +0000
Revision:
3:64d4f7cb83d5
Parent:
0:1239e9b70ca2
added IGNORE_KEY_EXTENSIONS

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 0:1239e9b70ca2 1 /* evp.h
wolfSSL 0:1239e9b70ca2 2 *
wolfSSL 0:1239e9b70ca2 3 * Copyright (C) 2013 wolfSSL Inc.
wolfSSL 0:1239e9b70ca2 4 *
wolfSSL 0:1239e9b70ca2 5 * This file is part of CyaSSL.
wolfSSL 0:1239e9b70ca2 6 *
wolfSSL 0:1239e9b70ca2 7 * CyaSSL is free software; you can redistribute it and/or modify
wolfSSL 0:1239e9b70ca2 8 * it under the terms of the GNU General Public License as published by
wolfSSL 0:1239e9b70ca2 9 * the Free Software Foundation; either version 2 of the License, or
wolfSSL 0:1239e9b70ca2 10 * (at your option) any later version.
wolfSSL 0:1239e9b70ca2 11 *
wolfSSL 0:1239e9b70ca2 12 * CyaSSL is distributed in the hope that it will be useful,
wolfSSL 0:1239e9b70ca2 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wolfSSL 0:1239e9b70ca2 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wolfSSL 0:1239e9b70ca2 15 * GNU General Public License for more details.
wolfSSL 0:1239e9b70ca2 16 *
wolfSSL 0:1239e9b70ca2 17 * You should have received a copy of the GNU General Public License
wolfSSL 0:1239e9b70ca2 18 * along with this program; if not, write to the Free Software
wolfSSL 0:1239e9b70ca2 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
wolfSSL 0:1239e9b70ca2 20 */
wolfSSL 0:1239e9b70ca2 21
wolfSSL 0:1239e9b70ca2 22
wolfSSL 0:1239e9b70ca2 23 /* evp.h defines mini evp openssl compatibility layer
wolfSSL 0:1239e9b70ca2 24 *
wolfSSL 0:1239e9b70ca2 25 */
wolfSSL 0:1239e9b70ca2 26
wolfSSL 0:1239e9b70ca2 27
wolfSSL 0:1239e9b70ca2 28 #ifndef CYASSL_EVP_H_
wolfSSL 0:1239e9b70ca2 29 #define CYASSL_EVP_H_
wolfSSL 0:1239e9b70ca2 30
wolfSSL 0:1239e9b70ca2 31 #include <cyassl/ctaocrypt/settings.h>
wolfSSL 0:1239e9b70ca2 32
wolfSSL 0:1239e9b70ca2 33 #ifdef YASSL_PREFIX
wolfSSL 0:1239e9b70ca2 34 #include "prefix_evp.h"
wolfSSL 0:1239e9b70ca2 35 #endif
wolfSSL 0:1239e9b70ca2 36
wolfSSL 0:1239e9b70ca2 37 #include <cyassl/openssl/md5.h>
wolfSSL 0:1239e9b70ca2 38 #include <cyassl/openssl/sha.h>
wolfSSL 0:1239e9b70ca2 39 #include <cyassl/openssl/ripemd.h>
wolfSSL 0:1239e9b70ca2 40 #include <cyassl/openssl/rsa.h>
wolfSSL 0:1239e9b70ca2 41 #include <cyassl/openssl/dsa.h>
wolfSSL 0:1239e9b70ca2 42
wolfSSL 0:1239e9b70ca2 43 #include <cyassl/ctaocrypt/aes.h>
wolfSSL 0:1239e9b70ca2 44 #include <cyassl/ctaocrypt/des3.h>
wolfSSL 0:1239e9b70ca2 45 #include <cyassl/ctaocrypt/arc4.h>
wolfSSL 0:1239e9b70ca2 46
wolfSSL 0:1239e9b70ca2 47
wolfSSL 0:1239e9b70ca2 48 #ifdef __cplusplus
wolfSSL 0:1239e9b70ca2 49 extern "C" {
wolfSSL 0:1239e9b70ca2 50 #endif
wolfSSL 0:1239e9b70ca2 51
wolfSSL 0:1239e9b70ca2 52 typedef char CYASSL_EVP_MD;
wolfSSL 0:1239e9b70ca2 53 typedef char CYASSL_EVP_CIPHER;
wolfSSL 0:1239e9b70ca2 54
wolfSSL 0:1239e9b70ca2 55 CYASSL_API const CYASSL_EVP_MD* CyaSSL_EVP_md5(void);
wolfSSL 0:1239e9b70ca2 56 CYASSL_API const CYASSL_EVP_MD* CyaSSL_EVP_sha1(void);
wolfSSL 0:1239e9b70ca2 57 CYASSL_API const CYASSL_EVP_MD* CyaSSL_EVP_sha256(void);
wolfSSL 0:1239e9b70ca2 58 CYASSL_API const CYASSL_EVP_MD* CyaSSL_EVP_sha384(void);
wolfSSL 0:1239e9b70ca2 59 CYASSL_API const CYASSL_EVP_MD* CyaSSL_EVP_sha512(void);
wolfSSL 0:1239e9b70ca2 60 CYASSL_API const CYASSL_EVP_MD* CyaSSL_EVP_ripemd160(void);
wolfSSL 0:1239e9b70ca2 61
wolfSSL 0:1239e9b70ca2 62 CYASSL_API const CYASSL_EVP_CIPHER* CyaSSL_EVP_aes_128_cbc(void);
wolfSSL 0:1239e9b70ca2 63 CYASSL_API const CYASSL_EVP_CIPHER* CyaSSL_EVP_aes_192_cbc(void);
wolfSSL 0:1239e9b70ca2 64 CYASSL_API const CYASSL_EVP_CIPHER* CyaSSL_EVP_aes_256_cbc(void);
wolfSSL 0:1239e9b70ca2 65 CYASSL_API const CYASSL_EVP_CIPHER* CyaSSL_EVP_aes_128_ctr(void);
wolfSSL 0:1239e9b70ca2 66 CYASSL_API const CYASSL_EVP_CIPHER* CyaSSL_EVP_aes_192_ctr(void);
wolfSSL 0:1239e9b70ca2 67 CYASSL_API const CYASSL_EVP_CIPHER* CyaSSL_EVP_aes_256_ctr(void);
wolfSSL 0:1239e9b70ca2 68 CYASSL_API const CYASSL_EVP_CIPHER* CyaSSL_EVP_des_cbc(void);
wolfSSL 0:1239e9b70ca2 69 CYASSL_API const CYASSL_EVP_CIPHER* CyaSSL_EVP_des_ede3_cbc(void);
wolfSSL 0:1239e9b70ca2 70 CYASSL_API const CYASSL_EVP_CIPHER* CyaSSL_EVP_rc4(void);
wolfSSL 0:1239e9b70ca2 71 CYASSL_API const CYASSL_EVP_CIPHER* CyaSSL_EVP_enc_null(void);
wolfSSL 0:1239e9b70ca2 72
wolfSSL 0:1239e9b70ca2 73
wolfSSL 0:1239e9b70ca2 74 typedef union {
wolfSSL 0:1239e9b70ca2 75 CYASSL_MD5_CTX md5;
wolfSSL 0:1239e9b70ca2 76 CYASSL_SHA_CTX sha;
wolfSSL 0:1239e9b70ca2 77 CYASSL_SHA256_CTX sha256;
wolfSSL 0:1239e9b70ca2 78 #ifdef CYASSL_SHA384
wolfSSL 0:1239e9b70ca2 79 CYASSL_SHA384_CTX sha384;
wolfSSL 0:1239e9b70ca2 80 #endif
wolfSSL 0:1239e9b70ca2 81 #ifdef CYASSL_SHA512
wolfSSL 0:1239e9b70ca2 82 CYASSL_SHA512_CTX sha512;
wolfSSL 0:1239e9b70ca2 83 #endif
wolfSSL 0:1239e9b70ca2 84 #ifdef CYASSL_RIPEMD
wolfSSL 0:1239e9b70ca2 85 CYASSL_RIPEMD_CTX ripemd;
wolfSSL 0:1239e9b70ca2 86 #endif
wolfSSL 0:1239e9b70ca2 87 } CYASSL_Hasher;
wolfSSL 0:1239e9b70ca2 88
wolfSSL 0:1239e9b70ca2 89
wolfSSL 0:1239e9b70ca2 90 typedef struct CYASSL_EVP_MD_CTX {
wolfSSL 0:1239e9b70ca2 91 unsigned char macType;
wolfSSL 0:1239e9b70ca2 92 CYASSL_Hasher hash;
wolfSSL 0:1239e9b70ca2 93 } CYASSL_EVP_MD_CTX;
wolfSSL 0:1239e9b70ca2 94
wolfSSL 0:1239e9b70ca2 95
wolfSSL 0:1239e9b70ca2 96 typedef union {
wolfSSL 0:1239e9b70ca2 97 Aes aes;
wolfSSL 0:1239e9b70ca2 98 #ifndef NO_DES3
wolfSSL 0:1239e9b70ca2 99 Des des;
wolfSSL 0:1239e9b70ca2 100 Des3 des3;
wolfSSL 0:1239e9b70ca2 101 #endif
wolfSSL 0:1239e9b70ca2 102 Arc4 arc4;
wolfSSL 0:1239e9b70ca2 103 } CYASSL_Cipher;
wolfSSL 0:1239e9b70ca2 104
wolfSSL 0:1239e9b70ca2 105
wolfSSL 0:1239e9b70ca2 106 enum {
wolfSSL 0:1239e9b70ca2 107 AES_128_CBC_TYPE = 1,
wolfSSL 0:1239e9b70ca2 108 AES_192_CBC_TYPE = 2,
wolfSSL 0:1239e9b70ca2 109 AES_256_CBC_TYPE = 3,
wolfSSL 0:1239e9b70ca2 110 AES_128_CTR_TYPE = 4,
wolfSSL 0:1239e9b70ca2 111 AES_192_CTR_TYPE = 5,
wolfSSL 0:1239e9b70ca2 112 AES_256_CTR_TYPE = 6,
wolfSSL 0:1239e9b70ca2 113 DES_CBC_TYPE = 7,
wolfSSL 0:1239e9b70ca2 114 DES_EDE3_CBC_TYPE = 8,
wolfSSL 0:1239e9b70ca2 115 ARC4_TYPE = 9,
wolfSSL 0:1239e9b70ca2 116 NULL_CIPHER_TYPE = 10,
wolfSSL 0:1239e9b70ca2 117 EVP_PKEY_RSA = 11,
wolfSSL 0:1239e9b70ca2 118 EVP_PKEY_DSA = 12,
wolfSSL 0:1239e9b70ca2 119 NID_sha1 = 64,
wolfSSL 0:1239e9b70ca2 120 NID_md5 = 4
wolfSSL 0:1239e9b70ca2 121 };
wolfSSL 0:1239e9b70ca2 122
wolfSSL 0:1239e9b70ca2 123
wolfSSL 0:1239e9b70ca2 124 typedef struct CYASSL_EVP_CIPHER_CTX {
wolfSSL 0:1239e9b70ca2 125 int keyLen; /* user may set for variable */
wolfSSL 0:1239e9b70ca2 126 unsigned char enc; /* if encrypt side, then true */
wolfSSL 0:1239e9b70ca2 127 unsigned char cipherType;
wolfSSL 0:1239e9b70ca2 128 unsigned char iv[AES_BLOCK_SIZE]; /* working iv pointer into cipher */
wolfSSL 0:1239e9b70ca2 129 CYASSL_Cipher cipher;
wolfSSL 0:1239e9b70ca2 130 } CYASSL_EVP_CIPHER_CTX;
wolfSSL 0:1239e9b70ca2 131
wolfSSL 0:1239e9b70ca2 132
wolfSSL 0:1239e9b70ca2 133 CYASSL_API int CyaSSL_EVP_MD_size(const CYASSL_EVP_MD* md);
wolfSSL 0:1239e9b70ca2 134 CYASSL_API void CyaSSL_EVP_MD_CTX_init(CYASSL_EVP_MD_CTX* ctx);
wolfSSL 0:1239e9b70ca2 135 CYASSL_API int CyaSSL_EVP_MD_CTX_cleanup(CYASSL_EVP_MD_CTX* ctx);
wolfSSL 0:1239e9b70ca2 136
wolfSSL 0:1239e9b70ca2 137 CYASSL_API int CyaSSL_EVP_DigestInit(CYASSL_EVP_MD_CTX* ctx,
wolfSSL 0:1239e9b70ca2 138 const CYASSL_EVP_MD* type);
wolfSSL 0:1239e9b70ca2 139 CYASSL_API int CyaSSL_EVP_DigestUpdate(CYASSL_EVP_MD_CTX* ctx, const void* data,
wolfSSL 0:1239e9b70ca2 140 unsigned long sz);
wolfSSL 0:1239e9b70ca2 141 CYASSL_API int CyaSSL_EVP_DigestFinal(CYASSL_EVP_MD_CTX* ctx, unsigned char* md,
wolfSSL 0:1239e9b70ca2 142 unsigned int* s);
wolfSSL 0:1239e9b70ca2 143 CYASSL_API int CyaSSL_EVP_DigestFinal_ex(CYASSL_EVP_MD_CTX* ctx,
wolfSSL 0:1239e9b70ca2 144 unsigned char* md, unsigned int* s);
wolfSSL 0:1239e9b70ca2 145 CYASSL_API int CyaSSL_EVP_BytesToKey(const CYASSL_EVP_CIPHER*,
wolfSSL 0:1239e9b70ca2 146 const CYASSL_EVP_MD*, const unsigned char*,
wolfSSL 0:1239e9b70ca2 147 const unsigned char*, int, int, unsigned char*,
wolfSSL 0:1239e9b70ca2 148 unsigned char*);
wolfSSL 0:1239e9b70ca2 149
wolfSSL 0:1239e9b70ca2 150 CYASSL_API void CyaSSL_EVP_CIPHER_CTX_init(CYASSL_EVP_CIPHER_CTX* ctx);
wolfSSL 0:1239e9b70ca2 151 CYASSL_API int CyaSSL_EVP_CIPHER_CTX_cleanup(CYASSL_EVP_CIPHER_CTX* ctx);
wolfSSL 0:1239e9b70ca2 152
wolfSSL 0:1239e9b70ca2 153 CYASSL_API int CyaSSL_EVP_CIPHER_CTX_iv_length(const CYASSL_EVP_CIPHER_CTX*);
wolfSSL 0:1239e9b70ca2 154
wolfSSL 0:1239e9b70ca2 155
wolfSSL 0:1239e9b70ca2 156 CYASSL_API int CyaSSL_EVP_CipherInit(CYASSL_EVP_CIPHER_CTX* ctx,
wolfSSL 0:1239e9b70ca2 157 const CYASSL_EVP_CIPHER* type,
wolfSSL 0:1239e9b70ca2 158 unsigned char* key, unsigned char* iv,
wolfSSL 0:1239e9b70ca2 159 int enc);
wolfSSL 0:1239e9b70ca2 160 CYASSL_API int CyaSSL_EVP_CIPHER_CTX_key_length(CYASSL_EVP_CIPHER_CTX* ctx);
wolfSSL 0:1239e9b70ca2 161 CYASSL_API int CyaSSL_EVP_CIPHER_CTX_set_key_length(CYASSL_EVP_CIPHER_CTX* ctx,
wolfSSL 0:1239e9b70ca2 162 int keylen);
wolfSSL 0:1239e9b70ca2 163 CYASSL_API int CyaSSL_EVP_Cipher(CYASSL_EVP_CIPHER_CTX* ctx,
wolfSSL 0:1239e9b70ca2 164 unsigned char* dst, unsigned char* src,
wolfSSL 0:1239e9b70ca2 165 unsigned int len);
wolfSSL 0:1239e9b70ca2 166
wolfSSL 0:1239e9b70ca2 167 CYASSL_API const CYASSL_EVP_MD* CyaSSL_EVP_get_digestbynid(int);
wolfSSL 0:1239e9b70ca2 168
wolfSSL 0:1239e9b70ca2 169 CYASSL_API CYASSL_RSA* CyaSSL_EVP_PKEY_get1_RSA(CYASSL_EVP_PKEY*);
wolfSSL 0:1239e9b70ca2 170 CYASSL_API CYASSL_DSA* CyaSSL_EVP_PKEY_get1_DSA(CYASSL_EVP_PKEY*);
wolfSSL 0:1239e9b70ca2 171
wolfSSL 0:1239e9b70ca2 172 /* these next ones don't need real OpenSSL type, for OpenSSH compat only */
wolfSSL 0:1239e9b70ca2 173 CYASSL_API void* CyaSSL_EVP_X_STATE(const CYASSL_EVP_CIPHER_CTX* ctx);
wolfSSL 0:1239e9b70ca2 174 CYASSL_API int CyaSSL_EVP_X_STATE_LEN(const CYASSL_EVP_CIPHER_CTX* ctx);
wolfSSL 0:1239e9b70ca2 175
wolfSSL 0:1239e9b70ca2 176 CYASSL_API void CyaSSL_3des_iv(CYASSL_EVP_CIPHER_CTX* ctx, int doset,
wolfSSL 0:1239e9b70ca2 177 unsigned char* iv, int len);
wolfSSL 0:1239e9b70ca2 178 CYASSL_API void CyaSSL_aes_ctr_iv(CYASSL_EVP_CIPHER_CTX* ctx, int doset,
wolfSSL 0:1239e9b70ca2 179 unsigned char* iv, int len);
wolfSSL 0:1239e9b70ca2 180
wolfSSL 0:1239e9b70ca2 181 CYASSL_API int CyaSSL_StoreExternalIV(CYASSL_EVP_CIPHER_CTX* ctx);
wolfSSL 0:1239e9b70ca2 182 CYASSL_API int CyaSSL_SetInternalIV(CYASSL_EVP_CIPHER_CTX* ctx);
wolfSSL 0:1239e9b70ca2 183
wolfSSL 0:1239e9b70ca2 184
wolfSSL 0:1239e9b70ca2 185 /* end OpenSSH compat */
wolfSSL 0:1239e9b70ca2 186
wolfSSL 0:1239e9b70ca2 187 typedef CYASSL_EVP_MD EVP_MD;
wolfSSL 0:1239e9b70ca2 188 typedef CYASSL_EVP_CIPHER EVP_CIPHER;
wolfSSL 0:1239e9b70ca2 189 typedef CYASSL_EVP_MD_CTX EVP_MD_CTX;
wolfSSL 0:1239e9b70ca2 190 typedef CYASSL_EVP_CIPHER_CTX EVP_CIPHER_CTX;
wolfSSL 0:1239e9b70ca2 191
wolfSSL 0:1239e9b70ca2 192 #define EVP_md5 CyaSSL_EVP_md5
wolfSSL 0:1239e9b70ca2 193 #define EVP_sha1 CyaSSL_EVP_sha1
wolfSSL 0:1239e9b70ca2 194 #define EVP_sha256 CyaSSL_EVP_sha256
wolfSSL 0:1239e9b70ca2 195 #define EVP_sha384 CyaSSL_EVP_sha384
wolfSSL 0:1239e9b70ca2 196 #define EVP_sha512 CyaSSL_EVP_sha512
wolfSSL 0:1239e9b70ca2 197 #define EVP_ripemd160 CyaSSL_EVP_ripemd160
wolfSSL 0:1239e9b70ca2 198
wolfSSL 0:1239e9b70ca2 199 #define EVP_aes_128_cbc CyaSSL_EVP_aes_128_cbc
wolfSSL 0:1239e9b70ca2 200 #define EVP_aes_192_cbc CyaSSL_EVP_aes_192_cbc
wolfSSL 0:1239e9b70ca2 201 #define EVP_aes_256_cbc CyaSSL_EVP_aes_256_cbc
wolfSSL 0:1239e9b70ca2 202 #define EVP_aes_128_ctr CyaSSL_EVP_aes_128_ctr
wolfSSL 0:1239e9b70ca2 203 #define EVP_aes_192_ctr CyaSSL_EVP_aes_192_ctr
wolfSSL 0:1239e9b70ca2 204 #define EVP_aes_256_ctr CyaSSL_EVP_aes_256_ctr
wolfSSL 0:1239e9b70ca2 205 #define EVP_des_cbc CyaSSL_EVP_des_cbc
wolfSSL 0:1239e9b70ca2 206 #define EVP_des_ede3_cbc CyaSSL_EVP_des_ede3_cbc
wolfSSL 0:1239e9b70ca2 207 #define EVP_rc4 CyaSSL_EVP_rc4
wolfSSL 0:1239e9b70ca2 208 #define EVP_enc_null CyaSSL_EVP_enc_null
wolfSSL 0:1239e9b70ca2 209
wolfSSL 0:1239e9b70ca2 210 #define EVP_MD_size CyaSSL_EVP_MD_size
wolfSSL 0:1239e9b70ca2 211 #define EVP_MD_CTX_init CyaSSL_EVP_MD_CTX_init
wolfSSL 0:1239e9b70ca2 212 #define EVP_MD_CTX_cleanup CyaSSL_EVP_MD_CTX_cleanup
wolfSSL 0:1239e9b70ca2 213 #define EVP_DigestInit CyaSSL_EVP_DigestInit
wolfSSL 0:1239e9b70ca2 214 #define EVP_DigestUpdate CyaSSL_EVP_DigestUpdate
wolfSSL 0:1239e9b70ca2 215 #define EVP_DigestFinal CyaSSL_EVP_DigestFinal
wolfSSL 0:1239e9b70ca2 216 #define EVP_DigestFinal_ex CyaSSL_EVP_DigestFinal_ex
wolfSSL 0:1239e9b70ca2 217 #define EVP_BytesToKey CyaSSL_EVP_BytesToKey
wolfSSL 0:1239e9b70ca2 218
wolfSSL 0:1239e9b70ca2 219 #define EVP_CIPHER_CTX_init CyaSSL_EVP_CIPHER_CTX_init
wolfSSL 0:1239e9b70ca2 220 #define EVP_CIPHER_CTX_cleanup CyaSSL_EVP_CIPHER_CTX_cleanup
wolfSSL 0:1239e9b70ca2 221 #define EVP_CIPHER_CTX_iv_length CyaSSL_EVP_CIPHER_CTX_iv_length
wolfSSL 0:1239e9b70ca2 222 #define EVP_CIPHER_CTX_key_length CyaSSL_EVP_CIPHER_CTX_key_length
wolfSSL 0:1239e9b70ca2 223 #define EVP_CIPHER_CTX_set_key_length CyaSSL_EVP_CIPHER_CTX_set_key_length
wolfSSL 0:1239e9b70ca2 224 #define EVP_CipherInit CyaSSL_EVP_CipherInit
wolfSSL 0:1239e9b70ca2 225 #define EVP_Cipher CyaSSL_EVP_Cipher
wolfSSL 0:1239e9b70ca2 226
wolfSSL 0:1239e9b70ca2 227 #define EVP_get_digestbynid CyaSSL_EVP_get_digestbynid
wolfSSL 0:1239e9b70ca2 228
wolfSSL 0:1239e9b70ca2 229 #define EVP_PKEY_get1_RSA CyaSSL_EVP_PKEY_get1_RSA
wolfSSL 0:1239e9b70ca2 230 #define EVP_PKEY_get1_DSA CyaSSL_EVP_PKEY_get1_DSA
wolfSSL 0:1239e9b70ca2 231
wolfSSL 0:1239e9b70ca2 232 #ifndef EVP_MAX_MD_SIZE
wolfSSL 0:1239e9b70ca2 233 #define EVP_MAX_MD_SIZE 64 /* sha512 */
wolfSSL 0:1239e9b70ca2 234 #endif
wolfSSL 0:1239e9b70ca2 235
wolfSSL 0:1239e9b70ca2 236 #ifdef __cplusplus
wolfSSL 0:1239e9b70ca2 237 } /* extern "C" */
wolfSSL 0:1239e9b70ca2 238 #endif
wolfSSL 0:1239e9b70ca2 239
wolfSSL 0:1239e9b70ca2 240
wolfSSL 0:1239e9b70ca2 241 #endif /* CYASSL_EVP_H_ */
wolfSSL 0:1239e9b70ca2 242