2 * Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
17 #include <openssl/engine.h>
18 #include <openssl/sha.h>
19 #include <openssl/aes.h>
20 #include <openssl/rsa.h>
21 #include <openssl/evp.h>
22 #include <openssl/async.h>
23 #include <openssl/bn.h>
24 #include <openssl/crypto.h>
25 #include <openssl/ssl.h>
26 #include <openssl/modes.h>
28 #if defined(OPENSSL_SYS_UNIX) && defined(OPENSSL_THREADS)
37 #include "e_dasync_err.c"
39 /* Engine Id and Name */
40 static const char *engine_dasync_id = "dasync";
41 static const char *engine_dasync_name = "Dummy Async engine support";
44 /* Engine Lifetime functions */
45 static int dasync_destroy(ENGINE *e);
46 static int dasync_init(ENGINE *e);
47 static int dasync_finish(ENGINE *e);
48 void engine_load_dasync_int(void);
51 /* Set up digests. Just SHA1 for now */
52 static int dasync_digests(ENGINE *e, const EVP_MD **digest,
53 const int **nids, int nid);
55 static void dummy_pause_job(void);
58 static int dasync_sha1_init(EVP_MD_CTX *ctx);
59 static int dasync_sha1_update(EVP_MD_CTX *ctx, const void *data,
61 static int dasync_sha1_final(EVP_MD_CTX *ctx, unsigned char *md);
64 * Holds the EVP_MD object for sha1 in this engine. Set up once only during
65 * engine bind and can then be reused many times.
67 static EVP_MD *_hidden_sha1_md = NULL;
68 static const EVP_MD *dasync_sha1(void)
70 return _hidden_sha1_md;
72 static void destroy_digests(void)
74 EVP_MD_meth_free(_hidden_sha1_md);
75 _hidden_sha1_md = NULL;
78 static int dasync_digest_nids(const int **nids)
80 static int digest_nids[2] = { 0, 0 };
86 if ((md = dasync_sha1()) != NULL)
87 digest_nids[pos++] = EVP_MD_type(md);
97 static int dasync_pub_enc(int flen, const unsigned char *from,
98 unsigned char *to, RSA *rsa, int padding);
99 static int dasync_pub_dec(int flen, const unsigned char *from,
100 unsigned char *to, RSA *rsa, int padding);
101 static int dasync_rsa_priv_enc(int flen, const unsigned char *from,
102 unsigned char *to, RSA *rsa, int padding);
103 static int dasync_rsa_priv_dec(int flen, const unsigned char *from,
104 unsigned char *to, RSA *rsa, int padding);
105 static int dasync_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa,
108 static int dasync_rsa_init(RSA *rsa);
109 static int dasync_rsa_finish(RSA *rsa);
111 static RSA_METHOD *dasync_rsa_method = NULL;
115 static int dasync_aes128_cbc_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg,
117 static int dasync_aes128_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
118 const unsigned char *iv, int enc);
119 static int dasync_aes128_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
120 const unsigned char *in, size_t inl);
121 static int dasync_aes128_cbc_cleanup(EVP_CIPHER_CTX *ctx);
123 static int dasync_aes128_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type,
125 static int dasync_aes128_cbc_hmac_sha1_init_key(EVP_CIPHER_CTX *ctx,
126 const unsigned char *key,
127 const unsigned char *iv,
129 static int dasync_aes128_cbc_hmac_sha1_cipher(EVP_CIPHER_CTX *ctx,
131 const unsigned char *in,
133 static int dasync_aes128_cbc_hmac_sha1_cleanup(EVP_CIPHER_CTX *ctx);
135 struct dasync_pipeline_ctx {
136 void *inner_cipher_data;
137 unsigned int numpipes;
138 unsigned char **inbufs;
139 unsigned char **outbufs;
141 unsigned char tlsaad[SSL_MAX_PIPELINES][EVP_AEAD_TLS1_AAD_LEN];
146 * Holds the EVP_CIPHER object for aes_128_cbc in this engine. Set up once only
147 * during engine bind and can then be reused many times.
149 static EVP_CIPHER *_hidden_aes_128_cbc = NULL;
150 static const EVP_CIPHER *dasync_aes_128_cbc(void)
152 return _hidden_aes_128_cbc;
156 * Holds the EVP_CIPHER object for aes_128_cbc_hmac_sha1 in this engine. Set up
157 * once only during engine bind and can then be reused many times.
159 * This 'stitched' cipher depends on the EVP_aes_128_cbc_hmac_sha1() cipher,
160 * which is implemented only if the AES-NI instruction set extension is available
161 * (see OPENSSL_IA32CAP(3)). If that's not the case, then this cipher will not
162 * be available either.
164 * Note: Since it is a legacy mac-then-encrypt cipher, modern TLS peers (which
165 * negotiate the encrypt-then-mac extension) won't negotiate it anyway.
167 static EVP_CIPHER *_hidden_aes_128_cbc_hmac_sha1 = NULL;
168 static const EVP_CIPHER *dasync_aes_128_cbc_hmac_sha1(void)
170 return _hidden_aes_128_cbc_hmac_sha1;
173 static void destroy_ciphers(void)
175 EVP_CIPHER_meth_free(_hidden_aes_128_cbc);
176 EVP_CIPHER_meth_free(_hidden_aes_128_cbc_hmac_sha1);
177 _hidden_aes_128_cbc = NULL;
178 _hidden_aes_128_cbc_hmac_sha1 = NULL;
181 static int dasync_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
182 const int **nids, int nid);
184 static int dasync_cipher_nids[] = {
186 NID_aes_128_cbc_hmac_sha1,
190 static int bind_dasync(ENGINE *e)
192 /* Setup RSA_METHOD */
193 if ((dasync_rsa_method = RSA_meth_new("Dummy Async RSA method", 0)) == NULL
194 || RSA_meth_set_pub_enc(dasync_rsa_method, dasync_pub_enc) == 0
195 || RSA_meth_set_pub_dec(dasync_rsa_method, dasync_pub_dec) == 0
196 || RSA_meth_set_priv_enc(dasync_rsa_method, dasync_rsa_priv_enc) == 0
197 || RSA_meth_set_priv_dec(dasync_rsa_method, dasync_rsa_priv_dec) == 0
198 || RSA_meth_set_mod_exp(dasync_rsa_method, dasync_rsa_mod_exp) == 0
199 || RSA_meth_set_bn_mod_exp(dasync_rsa_method, BN_mod_exp_mont) == 0
200 || RSA_meth_set_init(dasync_rsa_method, dasync_rsa_init) == 0
201 || RSA_meth_set_finish(dasync_rsa_method, dasync_rsa_finish) == 0) {
202 DASYNCerr(DASYNC_F_BIND_DASYNC, DASYNC_R_INIT_FAILED);
206 /* Ensure the dasync error handling is set up */
207 ERR_load_DASYNC_strings();
209 if (!ENGINE_set_id(e, engine_dasync_id)
210 || !ENGINE_set_name(e, engine_dasync_name)
211 || !ENGINE_set_RSA(e, dasync_rsa_method)
212 || !ENGINE_set_digests(e, dasync_digests)
213 || !ENGINE_set_ciphers(e, dasync_ciphers)
214 || !ENGINE_set_destroy_function(e, dasync_destroy)
215 || !ENGINE_set_init_function(e, dasync_init)
216 || !ENGINE_set_finish_function(e, dasync_finish)) {
217 DASYNCerr(DASYNC_F_BIND_DASYNC, DASYNC_R_INIT_FAILED);
222 * Set up the EVP_CIPHER and EVP_MD objects for the ciphers/digests
223 * supplied by this engine
225 _hidden_sha1_md = EVP_MD_meth_new(NID_sha1, NID_sha1WithRSAEncryption);
226 if (_hidden_sha1_md == NULL
227 || !EVP_MD_meth_set_result_size(_hidden_sha1_md, SHA_DIGEST_LENGTH)
228 || !EVP_MD_meth_set_input_blocksize(_hidden_sha1_md, SHA_CBLOCK)
229 || !EVP_MD_meth_set_app_datasize(_hidden_sha1_md,
230 sizeof(EVP_MD *) + sizeof(SHA_CTX))
231 || !EVP_MD_meth_set_flags(_hidden_sha1_md, EVP_MD_FLAG_DIGALGID_ABSENT)
232 || !EVP_MD_meth_set_init(_hidden_sha1_md, dasync_sha1_init)
233 || !EVP_MD_meth_set_update(_hidden_sha1_md, dasync_sha1_update)
234 || !EVP_MD_meth_set_final(_hidden_sha1_md, dasync_sha1_final)) {
235 EVP_MD_meth_free(_hidden_sha1_md);
236 _hidden_sha1_md = NULL;
239 _hidden_aes_128_cbc = EVP_CIPHER_meth_new(NID_aes_128_cbc,
242 if (_hidden_aes_128_cbc == NULL
243 || !EVP_CIPHER_meth_set_iv_length(_hidden_aes_128_cbc,16)
244 || !EVP_CIPHER_meth_set_flags(_hidden_aes_128_cbc,
245 EVP_CIPH_FLAG_DEFAULT_ASN1
247 | EVP_CIPH_FLAG_PIPELINE)
248 || !EVP_CIPHER_meth_set_init(_hidden_aes_128_cbc,
249 dasync_aes128_init_key)
250 || !EVP_CIPHER_meth_set_do_cipher(_hidden_aes_128_cbc,
251 dasync_aes128_cbc_cipher)
252 || !EVP_CIPHER_meth_set_cleanup(_hidden_aes_128_cbc,
253 dasync_aes128_cbc_cleanup)
254 || !EVP_CIPHER_meth_set_ctrl(_hidden_aes_128_cbc,
255 dasync_aes128_cbc_ctrl)
256 || !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_aes_128_cbc,
257 sizeof(struct dasync_pipeline_ctx))) {
258 EVP_CIPHER_meth_free(_hidden_aes_128_cbc);
259 _hidden_aes_128_cbc = NULL;
262 _hidden_aes_128_cbc_hmac_sha1 = EVP_CIPHER_meth_new(
263 NID_aes_128_cbc_hmac_sha1,
266 if (_hidden_aes_128_cbc_hmac_sha1 == NULL
267 || !EVP_CIPHER_meth_set_iv_length(_hidden_aes_128_cbc_hmac_sha1,16)
268 || !EVP_CIPHER_meth_set_flags(_hidden_aes_128_cbc_hmac_sha1,
270 | EVP_CIPH_FLAG_DEFAULT_ASN1
271 | EVP_CIPH_FLAG_AEAD_CIPHER
272 | EVP_CIPH_FLAG_PIPELINE)
273 || !EVP_CIPHER_meth_set_init(_hidden_aes_128_cbc_hmac_sha1,
274 dasync_aes128_cbc_hmac_sha1_init_key)
275 || !EVP_CIPHER_meth_set_do_cipher(_hidden_aes_128_cbc_hmac_sha1,
276 dasync_aes128_cbc_hmac_sha1_cipher)
277 || !EVP_CIPHER_meth_set_cleanup(_hidden_aes_128_cbc_hmac_sha1,
278 dasync_aes128_cbc_hmac_sha1_cleanup)
279 || !EVP_CIPHER_meth_set_ctrl(_hidden_aes_128_cbc_hmac_sha1,
280 dasync_aes128_cbc_hmac_sha1_ctrl)
281 || !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_aes_128_cbc_hmac_sha1,
282 sizeof(struct dasync_pipeline_ctx))) {
283 EVP_CIPHER_meth_free(_hidden_aes_128_cbc_hmac_sha1);
284 _hidden_aes_128_cbc_hmac_sha1 = NULL;
290 # ifndef OPENSSL_NO_DYNAMIC_ENGINE
291 static int bind_helper(ENGINE *e, const char *id)
293 if (id && (strcmp(id, engine_dasync_id) != 0))
300 IMPLEMENT_DYNAMIC_CHECK_FN()
301 IMPLEMENT_DYNAMIC_BIND_FN(bind_helper)
304 static ENGINE *engine_dasync(void)
306 ENGINE *ret = ENGINE_new();
309 if (!bind_dasync(ret)) {
316 void engine_load_dasync_int(void)
318 ENGINE *toadd = engine_dasync();
326 static int dasync_init(ENGINE *e)
332 static int dasync_finish(ENGINE *e)
338 static int dasync_destroy(ENGINE *e)
342 RSA_meth_free(dasync_rsa_method);
343 ERR_unload_DASYNC_strings();
347 static int dasync_digests(ENGINE *e, const EVP_MD **digest,
348 const int **nids, int nid)
352 /* We are returning a list of supported nids */
353 return dasync_digest_nids(nids);
355 /* We are being asked for a specific digest */
358 *digest = dasync_sha1();
368 static int dasync_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
369 const int **nids, int nid)
372 if (cipher == NULL) {
373 /* We are returning a list of supported nids */
374 *nids = dasync_cipher_nids;
375 return (sizeof(dasync_cipher_nids) -
376 1) / sizeof(dasync_cipher_nids[0]);
378 /* We are being asked for a specific cipher */
380 case NID_aes_128_cbc:
381 *cipher = dasync_aes_128_cbc();
383 case NID_aes_128_cbc_hmac_sha1:
384 *cipher = dasync_aes_128_cbc_hmac_sha1();
394 static void wait_cleanup(ASYNC_WAIT_CTX *ctx, const void *key,
395 OSSL_ASYNC_FD readfd, void *pvwritefd)
397 OSSL_ASYNC_FD *pwritefd = (OSSL_ASYNC_FD *)pvwritefd;
398 #if defined(ASYNC_WIN)
400 CloseHandle(*pwritefd);
401 #elif defined(ASYNC_POSIX)
405 OPENSSL_free(pwritefd);
408 #define DUMMY_CHAR 'X'
410 static void dummy_pause_job(void) {
412 ASYNC_WAIT_CTX *waitctx;
413 OSSL_ASYNC_FD pipefds[2] = {0, 0};
414 OSSL_ASYNC_FD *writefd;
415 #if defined(ASYNC_WIN)
416 DWORD numwritten, numread;
417 char buf = DUMMY_CHAR;
418 #elif defined(ASYNC_POSIX)
419 char buf = DUMMY_CHAR;
422 if ((job = ASYNC_get_current_job()) == NULL)
425 waitctx = ASYNC_get_wait_ctx(job);
427 if (ASYNC_WAIT_CTX_get_fd(waitctx, engine_dasync_id, &pipefds[0],
428 (void **)&writefd)) {
429 pipefds[1] = *writefd;
431 writefd = OPENSSL_malloc(sizeof(*writefd));
434 #if defined(ASYNC_WIN)
435 if (CreatePipe(&pipefds[0], &pipefds[1], NULL, 256) == 0) {
436 OPENSSL_free(writefd);
439 #elif defined(ASYNC_POSIX)
440 if (pipe(pipefds) != 0) {
441 OPENSSL_free(writefd);
445 *writefd = pipefds[1];
447 if (!ASYNC_WAIT_CTX_set_wait_fd(waitctx, engine_dasync_id, pipefds[0],
448 writefd, wait_cleanup)) {
449 wait_cleanup(waitctx, engine_dasync_id, pipefds[0], writefd);
454 * In the Dummy async engine we are cheating. We signal that the job
455 * is complete by waking it before the call to ASYNC_pause_job(). A real
456 * async engine would only wake when the job was actually complete
458 #if defined(ASYNC_WIN)
459 WriteFile(pipefds[1], &buf, 1, &numwritten, NULL);
460 #elif defined(ASYNC_POSIX)
461 if (write(pipefds[1], &buf, 1) < 0)
465 /* Ignore errors - we carry on anyway */
468 /* Clear the wake signal */
469 #if defined(ASYNC_WIN)
470 ReadFile(pipefds[0], &buf, 1, &numread, NULL);
471 #elif defined(ASYNC_POSIX)
472 if (read(pipefds[0], &buf, 1) < 0)
478 * SHA1 implementation. At the moment we just defer to the standard
482 #define data(ctx) ((SHA_CTX *)EVP_MD_CTX_md_data(ctx))
483 static int dasync_sha1_init(EVP_MD_CTX *ctx)
487 return SHA1_Init(data(ctx));
490 static int dasync_sha1_update(EVP_MD_CTX *ctx, const void *data,
495 return SHA1_Update(data(ctx), data, (size_t)count);
498 static int dasync_sha1_final(EVP_MD_CTX *ctx, unsigned char *md)
502 return SHA1_Final(md, data(ctx));
509 static int dasync_pub_enc(int flen, const unsigned char *from,
510 unsigned char *to, RSA *rsa, int padding) {
511 /* Ignore errors - we carry on anyway */
513 return RSA_meth_get_pub_enc(RSA_PKCS1_OpenSSL())
514 (flen, from, to, rsa, padding);
517 static int dasync_pub_dec(int flen, const unsigned char *from,
518 unsigned char *to, RSA *rsa, int padding) {
519 /* Ignore errors - we carry on anyway */
521 return RSA_meth_get_pub_dec(RSA_PKCS1_OpenSSL())
522 (flen, from, to, rsa, padding);
525 static int dasync_rsa_priv_enc(int flen, const unsigned char *from,
526 unsigned char *to, RSA *rsa, int padding)
528 /* Ignore errors - we carry on anyway */
530 return RSA_meth_get_priv_enc(RSA_PKCS1_OpenSSL())
531 (flen, from, to, rsa, padding);
534 static int dasync_rsa_priv_dec(int flen, const unsigned char *from,
535 unsigned char *to, RSA *rsa, int padding)
537 /* Ignore errors - we carry on anyway */
539 return RSA_meth_get_priv_dec(RSA_PKCS1_OpenSSL())
540 (flen, from, to, rsa, padding);
543 static int dasync_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
545 /* Ignore errors - we carry on anyway */
547 return RSA_meth_get_mod_exp(RSA_PKCS1_OpenSSL())(r0, I, rsa, ctx);
550 static int dasync_rsa_init(RSA *rsa)
552 return RSA_meth_get_init(RSA_PKCS1_OpenSSL())(rsa);
554 static int dasync_rsa_finish(RSA *rsa)
556 return RSA_meth_get_finish(RSA_PKCS1_OpenSSL())(rsa);
559 /* Cipher helper functions */
561 static int dasync_cipher_ctrl_helper(EVP_CIPHER_CTX *ctx, int type, int arg,
562 void *ptr, int aeadcapable)
565 struct dasync_pipeline_ctx *pipe_ctx =
566 (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx);
568 if (pipe_ctx == NULL)
572 case EVP_CTRL_SET_PIPELINE_OUTPUT_BUFS:
573 pipe_ctx->numpipes = arg;
574 pipe_ctx->outbufs = (unsigned char **)ptr;
577 case EVP_CTRL_SET_PIPELINE_INPUT_BUFS:
578 pipe_ctx->numpipes = arg;
579 pipe_ctx->inbufs = (unsigned char **)ptr;
582 case EVP_CTRL_SET_PIPELINE_INPUT_LENS:
583 pipe_ctx->numpipes = arg;
584 pipe_ctx->lens = (size_t *)ptr;
587 case EVP_CTRL_AEAD_SET_MAC_KEY:
590 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx->inner_cipher_data);
591 ret = EVP_CIPHER_meth_get_ctrl(EVP_aes_128_cbc_hmac_sha1())
592 (ctx, type, arg, ptr);
593 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx);
596 case EVP_CTRL_AEAD_TLS1_AAD:
598 unsigned char *p = ptr;
601 if (!aeadcapable || arg != EVP_AEAD_TLS1_AAD_LEN)
604 if (pipe_ctx->aadctr >= SSL_MAX_PIPELINES)
607 memcpy(pipe_ctx->tlsaad[pipe_ctx->aadctr], ptr,
608 EVP_AEAD_TLS1_AAD_LEN);
611 len = p[arg - 2] << 8 | p[arg - 1];
613 if (EVP_CIPHER_CTX_encrypting(ctx)) {
614 if ((p[arg - 4] << 8 | p[arg - 3]) >= TLS1_1_VERSION) {
615 if (len < AES_BLOCK_SIZE)
617 len -= AES_BLOCK_SIZE;
620 return ((len + SHA_DIGEST_LENGTH + AES_BLOCK_SIZE)
621 & -AES_BLOCK_SIZE) - len;
623 return SHA_DIGEST_LENGTH;
634 static int dasync_cipher_init_key_helper(EVP_CIPHER_CTX *ctx,
635 const unsigned char *key,
636 const unsigned char *iv, int enc,
637 const EVP_CIPHER *cipher)
640 struct dasync_pipeline_ctx *pipe_ctx =
641 (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx);
643 if (pipe_ctx->inner_cipher_data == NULL
644 && EVP_CIPHER_impl_ctx_size(cipher) != 0) {
645 pipe_ctx->inner_cipher_data = OPENSSL_zalloc(
646 EVP_CIPHER_impl_ctx_size(cipher));
647 if (pipe_ctx->inner_cipher_data == NULL) {
648 DASYNCerr(DASYNC_F_DASYNC_CIPHER_INIT_KEY_HELPER,
649 ERR_R_MALLOC_FAILURE);
654 pipe_ctx->numpipes = 0;
655 pipe_ctx->aadctr = 0;
657 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx->inner_cipher_data);
658 ret = EVP_CIPHER_meth_get_init(cipher)(ctx, key, iv, enc);
659 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx);
664 static int dasync_cipher_helper(EVP_CIPHER_CTX *ctx, unsigned char *out,
665 const unsigned char *in, size_t inl,
666 const EVP_CIPHER *cipher)
669 unsigned int i, pipes;
670 struct dasync_pipeline_ctx *pipe_ctx =
671 (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx);
673 pipes = pipe_ctx->numpipes;
674 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx->inner_cipher_data);
676 if (pipe_ctx->aadctr != 0) {
677 if (pipe_ctx->aadctr != 1)
679 EVP_CIPHER_meth_get_ctrl(cipher)
680 (ctx, EVP_CTRL_AEAD_TLS1_AAD,
681 EVP_AEAD_TLS1_AAD_LEN,
682 pipe_ctx->tlsaad[0]);
684 ret = EVP_CIPHER_meth_get_do_cipher(cipher)
687 if (pipe_ctx->aadctr > 0 && pipe_ctx->aadctr != pipes)
689 for (i = 0; i < pipes; i++) {
690 if (pipe_ctx->aadctr > 0) {
691 EVP_CIPHER_meth_get_ctrl(cipher)
692 (ctx, EVP_CTRL_AEAD_TLS1_AAD,
693 EVP_AEAD_TLS1_AAD_LEN,
694 pipe_ctx->tlsaad[i]);
696 ret = ret && EVP_CIPHER_meth_get_do_cipher(cipher)
697 (ctx, pipe_ctx->outbufs[i], pipe_ctx->inbufs[i],
700 pipe_ctx->numpipes = 0;
702 pipe_ctx->aadctr = 0;
703 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx);
707 static int dasync_cipher_cleanup_helper(EVP_CIPHER_CTX *ctx,
708 const EVP_CIPHER *cipher)
710 struct dasync_pipeline_ctx *pipe_ctx =
711 (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx);
713 OPENSSL_clear_free(pipe_ctx->inner_cipher_data,
714 EVP_CIPHER_impl_ctx_size(cipher));
720 * AES128 CBC Implementation
723 static int dasync_aes128_cbc_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg,
726 return dasync_cipher_ctrl_helper(ctx, type, arg, ptr, 0);
729 static int dasync_aes128_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
730 const unsigned char *iv, int enc)
732 return dasync_cipher_init_key_helper(ctx, key, iv, enc, EVP_aes_128_cbc());
735 static int dasync_aes128_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
736 const unsigned char *in, size_t inl)
738 return dasync_cipher_helper(ctx, out, in, inl, EVP_aes_128_cbc());
741 static int dasync_aes128_cbc_cleanup(EVP_CIPHER_CTX *ctx)
743 return dasync_cipher_cleanup_helper(ctx, EVP_aes_128_cbc());
748 * AES128 CBC HMAC SHA1 Implementation
751 static int dasync_aes128_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type,
754 return dasync_cipher_ctrl_helper(ctx, type, arg, ptr, 1);
757 static int dasync_aes128_cbc_hmac_sha1_init_key(EVP_CIPHER_CTX *ctx,
758 const unsigned char *key,
759 const unsigned char *iv,
763 * We can safely assume that EVP_aes_128_cbc_hmac_sha1() != NULL,
764 * see comment before the definition of dasync_aes_128_cbc_hmac_sha1().
766 return dasync_cipher_init_key_helper(ctx, key, iv, enc,
767 EVP_aes_128_cbc_hmac_sha1());
770 static int dasync_aes128_cbc_hmac_sha1_cipher(EVP_CIPHER_CTX *ctx,
772 const unsigned char *in,
775 return dasync_cipher_helper(ctx, out, in, inl, EVP_aes_128_cbc_hmac_sha1());
778 static int dasync_aes128_cbc_hmac_sha1_cleanup(EVP_CIPHER_CTX *ctx)
781 * We can safely assume that EVP_aes_128_cbc_hmac_sha1() != NULL,
782 * see comment before the definition of dasync_aes_128_cbc_hmac_sha1().
784 return dasync_cipher_cleanup_helper(ctx, EVP_aes_128_cbc_hmac_sha1());