A library for setting up Secure Socket Layer (SSL) connections and verifying remote hosts using certificates. Contains only the source files for mbed platform implementation of the library.

Dependents:   HTTPClient-SSL HTTPClient-SSL HTTPClient-SSL HTTPClient-SSL

Committer:
Mike Fiore
Date:
Mon Mar 23 16:51:07 2015 -0500
Revision:
6:cf58d49e1a86
Parent:
0:b86d15c6ba29
fix whitespace in sha512.c

Who changed what in which revision?

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