evp/e_aes_cbc_hmac_sha256.c: enable is on all AES-NI platforms, not only on AVX.
[openssl.git] / crypto / evp / e_aes_cbc_hmac_sha256.c
1 /* ====================================================================
2  * Copyright (c) 2011-2013 The OpenSSL Project.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in
13  *    the documentation and/or other materials provided with the
14  *    distribution.
15  *
16  * 3. All advertising materials mentioning features or use of this
17  *    software must display the following acknowledgment:
18  *    "This product includes software developed by the OpenSSL Project
19  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20  *
21  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22  *    endorse or promote products derived from this software without
23  *    prior written permission. For written permission, please contact
24  *    licensing@OpenSSL.org.
25  *
26  * 5. Products derived from this software may not be called "OpenSSL"
27  *    nor may "OpenSSL" appear in their names without prior written
28  *    permission of the OpenSSL Project.
29  *
30  * 6. Redistributions of any form whatsoever must retain the following
31  *    acknowledgment:
32  *    "This product includes software developed by the OpenSSL Project
33  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34  *
35  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
39  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46  * OF THE POSSIBILITY OF SUCH DAMAGE.
47  * ====================================================================
48  */
49
50 #include <openssl/opensslconf.h>
51
52 #include <stdio.h>
53 #include <string.h>
54
55 #if !defined(OPENSSL_NO_AES) && !defined(OPENSSL_NO_SHA256)
56
57 #include <openssl/evp.h>
58 #include <openssl/objects.h>
59 #include <openssl/aes.h>
60 #include <openssl/sha.h>
61
62 #ifndef EVP_CIPH_FLAG_AEAD_CIPHER
63 #define EVP_CIPH_FLAG_AEAD_CIPHER       0x200000
64 #define EVP_CTRL_AEAD_TLS1_AAD          0x16
65 #define EVP_CTRL_AEAD_SET_MAC_KEY       0x17
66 #endif
67
68 #if !defined(EVP_CIPH_FLAG_DEFAULT_ASN1)
69 #define EVP_CIPH_FLAG_DEFAULT_ASN1 0
70 #endif
71
72 #define TLS1_1_VERSION 0x0302
73
74 typedef struct
75     {
76     AES_KEY             ks;
77     SHA256_CTX          head,tail,md;
78     size_t              payload_length; /* AAD length in decrypt case */
79     union {
80         unsigned int    tls_ver;
81         unsigned char   tls_aad[16];    /* 13 used */
82     } aux;
83     } EVP_AES_HMAC_SHA256;
84
85 #define NO_PAYLOAD_LENGTH       ((size_t)-1)
86
87 #if     defined(AES_ASM) &&     ( \
88         defined(__x86_64)       || defined(__x86_64__)  || \
89         defined(_M_AMD64)       || defined(_M_X64)      || \
90         defined(__INTEL__)      )
91
92 #if defined(__GNUC__) && __GNUC__>=2 && !defined(PEDANTIC)
93 # define BSWAP(x) ({ unsigned int r=(x); asm ("bswapl %0":"=r"(r):"0"(r)); r; })
94 #endif
95
96 extern unsigned int OPENSSL_ia32cap_P[3];
97 #define AESNI_CAPABLE   (1<<(57-32))
98
99 int aesni_set_encrypt_key(const unsigned char *userKey, int bits,
100                               AES_KEY *key);
101 int aesni_set_decrypt_key(const unsigned char *userKey, int bits,
102                               AES_KEY *key);
103
104 void aesni_cbc_encrypt(const unsigned char *in,
105                            unsigned char *out,
106                            size_t length,
107                            const AES_KEY *key,
108                            unsigned char *ivec, int enc);
109
110 int aesni_cbc_sha256_enc (const void *inp, void *out, size_t blocks,
111                 const AES_KEY *key, unsigned char iv[16],
112                 SHA256_CTX *ctx,const void *in0);
113
114 #define data(ctx) ((EVP_AES_HMAC_SHA256 *)(ctx)->cipher_data)
115
116 static int aesni_cbc_hmac_sha256_init_key(EVP_CIPHER_CTX *ctx,
117                         const unsigned char *inkey,
118                         const unsigned char *iv, int enc)
119         {
120         EVP_AES_HMAC_SHA256 *key = data(ctx);
121         int ret;
122
123         if (enc)
124                 memset(&key->ks,0,sizeof(key->ks.rd_key)),
125                 ret=aesni_set_encrypt_key(inkey,ctx->key_len*8,&key->ks);
126         else
127                 ret=aesni_set_decrypt_key(inkey,ctx->key_len*8,&key->ks);
128
129         SHA256_Init(&key->head);        /* handy when benchmarking */
130         key->tail = key->head;
131         key->md   = key->head;
132
133         key->payload_length = NO_PAYLOAD_LENGTH;
134
135         return ret<0?0:1;
136         }
137
138 #define STITCHED_CALL
139
140 #if !defined(STITCHED_CALL)
141 #define aes_off 0
142 #endif
143
144 void sha256_block_data_order (void *c,const void *p,size_t len);
145
146 static void sha256_update(SHA256_CTX *c,const void *data,size_t len)
147 {       const unsigned char *ptr = data;
148         size_t res;
149
150         if ((res = c->num)) {
151                 res = SHA256_CBLOCK-res;
152                 if (len<res) res=len;
153                 SHA256_Update (c,ptr,res);
154                 ptr += res;
155                 len -= res;
156         }
157
158         res = len % SHA256_CBLOCK;
159         len -= res;
160
161         if (len) {
162                 sha256_block_data_order(c,ptr,len/SHA256_CBLOCK);
163
164                 ptr += len;
165                 c->Nh += len>>29;
166                 c->Nl += len<<=3;
167                 if (c->Nl<(unsigned int)len) c->Nh++;
168         }
169
170         if (res)
171                 SHA256_Update(c,ptr,res);
172 }
173
174 #ifdef SHA256_Update
175 #undef SHA256_Update
176 #endif
177 #define SHA256_Update sha256_update
178
179 static int aesni_cbc_hmac_sha256_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
180                       const unsigned char *in, size_t len)
181         {
182         EVP_AES_HMAC_SHA256 *key = data(ctx);
183         unsigned int l;
184         size_t  plen = key->payload_length,
185                 iv = 0,         /* explicit IV in TLS 1.1 and later */
186                 sha_off = 0;
187 #if defined(STITCHED_CALL)
188         size_t  aes_off = 0,
189                 blocks;
190
191         sha_off = SHA256_CBLOCK-key->md.num;
192 #endif
193
194         key->payload_length = NO_PAYLOAD_LENGTH;
195
196         if (len%AES_BLOCK_SIZE) return 0;
197
198         if (ctx->encrypt) {
199                 if (plen==NO_PAYLOAD_LENGTH)
200                         plen = len;
201                 else if (len!=((plen+SHA256_DIGEST_LENGTH+AES_BLOCK_SIZE)&-AES_BLOCK_SIZE))
202                         return 0;
203                 else if (key->aux.tls_ver >= TLS1_1_VERSION)
204                         iv = AES_BLOCK_SIZE;
205
206 #if defined(STITCHED_CALL)
207                 if (OPENSSL_ia32cap_P[1]&(1<<(60-32)) &&
208                     plen>(sha_off+iv) &&
209                     (blocks=(plen-(sha_off+iv))/SHA256_CBLOCK)) {
210                         SHA256_Update(&key->md,in+iv,sha_off);
211
212                         (void)aesni_cbc_sha256_enc(in,out,blocks,&key->ks,
213                                 ctx->iv,&key->md,in+iv+sha_off);
214                         blocks *= SHA256_CBLOCK;
215                         aes_off += blocks;
216                         sha_off += blocks;
217                         key->md.Nh += blocks>>29;
218                         key->md.Nl += blocks<<=3;
219                         if (key->md.Nl<(unsigned int)blocks) key->md.Nh++;
220                 } else {
221                         sha_off = 0;
222                 }
223 #endif
224                 sha_off += iv;
225                 SHA256_Update(&key->md,in+sha_off,plen-sha_off);
226
227                 if (plen!=len)  {       /* "TLS" mode of operation */
228                         if (in!=out)
229                                 memcpy(out+aes_off,in+aes_off,plen-aes_off);
230
231                         /* calculate HMAC and append it to payload */
232                         SHA256_Final(out+plen,&key->md);
233                         key->md = key->tail;
234                         SHA256_Update(&key->md,out+plen,SHA256_DIGEST_LENGTH);
235                         SHA256_Final(out+plen,&key->md);
236
237                         /* pad the payload|hmac */
238                         plen += SHA256_DIGEST_LENGTH;
239                         for (l=len-plen-1;plen<len;plen++) out[plen]=l;
240                         /* encrypt HMAC|padding at once */
241                         aesni_cbc_encrypt(out+aes_off,out+aes_off,len-aes_off,
242                                         &key->ks,ctx->iv,1);
243                 } else {
244                         aesni_cbc_encrypt(in+aes_off,out+aes_off,len-aes_off,
245                                         &key->ks,ctx->iv,1);
246                 }
247         } else {
248                 union { unsigned int  u[SHA256_DIGEST_LENGTH/sizeof(unsigned int)];
249                         unsigned char c[64+SHA256_DIGEST_LENGTH]; } mac, *pmac;
250
251                 /* arrange cache line alignment */
252                 pmac = (void *)(((size_t)mac.c+63)&((size_t)0-64));
253
254                 /* decrypt HMAC|padding at once */
255                 aesni_cbc_encrypt(in,out,len,
256                                 &key->ks,ctx->iv,0);
257
258                 if (plen) {     /* "TLS" mode of operation */
259                         size_t inp_len, mask, j, i;
260                         unsigned int res, maxpad, pad, bitlen;
261                         int ret = 1;
262                         union { unsigned int  u[SHA_LBLOCK];
263                                 unsigned char c[SHA256_CBLOCK]; }
264                                 *data = (void *)key->md.data;
265
266                         if ((key->aux.tls_aad[plen-4]<<8|key->aux.tls_aad[plen-3])
267                             >= TLS1_1_VERSION)
268                                 iv = AES_BLOCK_SIZE;
269
270                         if (len<(iv+SHA256_DIGEST_LENGTH+1))
271                                 return 0;
272
273                         /* omit explicit iv */
274                         out += iv;
275                         len -= iv;
276
277                         /* figure out payload length */
278                         pad = out[len-1];
279                         maxpad = len-(SHA256_DIGEST_LENGTH+1);
280                         maxpad |= (255-maxpad)>>(sizeof(maxpad)*8-8);
281                         maxpad &= 255;
282
283                         inp_len = len - (SHA256_DIGEST_LENGTH+pad+1);
284                         mask = (0-((inp_len-len)>>(sizeof(inp_len)*8-1)));
285                         inp_len &= mask;
286                         ret &= (int)mask;
287
288                         key->aux.tls_aad[plen-2] = inp_len>>8;
289                         key->aux.tls_aad[plen-1] = inp_len;
290
291                         /* calculate HMAC */
292                         key->md = key->head;
293                         SHA256_Update(&key->md,key->aux.tls_aad,plen);
294
295 #if 1
296                         len -= SHA256_DIGEST_LENGTH;            /* amend mac */
297                         if (len>=(256+SHA256_CBLOCK)) {
298                                 j = (len-(256+SHA256_CBLOCK))&(0-SHA256_CBLOCK);
299                                 j += SHA256_CBLOCK-key->md.num;
300                                 SHA256_Update(&key->md,out,j);
301                                 out += j;
302                                 len -= j;
303                                 inp_len -= j;
304                         }
305
306                         /* but pretend as if we hashed padded payload */
307                         bitlen = key->md.Nl+(inp_len<<3);       /* at most 18 bits */
308 #ifdef BSWAP
309                         bitlen = BSWAP(bitlen);
310 #else
311                         mac.c[0] = 0;
312                         mac.c[1] = (unsigned char)(bitlen>>16);
313                         mac.c[2] = (unsigned char)(bitlen>>8);
314                         mac.c[3] = (unsigned char)bitlen;
315                         bitlen = mac.u[0];
316 #endif
317
318                         pmac->u[0]=0;
319                         pmac->u[1]=0;
320                         pmac->u[2]=0;
321                         pmac->u[3]=0;
322                         pmac->u[4]=0;
323                         pmac->u[5]=0;
324                         pmac->u[6]=0;
325                         pmac->u[7]=0;
326
327                         for (res=key->md.num, j=0;j<len;j++) {
328                                 size_t c = out[j];
329                                 mask = (j-inp_len)>>(sizeof(j)*8-8);
330                                 c &= mask;
331                                 c |= 0x80&~mask&~((inp_len-j)>>(sizeof(j)*8-8));
332                                 data->c[res++]=(unsigned char)c;
333
334                                 if (res!=SHA256_CBLOCK) continue;
335
336                                 /* j is not incremented yet */
337                                 mask = 0-((inp_len+7-j)>>(sizeof(j)*8-1));
338                                 data->u[SHA_LBLOCK-1] |= bitlen&mask;
339                                 sha256_block_data_order(&key->md,data,1);
340                                 mask &= 0-((j-inp_len-72)>>(sizeof(j)*8-1));
341                                 pmac->u[0] |= key->md.h[0] & mask;
342                                 pmac->u[1] |= key->md.h[1] & mask;
343                                 pmac->u[2] |= key->md.h[2] & mask;
344                                 pmac->u[3] |= key->md.h[3] & mask;
345                                 pmac->u[4] |= key->md.h[4] & mask;
346                                 pmac->u[5] |= key->md.h[5] & mask;
347                                 pmac->u[6] |= key->md.h[6] & mask;
348                                 pmac->u[7] |= key->md.h[7] & mask;
349                                 res=0;
350                         }
351
352                         for(i=res;i<SHA256_CBLOCK;i++,j++) data->c[i]=0;
353
354                         if (res>SHA256_CBLOCK-8) {
355                                 mask = 0-((inp_len+8-j)>>(sizeof(j)*8-1));
356                                 data->u[SHA_LBLOCK-1] |= bitlen&mask;
357                                 sha256_block_data_order(&key->md,data,1);
358                                 mask &= 0-((j-inp_len-73)>>(sizeof(j)*8-1));
359                                 pmac->u[0] |= key->md.h[0] & mask;
360                                 pmac->u[1] |= key->md.h[1] & mask;
361                                 pmac->u[2] |= key->md.h[2] & mask;
362                                 pmac->u[3] |= key->md.h[3] & mask;
363                                 pmac->u[4] |= key->md.h[4] & mask;
364                                 pmac->u[5] |= key->md.h[5] & mask;
365                                 pmac->u[6] |= key->md.h[6] & mask;
366                                 pmac->u[7] |= key->md.h[7] & mask;
367
368                                 memset(data,0,SHA256_CBLOCK);
369                                 j+=64;
370                         }
371                         data->u[SHA_LBLOCK-1] = bitlen;
372                         sha256_block_data_order(&key->md,data,1);
373                         mask = 0-((j-inp_len-73)>>(sizeof(j)*8-1));
374                         pmac->u[0] |= key->md.h[0] & mask;
375                         pmac->u[1] |= key->md.h[1] & mask;
376                         pmac->u[2] |= key->md.h[2] & mask;
377                         pmac->u[3] |= key->md.h[3] & mask;
378                         pmac->u[4] |= key->md.h[4] & mask;
379                         pmac->u[5] |= key->md.h[5] & mask;
380                         pmac->u[6] |= key->md.h[6] & mask;
381                         pmac->u[7] |= key->md.h[7] & mask;
382
383 #ifdef BSWAP
384                         pmac->u[0] = BSWAP(pmac->u[0]);
385                         pmac->u[1] = BSWAP(pmac->u[1]);
386                         pmac->u[2] = BSWAP(pmac->u[2]);
387                         pmac->u[3] = BSWAP(pmac->u[3]);
388                         pmac->u[4] = BSWAP(pmac->u[4]);
389                         pmac->u[5] = BSWAP(pmac->u[5]);
390                         pmac->u[6] = BSWAP(pmac->u[6]);
391                         pmac->u[7] = BSWAP(pmac->u[7]);
392 #else
393                         for (i=0;i<8;i++) {
394                                 res = pmac->u[i];
395                                 pmac->c[4*i+0]=(unsigned char)(res>>24);
396                                 pmac->c[4*i+1]=(unsigned char)(res>>16);
397                                 pmac->c[4*i+2]=(unsigned char)(res>>8);
398                                 pmac->c[4*i+3]=(unsigned char)res;
399                         }
400 #endif
401                         len += SHA256_DIGEST_LENGTH;
402 #else
403                         SHA256_Update(&key->md,out,inp_len);
404                         res = key->md.num;
405                         SHA256_Final(pmac->c,&key->md);
406
407                         {
408                         unsigned int inp_blocks, pad_blocks;
409
410                         /* but pretend as if we hashed padded payload */
411                         inp_blocks = 1+((SHA256_CBLOCK-9-res)>>(sizeof(res)*8-1));
412                         res += (unsigned int)(len-inp_len);
413                         pad_blocks = res / SHA256_CBLOCK;
414                         res %= SHA256_CBLOCK;
415                         pad_blocks += 1+((SHA256_CBLOCK-9-res)>>(sizeof(res)*8-1));
416                         for (;inp_blocks<pad_blocks;inp_blocks++)
417                                 sha1_block_data_order(&key->md,data,1);
418                         }
419 #endif
420                         key->md = key->tail;
421                         SHA256_Update(&key->md,pmac->c,SHA256_DIGEST_LENGTH);
422                         SHA256_Final(pmac->c,&key->md);
423
424                         /* verify HMAC */
425                         out += inp_len;
426                         len -= inp_len;
427 #if 1
428                         {
429                         unsigned char *p = out+len-1-maxpad-SHA256_DIGEST_LENGTH;
430                         size_t off = out-p;
431                         unsigned int c, cmask;
432
433                         maxpad += SHA256_DIGEST_LENGTH;
434                         for (res=0,i=0,j=0;j<maxpad;j++) {
435                                 c = p[j];
436                                 cmask = ((int)(j-off-SHA256_DIGEST_LENGTH))>>(sizeof(int)*8-1);
437                                 res |= (c^pad)&~cmask;  /* ... and padding */
438                                 cmask &= ((int)(off-1-j))>>(sizeof(int)*8-1);
439                                 res |= (c^pmac->c[i])&cmask;
440                                 i += 1&cmask;
441                         }
442                         maxpad -= SHA256_DIGEST_LENGTH;
443
444                         res = 0-((0-res)>>(sizeof(res)*8-1));
445                         ret &= (int)~res;
446                         }
447 #else
448                         for (res=0,i=0;i<SHA256_DIGEST_LENGTH;i++)
449                                 res |= out[i]^pmac->c[i];
450                         res = 0-((0-res)>>(sizeof(res)*8-1));
451                         ret &= (int)~res;
452
453                         /* verify padding */
454                         pad = (pad&~res) | (maxpad&res);
455                         out = out+len-1-pad;
456                         for (res=0,i=0;i<pad;i++)
457                                 res |= out[i]^pad;
458
459                         res = (0-res)>>(sizeof(res)*8-1);
460                         ret &= (int)~res;
461 #endif
462                         return ret;
463                 } else {
464                         SHA256_Update(&key->md,out,len);
465                 }
466         }
467
468         return 1;
469         }
470
471 static int aesni_cbc_hmac_sha256_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
472         {
473         EVP_AES_HMAC_SHA256 *key = data(ctx);
474
475         switch (type)
476                 {
477         case EVP_CTRL_AEAD_SET_MAC_KEY:
478                 {
479                 unsigned int  i;
480                 unsigned char hmac_key[64];
481
482                 memset (hmac_key,0,sizeof(hmac_key));
483
484                 if (arg > (int)sizeof(hmac_key)) {
485                         SHA256_Init(&key->head);
486                         SHA256_Update(&key->head,ptr,arg);
487                         SHA256_Final(hmac_key,&key->head);
488                 } else {
489                         memcpy(hmac_key,ptr,arg);
490                 }
491
492                 for (i=0;i<sizeof(hmac_key);i++)
493                         hmac_key[i] ^= 0x36;            /* ipad */
494                 SHA256_Init(&key->head);
495                 SHA256_Update(&key->head,hmac_key,sizeof(hmac_key));
496
497                 for (i=0;i<sizeof(hmac_key);i++)
498                         hmac_key[i] ^= 0x36^0x5c;       /* opad */
499                 SHA256_Init(&key->tail);
500                 SHA256_Update(&key->tail,hmac_key,sizeof(hmac_key));
501
502                 OPENSSL_cleanse(hmac_key,sizeof(hmac_key));
503
504                 return 1;
505                 }
506         case EVP_CTRL_AEAD_TLS1_AAD:
507                 {
508                 unsigned char *p=ptr;
509                 unsigned int   len=p[arg-2]<<8|p[arg-1];
510
511                 if (ctx->encrypt)
512                         {
513                         key->payload_length = len;
514                         if ((key->aux.tls_ver=p[arg-4]<<8|p[arg-3]) >= TLS1_1_VERSION) {
515                                 len -= AES_BLOCK_SIZE;
516                                 p[arg-2] = len>>8;
517                                 p[arg-1] = len;
518                         }
519                         key->md = key->head;
520                         SHA256_Update(&key->md,p,arg);
521
522                         return (int)(((len+SHA256_DIGEST_LENGTH+AES_BLOCK_SIZE)&-AES_BLOCK_SIZE)
523                                 - len);
524                         }
525                 else
526                         {
527                         if (arg>13) arg = 13;
528                         memcpy(key->aux.tls_aad,ptr,arg);
529                         key->payload_length = arg;
530
531                         return SHA256_DIGEST_LENGTH;
532                         }
533                 }
534         default:
535                 return -1;
536                 }
537         }
538
539 static EVP_CIPHER aesni_128_cbc_hmac_sha256_cipher =
540         {
541 #ifdef NID_aes_128_cbc_hmac_sha256
542         NID_aes_128_cbc_hmac_sha256,
543 #else
544         NID_undef,
545 #endif
546         16,16,16,
547         EVP_CIPH_CBC_MODE|EVP_CIPH_FLAG_DEFAULT_ASN1|EVP_CIPH_FLAG_AEAD_CIPHER,
548         aesni_cbc_hmac_sha256_init_key,
549         aesni_cbc_hmac_sha256_cipher,
550         NULL,
551         sizeof(EVP_AES_HMAC_SHA256),
552         EVP_CIPH_FLAG_DEFAULT_ASN1?NULL:EVP_CIPHER_set_asn1_iv,
553         EVP_CIPH_FLAG_DEFAULT_ASN1?NULL:EVP_CIPHER_get_asn1_iv,
554         aesni_cbc_hmac_sha256_ctrl,
555         NULL
556         };
557
558 static EVP_CIPHER aesni_256_cbc_hmac_sha256_cipher =
559         {
560 #ifdef NID_aes_256_cbc_hmac_sha256
561         NID_aes_256_cbc_hmac_sha256,
562 #else
563         NID_undef,
564 #endif
565         16,32,16,
566         EVP_CIPH_CBC_MODE|EVP_CIPH_FLAG_DEFAULT_ASN1|EVP_CIPH_FLAG_AEAD_CIPHER,
567         aesni_cbc_hmac_sha256_init_key,
568         aesni_cbc_hmac_sha256_cipher,
569         NULL,
570         sizeof(EVP_AES_HMAC_SHA256),
571         EVP_CIPH_FLAG_DEFAULT_ASN1?NULL:EVP_CIPHER_set_asn1_iv,
572         EVP_CIPH_FLAG_DEFAULT_ASN1?NULL:EVP_CIPHER_get_asn1_iv,
573         aesni_cbc_hmac_sha256_ctrl,
574         NULL
575         };
576
577 const EVP_CIPHER *EVP_aes_128_cbc_hmac_sha256(void)
578         {
579         return((OPENSSL_ia32cap_P[1]&AESNI_CAPABLE) &&
580                 aesni_cbc_sha256_enc(NULL,NULL,0,NULL,NULL,NULL,NULL) ?
581                 &aesni_128_cbc_hmac_sha256_cipher:NULL);
582         }
583
584 const EVP_CIPHER *EVP_aes_256_cbc_hmac_sha256(void)
585         {
586         return((OPENSSL_ia32cap_P[1]&AESNI_CAPABLE) &&
587                 aesni_cbc_sha256_enc(NULL,NULL,0,NULL,NULL,NULL,NULL)?
588                 &aesni_256_cbc_hmac_sha256_cipher:NULL);
589         }
590 #else
591 const EVP_CIPHER *EVP_aes_128_cbc_hmac_sha256(void)
592         {
593         return NULL;
594         }
595 const EVP_CIPHER *EVP_aes_256_cbc_hmac_sha256(void)
596         {
597         return NULL;
598         }
599 #endif
600 #endif