55 #if !defined(OPENSSL_NO_AES) && !defined(OPENSSL_NO_SHA1)
63 #ifndef EVP_CIPH_FLAG_AEAD_CIPHER
64 #define EVP_CIPH_FLAG_AEAD_CIPHER 0x200000
65 #define EVP_CTRL_AEAD_TLS1_AAD 0x16
66 #define EVP_CTRL_AEAD_SET_MAC_KEY 0x17
69 #if !defined(EVP_CIPH_FLAG_DEFAULT_ASN1)
70 #define EVP_CIPH_FLAG_DEFAULT_ASN1 0
73 #define TLS1_1_VERSION 0x0302
82 unsigned char tls_aad[16];
86 #define NO_PAYLOAD_LENGTH ((size_t)-1)
88 #if defined(AES_ASM) && ( \
89 defined(__x86_64) || defined(__x86_64__) || \
90 defined(_M_AMD64) || defined(_M_X64) || \
94 #define AESNI_CAPABLE (1<<(57-32))
96 int aesni_set_encrypt_key(
const unsigned char *userKey,
int bits,
98 int aesni_set_decrypt_key(
const unsigned char *userKey,
int bits,
101 void aesni_cbc_encrypt(
const unsigned char *in,
105 unsigned char *ivec,
int enc);
107 void aesni_cbc_sha1_enc (
const void *inp,
void *out,
size_t blocks,
111 #define data(ctx) ((EVP_AES_HMAC_SHA1 *)(ctx)->cipher_data)
114 const unsigned char *inkey,
115 const unsigned char *iv,
int enc)
121 ret=aesni_set_encrypt_key(inkey,ctx->
key_len*8,&key->
ks);
123 ret=aesni_set_decrypt_key(inkey,ctx->
key_len*8,&key->
ks);
134 #define STITCHED_CALL
136 #if !defined(STITCHED_CALL)
140 void sha1_block_data_order (
void *c,
const void *
p,
size_t len);
143 {
const unsigned char *
ptr =
data;
146 if ((res = c->
num)) {
148 if (len<res) res=
len;
163 if (c->
Nl<(
unsigned int)len) c->
Nh++;
170 #define SHA1_Update sha1_update
172 static int aesni_cbc_hmac_sha1_cipher(
EVP_CIPHER_CTX *ctx,
unsigned char *out,
173 const unsigned char *in,
size_t len)
180 #if defined(STITCHED_CALL)
197 #if defined(STITCHED_CALL)
198 if (plen>(sha_off+iv) && (blocks=(plen-(sha_off+iv))/
SHA_CBLOCK)) {
201 aesni_cbc_sha1_enc(in,out,blocks,&key->
ks,
202 ctx->
iv,&key->
md,in+iv+sha_off);
206 key->
md.
Nh += blocks>>29;
207 key->
md.
Nl += blocks<<=3;
208 if (key->
md.
Nl<(
unsigned int)blocks) key->
md.
Nh++;
218 memcpy(out+aes_off,in+aes_off,plen-aes_off);
228 for (l=len-plen-1;plen<
len;plen++) out[plen]=l;
230 aesni_cbc_encrypt(out+aes_off,out+aes_off,len-aes_off,
233 aesni_cbc_encrypt(in+aes_off,out+aes_off,len-aes_off,
240 aesni_cbc_encrypt(in,out,len,
290 unsigned char hmac_key[64];
292 memset (hmac_key,0,
sizeof(hmac_key));
294 if (arg > (
int)
sizeof(hmac_key)) {
299 memcpy(hmac_key,ptr,arg);
302 for (i=0;i<
sizeof(hmac_key);i++)
307 for (i=0;i<
sizeof(hmac_key);i++)
308 hmac_key[i] ^= 0x36^0x5c;
316 unsigned char *
p=
ptr;
317 unsigned int len=p[arg-2]<<8|p[arg-1];
335 if (arg>13) arg = 13;
347 static EVP_CIPHER aesni_128_cbc_hmac_sha1_cipher =
349 #ifdef NID_aes_128_cbc_hmac_sha1
356 aesni_cbc_hmac_sha1_init_key,
357 aesni_cbc_hmac_sha1_cipher,
362 aesni_cbc_hmac_sha1_ctrl,
366 static EVP_CIPHER aesni_256_cbc_hmac_sha1_cipher =
368 #ifdef NID_aes_256_cbc_hmac_sha1
375 aesni_cbc_hmac_sha1_init_key,
376 aesni_cbc_hmac_sha1_cipher,
381 aesni_cbc_hmac_sha1_ctrl,
387 return(OPENSSL_ia32cap_P[1]&AESNI_CAPABLE?
388 &aesni_128_cbc_hmac_sha1_cipher:NULL);
393 return(OPENSSL_ia32cap_P[1]&AESNI_CAPABLE?
394 &aesni_256_cbc_hmac_sha1_cipher:NULL);