SSL/TLS Library

Dependents:  

CyaSSL is SSL/TLS library for embedded systems.

wolfssl.com

Committer:
wolfSSL
Date:
Sun Apr 20 12:40:57 2014 +0000
Revision:
0:9d17e4342598
CyaSSL SSL/TLS Library 2.9.4;

Who changed what in which revision?

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