2 * Copyright 2015-2016 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
13 #include <openssl/engine.h>
14 #include <openssl/sha.h>
15 #include <openssl/aes.h>
16 #include <openssl/rsa.h>
17 #include <openssl/evp.h>
18 #include <openssl/async.h>
19 #include <openssl/bn.h>
20 #include <openssl/crypto.h>
21 #include <openssl/ssl.h>
22 #include <openssl/modes.h>
24 #if (defined(OPENSSL_SYS_UNIX) || defined(OPENSSL_SYS_CYGWIN)) && defined(OPENSSL_THREADS)
34 #define DASYNC_LIB_NAME "DASYNC"
35 #include "e_dasync_err.c"
37 /* Engine Id and Name */
38 static const char *engine_dasync_id = "dasync";
39 static const char *engine_dasync_name = "Dummy Async engine support";
42 /* Engine Lifetime functions */
43 static int dasync_destroy(ENGINE *e);
44 static int dasync_init(ENGINE *e);
45 static int dasync_finish(ENGINE *e);
46 void engine_load_dasync_int(void);
49 /* Set up digests. Just SHA1 for now */
50 static int dasync_digests(ENGINE *e, const EVP_MD **digest,
51 const int **nids, int nid);
53 static void dummy_pause_job(void);
56 static int dasync_sha1_init(EVP_MD_CTX *ctx);
57 static int dasync_sha1_update(EVP_MD_CTX *ctx, const void *data,
59 static int dasync_sha1_final(EVP_MD_CTX *ctx, unsigned char *md);
62 * Holds the EVP_MD object for sha1 in this engine. Set up once only during
63 * engine bind and can then be reused many times.
65 static EVP_MD *_hidden_sha1_md = NULL;
66 static const EVP_MD *dasync_sha1(void)
68 return _hidden_sha1_md;
70 static void destroy_digests(void)
72 EVP_MD_meth_free(_hidden_sha1_md);
73 _hidden_sha1_md = NULL;
76 static int dasync_digest_nids(const int **nids)
78 static int digest_nids[2] = { 0, 0 };
84 if ((md = dasync_sha1()) != NULL)
85 digest_nids[pos++] = EVP_MD_type(md);
95 static int dasync_pub_enc(int flen, const unsigned char *from,
96 unsigned char *to, RSA *rsa, int padding);
97 static int dasync_pub_dec(int flen, const unsigned char *from,
98 unsigned char *to, RSA *rsa, int padding);
99 static int dasync_rsa_priv_enc(int flen, const unsigned char *from,
100 unsigned char *to, RSA *rsa, int padding);
101 static int dasync_rsa_priv_dec(int flen, const unsigned char *from,
102 unsigned char *to, RSA *rsa, int padding);
103 static int dasync_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa,
106 static int dasync_rsa_init(RSA *rsa);
107 static int dasync_rsa_finish(RSA *rsa);
109 static RSA_METHOD *dasync_rsa_method = NULL;
113 static int dasync_aes128_cbc_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg,
115 static int dasync_aes128_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
116 const unsigned char *iv, int enc);
117 static int dasync_aes128_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
118 const unsigned char *in, size_t inl);
119 static int dasync_aes128_cbc_cleanup(EVP_CIPHER_CTX *ctx);
121 static int dasync_aes128_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type,
123 static int dasync_aes128_cbc_hmac_sha1_init_key(EVP_CIPHER_CTX *ctx,
124 const unsigned char *key,
125 const unsigned char *iv,
127 static int dasync_aes128_cbc_hmac_sha1_cipher(EVP_CIPHER_CTX *ctx,
129 const unsigned char *in,
131 static int dasync_aes128_cbc_hmac_sha1_cleanup(EVP_CIPHER_CTX *ctx);
133 struct dasync_pipeline_ctx {
134 void *inner_cipher_data;
135 unsigned int numpipes;
136 unsigned char **inbufs;
137 unsigned char **outbufs;
140 unsigned char tlsaad[SSL_MAX_PIPELINES][EVP_AEAD_TLS1_AAD_LEN];
145 * Holds the EVP_CIPHER object for aes_128_cbc in this engine. Set up once only
146 * during engine bind and can then be reused many times.
148 static EVP_CIPHER *_hidden_aes_128_cbc = NULL;
149 static const EVP_CIPHER *dasync_aes_128_cbc(void)
151 return _hidden_aes_128_cbc;
155 * Holds the EVP_CIPHER object for aes_128_cbc_hmac_sha1 in this engine. Set up
156 * once only during engine bind and can then be reused many times.
158 static EVP_CIPHER *_hidden_aes_128_cbc_hmac_sha1 = NULL;
159 static const EVP_CIPHER *dasync_aes_128_cbc_hmac_sha1(void)
161 return _hidden_aes_128_cbc_hmac_sha1;
164 static void destroy_ciphers(void)
166 EVP_CIPHER_meth_free(_hidden_aes_128_cbc);
167 EVP_CIPHER_meth_free(_hidden_aes_128_cbc_hmac_sha1);
168 _hidden_aes_128_cbc = NULL;
169 _hidden_aes_128_cbc_hmac_sha1 = NULL;
172 static int dasync_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
173 const int **nids, int nid);
175 static int dasync_cipher_nids[] = {
177 NID_aes_128_cbc_hmac_sha1,
181 static int bind_dasync(ENGINE *e)
183 /* Setup RSA_METHOD */
184 if ((dasync_rsa_method = RSA_meth_new("Dummy Async RSA method", 0)) == NULL
185 || RSA_meth_set_pub_enc(dasync_rsa_method, dasync_pub_enc) == 0
186 || RSA_meth_set_pub_dec(dasync_rsa_method, dasync_pub_dec) == 0
187 || RSA_meth_set_priv_enc(dasync_rsa_method, dasync_rsa_priv_enc) == 0
188 || RSA_meth_set_priv_dec(dasync_rsa_method, dasync_rsa_priv_dec) == 0
189 || RSA_meth_set_mod_exp(dasync_rsa_method, dasync_rsa_mod_exp) == 0
190 || RSA_meth_set_bn_mod_exp(dasync_rsa_method, BN_mod_exp_mont) == 0
191 || RSA_meth_set_init(dasync_rsa_method, dasync_rsa_init) == 0
192 || RSA_meth_set_finish(dasync_rsa_method, dasync_rsa_finish) == 0) {
193 DASYNCerr(DASYNC_F_BIND_DASYNC, DASYNC_R_INIT_FAILED);
197 /* Ensure the dasync error handling is set up */
198 ERR_load_DASYNC_strings();
200 if (!ENGINE_set_id(e, engine_dasync_id)
201 || !ENGINE_set_name(e, engine_dasync_name)
202 || !ENGINE_set_RSA(e, dasync_rsa_method)
203 || !ENGINE_set_digests(e, dasync_digests)
204 || !ENGINE_set_ciphers(e, dasync_ciphers)
205 || !ENGINE_set_destroy_function(e, dasync_destroy)
206 || !ENGINE_set_init_function(e, dasync_init)
207 || !ENGINE_set_finish_function(e, dasync_finish)) {
208 DASYNCerr(DASYNC_F_BIND_DASYNC, DASYNC_R_INIT_FAILED);
213 * Set up the EVP_CIPHER and EVP_MD objects for the ciphers/digests
214 * supplied by this engine
216 _hidden_sha1_md = EVP_MD_meth_new(NID_sha1, NID_sha1WithRSAEncryption);
217 if (_hidden_sha1_md == NULL
218 || !EVP_MD_meth_set_result_size(_hidden_sha1_md, SHA_DIGEST_LENGTH)
219 || !EVP_MD_meth_set_input_blocksize(_hidden_sha1_md, SHA_CBLOCK)
220 || !EVP_MD_meth_set_app_datasize(_hidden_sha1_md,
221 sizeof(EVP_MD *) + sizeof(SHA_CTX))
222 || !EVP_MD_meth_set_flags(_hidden_sha1_md, EVP_MD_FLAG_DIGALGID_ABSENT)
223 || !EVP_MD_meth_set_init(_hidden_sha1_md, dasync_sha1_init)
224 || !EVP_MD_meth_set_update(_hidden_sha1_md, dasync_sha1_update)
225 || !EVP_MD_meth_set_final(_hidden_sha1_md, dasync_sha1_final)) {
226 EVP_MD_meth_free(_hidden_sha1_md);
227 _hidden_sha1_md = NULL;
230 _hidden_aes_128_cbc = EVP_CIPHER_meth_new(NID_aes_128_cbc,
233 if (_hidden_aes_128_cbc == NULL
234 || !EVP_CIPHER_meth_set_iv_length(_hidden_aes_128_cbc,16)
235 || !EVP_CIPHER_meth_set_flags(_hidden_aes_128_cbc,
236 EVP_CIPH_FLAG_DEFAULT_ASN1
238 | EVP_CIPH_FLAG_PIPELINE)
239 || !EVP_CIPHER_meth_set_init(_hidden_aes_128_cbc,
240 dasync_aes128_init_key)
241 || !EVP_CIPHER_meth_set_do_cipher(_hidden_aes_128_cbc,
242 dasync_aes128_cbc_cipher)
243 || !EVP_CIPHER_meth_set_cleanup(_hidden_aes_128_cbc,
244 dasync_aes128_cbc_cleanup)
245 || !EVP_CIPHER_meth_set_ctrl(_hidden_aes_128_cbc,
246 dasync_aes128_cbc_ctrl)
247 || !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_aes_128_cbc,
248 sizeof(struct dasync_pipeline_ctx))) {
249 EVP_CIPHER_meth_free(_hidden_aes_128_cbc);
250 _hidden_aes_128_cbc = NULL;
253 _hidden_aes_128_cbc_hmac_sha1 = EVP_CIPHER_meth_new(
254 NID_aes_128_cbc_hmac_sha1,
257 if (_hidden_aes_128_cbc_hmac_sha1 == NULL
258 || !EVP_CIPHER_meth_set_iv_length(_hidden_aes_128_cbc_hmac_sha1,16)
259 || !EVP_CIPHER_meth_set_flags(_hidden_aes_128_cbc_hmac_sha1,
261 | EVP_CIPH_FLAG_DEFAULT_ASN1
262 | EVP_CIPH_FLAG_AEAD_CIPHER
263 | EVP_CIPH_FLAG_PIPELINE)
264 || !EVP_CIPHER_meth_set_init(_hidden_aes_128_cbc_hmac_sha1,
265 dasync_aes128_cbc_hmac_sha1_init_key)
266 || !EVP_CIPHER_meth_set_do_cipher(_hidden_aes_128_cbc_hmac_sha1,
267 dasync_aes128_cbc_hmac_sha1_cipher)
268 || !EVP_CIPHER_meth_set_cleanup(_hidden_aes_128_cbc_hmac_sha1,
269 dasync_aes128_cbc_hmac_sha1_cleanup)
270 || !EVP_CIPHER_meth_set_ctrl(_hidden_aes_128_cbc_hmac_sha1,
271 dasync_aes128_cbc_hmac_sha1_ctrl)
272 || !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_aes_128_cbc_hmac_sha1,
273 sizeof(struct dasync_pipeline_ctx))) {
274 EVP_CIPHER_meth_free(_hidden_aes_128_cbc_hmac_sha1);
275 _hidden_aes_128_cbc_hmac_sha1 = NULL;
281 # ifndef OPENSSL_NO_DYNAMIC_ENGINE
282 static int bind_helper(ENGINE *e, const char *id)
284 if (id && (strcmp(id, engine_dasync_id) != 0))
291 IMPLEMENT_DYNAMIC_CHECK_FN()
292 IMPLEMENT_DYNAMIC_BIND_FN(bind_helper)
295 static ENGINE *engine_dasync(void)
297 ENGINE *ret = ENGINE_new();
300 if (!bind_dasync(ret)) {
307 void engine_load_dasync_int(void)
309 ENGINE *toadd = engine_dasync();
317 static int dasync_init(ENGINE *e)
323 static int dasync_finish(ENGINE *e)
329 static int dasync_destroy(ENGINE *e)
333 RSA_meth_free(dasync_rsa_method);
334 ERR_unload_DASYNC_strings();
338 static int dasync_digests(ENGINE *e, const EVP_MD **digest,
339 const int **nids, int nid)
343 /* We are returning a list of supported nids */
344 return dasync_digest_nids(nids);
346 /* We are being asked for a specific digest */
349 *digest = dasync_sha1();
359 static int dasync_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
360 const int **nids, int nid)
363 if (cipher == NULL) {
364 /* We are returning a list of supported nids */
365 *nids = dasync_cipher_nids;
366 return (sizeof(dasync_cipher_nids) -
367 1) / sizeof(dasync_cipher_nids[0]);
369 /* We are being asked for a specific cipher */
371 case NID_aes_128_cbc:
372 *cipher = dasync_aes_128_cbc();
374 case NID_aes_128_cbc_hmac_sha1:
375 *cipher = dasync_aes_128_cbc_hmac_sha1();
385 static void wait_cleanup(ASYNC_WAIT_CTX *ctx, const void *key,
386 OSSL_ASYNC_FD readfd, void *pvwritefd)
388 OSSL_ASYNC_FD *pwritefd = (OSSL_ASYNC_FD *)pvwritefd;
389 #if defined(ASYNC_WIN)
391 CloseHandle(*pwritefd);
392 #elif defined(ASYNC_POSIX)
396 OPENSSL_free(pwritefd);
399 #define DUMMY_CHAR 'X'
401 static void dummy_pause_job(void) {
403 ASYNC_WAIT_CTX *waitctx;
404 OSSL_ASYNC_FD pipefds[2] = {0, 0};
405 OSSL_ASYNC_FD *writefd;
406 #if defined(ASYNC_WIN)
407 DWORD numwritten, numread;
408 char buf = DUMMY_CHAR;
409 #elif defined(ASYNC_POSIX)
410 char buf = DUMMY_CHAR;
413 if ((job = ASYNC_get_current_job()) == NULL)
416 waitctx = ASYNC_get_wait_ctx(job);
418 if (ASYNC_WAIT_CTX_get_fd(waitctx, engine_dasync_id, &pipefds[0],
419 (void **)&writefd)) {
420 pipefds[1] = *writefd;
422 writefd = OPENSSL_malloc(sizeof(*writefd));
425 #if defined(ASYNC_WIN)
426 if (CreatePipe(&pipefds[0], &pipefds[1], NULL, 256) == 0) {
427 OPENSSL_free(writefd);
430 #elif defined(ASYNC_POSIX)
431 if (pipe(pipefds) != 0) {
432 OPENSSL_free(writefd);
436 *writefd = pipefds[1];
438 if(!ASYNC_WAIT_CTX_set_wait_fd(waitctx, engine_dasync_id, pipefds[0],
439 writefd, wait_cleanup)) {
440 wait_cleanup(waitctx, engine_dasync_id, pipefds[0], writefd);
445 * In the Dummy async engine we are cheating. We signal that the job
446 * is complete by waking it before the call to ASYNC_pause_job(). A real
447 * async engine would only wake when the job was actually complete
449 #if defined(ASYNC_WIN)
450 WriteFile(pipefds[1], &buf, 1, &numwritten, NULL);
451 #elif defined(ASYNC_POSIX)
452 if (write(pipefds[1], &buf, 1) < 0)
456 /* Ignore errors - we carry on anyway */
459 /* Clear the wake signal */
460 #if defined(ASYNC_WIN)
461 ReadFile(pipefds[0], &buf, 1, &numread, NULL);
462 #elif defined(ASYNC_POSIX)
463 if (read(pipefds[0], &buf, 1) < 0)
469 * SHA1 implementation. At the moment we just defer to the standard
473 #define data(ctx) ((SHA_CTX *)EVP_MD_CTX_md_data(ctx))
474 static int dasync_sha1_init(EVP_MD_CTX *ctx)
478 return SHA1_Init(data(ctx));
481 static int dasync_sha1_update(EVP_MD_CTX *ctx, const void *data,
486 return SHA1_Update(data(ctx), data, (size_t)count);
489 static int dasync_sha1_final(EVP_MD_CTX *ctx, unsigned char *md)
493 return SHA1_Final(md, data(ctx));
500 static int dasync_pub_enc(int flen, const unsigned char *from,
501 unsigned char *to, RSA *rsa, int padding) {
502 /* Ignore errors - we carry on anyway */
504 return RSA_meth_get_pub_enc(RSA_PKCS1_OpenSSL())
505 (flen, from, to, rsa, padding);
508 static int dasync_pub_dec(int flen, const unsigned char *from,
509 unsigned char *to, RSA *rsa, int padding) {
510 /* Ignore errors - we carry on anyway */
512 return RSA_meth_get_pub_dec(RSA_PKCS1_OpenSSL())
513 (flen, from, to, rsa, padding);
516 static int dasync_rsa_priv_enc(int flen, const unsigned char *from,
517 unsigned char *to, RSA *rsa, int padding)
519 /* Ignore errors - we carry on anyway */
521 return RSA_meth_get_priv_enc(RSA_PKCS1_OpenSSL())
522 (flen, from, to, rsa, padding);
525 static int dasync_rsa_priv_dec(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_dec(RSA_PKCS1_OpenSSL())
531 (flen, from, to, rsa, padding);
534 static int dasync_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
536 /* Ignore errors - we carry on anyway */
538 return RSA_meth_get_mod_exp(RSA_PKCS1_OpenSSL())(r0, I, rsa, ctx);
541 static int dasync_rsa_init(RSA *rsa)
543 return RSA_meth_get_init(RSA_PKCS1_OpenSSL())(rsa);
545 static int dasync_rsa_finish(RSA *rsa)
547 return RSA_meth_get_finish(RSA_PKCS1_OpenSSL())(rsa);
550 /* Cipher helper functions */
552 static int dasync_cipher_ctrl_helper(EVP_CIPHER_CTX *ctx, int type, int arg,
553 void *ptr, int aeadcapable)
556 struct dasync_pipeline_ctx *pipe_ctx =
557 (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx);
559 if (pipe_ctx == NULL)
563 case EVP_CTRL_SET_PIPELINE_OUTPUT_BUFS:
564 pipe_ctx->numpipes = arg;
565 pipe_ctx->outbufs = (unsigned char **)ptr;
568 case EVP_CTRL_SET_PIPELINE_INPUT_BUFS:
569 pipe_ctx->numpipes = arg;
570 pipe_ctx->inbufs = (unsigned char **)ptr;
573 case EVP_CTRL_SET_PIPELINE_INPUT_LENS:
574 pipe_ctx->numpipes = arg;
575 pipe_ctx->lens = (size_t *)ptr;
578 case EVP_CTRL_AEAD_SET_MAC_KEY:
581 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx->inner_cipher_data);
582 ret = EVP_CIPHER_meth_get_ctrl(EVP_aes_128_cbc_hmac_sha1())
583 (ctx, type, arg, ptr);
584 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx);
587 case EVP_CTRL_AEAD_TLS1_AAD:
589 unsigned char *p = ptr;
592 if (!aeadcapable || arg != EVP_AEAD_TLS1_AAD_LEN)
595 if (pipe_ctx->aadctr >= SSL_MAX_PIPELINES)
598 memcpy(pipe_ctx->tlsaad[pipe_ctx->aadctr], ptr,
599 EVP_AEAD_TLS1_AAD_LEN);
602 len = p[arg - 2] << 8 | p[arg - 1];
605 if ((p[arg - 4] << 8 | p[arg - 3]) >= TLS1_1_VERSION) {
606 len -= AES_BLOCK_SIZE;
609 return ((len + SHA_DIGEST_LENGTH + AES_BLOCK_SIZE)
610 & -AES_BLOCK_SIZE) - len;
612 return SHA_DIGEST_LENGTH;
623 static int dasync_cipher_init_key_helper(EVP_CIPHER_CTX *ctx,
624 const unsigned char *key,
625 const unsigned char *iv, int enc,
626 const EVP_CIPHER *cipher)
629 struct dasync_pipeline_ctx *pipe_ctx =
630 (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx);
632 if (pipe_ctx->inner_cipher_data == NULL
633 && EVP_CIPHER_impl_ctx_size(cipher) != 0) {
634 pipe_ctx->inner_cipher_data = OPENSSL_zalloc(
635 EVP_CIPHER_impl_ctx_size(cipher));
636 if (pipe_ctx->inner_cipher_data == NULL) {
637 DASYNCerr(DASYNC_F_DASYNC_CIPHER_INIT_KEY_HELPER,
638 ERR_R_MALLOC_FAILURE);
643 pipe_ctx->numpipes = 0;
644 pipe_ctx->aadctr = 0;
646 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx->inner_cipher_data);
647 ret = EVP_CIPHER_meth_get_init(cipher)(ctx, key, iv, enc);
648 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx);
653 static int dasync_cipher_helper(EVP_CIPHER_CTX *ctx, unsigned char *out,
654 const unsigned char *in, size_t inl,
655 const EVP_CIPHER *cipher)
658 unsigned int i, pipes;
659 struct dasync_pipeline_ctx *pipe_ctx =
660 (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx);
662 pipes = pipe_ctx->numpipes;
663 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx->inner_cipher_data);
665 if (pipe_ctx->aadctr != 0) {
666 if (pipe_ctx->aadctr != 1)
668 EVP_CIPHER_meth_get_ctrl(cipher)
669 (ctx, EVP_CTRL_AEAD_TLS1_AAD,
670 EVP_AEAD_TLS1_AAD_LEN,
671 pipe_ctx->tlsaad[0]);
673 ret = EVP_CIPHER_meth_get_do_cipher(cipher)
676 if (pipe_ctx->aadctr > 0 && pipe_ctx->aadctr != pipes)
678 for (i = 0; i < pipes; i++) {
679 if (pipe_ctx->aadctr > 0) {
680 EVP_CIPHER_meth_get_ctrl(cipher)
681 (ctx, EVP_CTRL_AEAD_TLS1_AAD,
682 EVP_AEAD_TLS1_AAD_LEN,
683 pipe_ctx->tlsaad[i]);
685 ret = ret && EVP_CIPHER_meth_get_do_cipher(cipher)
686 (ctx, pipe_ctx->outbufs[i], pipe_ctx->inbufs[i],
689 pipe_ctx->numpipes = 0;
691 pipe_ctx->aadctr = 0;
692 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx);
696 static int dasync_cipher_cleanup_helper(EVP_CIPHER_CTX *ctx,
697 const EVP_CIPHER *cipher)
699 struct dasync_pipeline_ctx *pipe_ctx =
700 (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx);
702 OPENSSL_clear_free(pipe_ctx->inner_cipher_data,
703 EVP_CIPHER_impl_ctx_size(cipher));
709 * AES128 CBC Implementation
712 static int dasync_aes128_cbc_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg,
715 return dasync_cipher_ctrl_helper(ctx, type, arg, ptr, 0);
718 static int dasync_aes128_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
719 const unsigned char *iv, int enc)
721 return dasync_cipher_init_key_helper(ctx, key, iv, enc, EVP_aes_128_cbc());
724 static int dasync_aes128_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
725 const unsigned char *in, size_t inl)
727 return dasync_cipher_helper(ctx, out, in, inl, EVP_aes_128_cbc());
730 static int dasync_aes128_cbc_cleanup(EVP_CIPHER_CTX *ctx)
732 return dasync_cipher_cleanup_helper(ctx, EVP_aes_128_cbc());
737 * AES128 CBC HMAC SHA1 Implementation
740 static int dasync_aes128_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type,
743 return dasync_cipher_ctrl_helper(ctx, type, arg, ptr, 1);
746 static int dasync_aes128_cbc_hmac_sha1_init_key(EVP_CIPHER_CTX *ctx,
747 const unsigned char *key,
748 const unsigned char *iv,
751 return dasync_cipher_init_key_helper(ctx, key, iv, enc,
752 EVP_aes_128_cbc_hmac_sha1());
755 static int dasync_aes128_cbc_hmac_sha1_cipher(EVP_CIPHER_CTX *ctx,
757 const unsigned char *in,
760 return dasync_cipher_helper(ctx, out, in, inl, EVP_aes_128_cbc_hmac_sha1());
763 static int dasync_aes128_cbc_hmac_sha1_cleanup(EVP_CIPHER_CTX *ctx)
765 return dasync_cipher_cleanup_helper(ctx, EVP_aes_128_cbc_hmac_sha1());