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 static EVP_CIPHER *_hidden_aes_128_cbc_hmac_sha1 = NULL;
160 static const EVP_CIPHER *dasync_aes_128_cbc_hmac_sha1(void)
162 return _hidden_aes_128_cbc_hmac_sha1;
165 static void destroy_ciphers(void)
167 EVP_CIPHER_meth_free(_hidden_aes_128_cbc);
168 EVP_CIPHER_meth_free(_hidden_aes_128_cbc_hmac_sha1);
169 _hidden_aes_128_cbc = NULL;
170 _hidden_aes_128_cbc_hmac_sha1 = NULL;
173 static int dasync_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
174 const int **nids, int nid);
176 static int dasync_cipher_nids[] = {
178 NID_aes_128_cbc_hmac_sha1,
182 static int bind_dasync(ENGINE *e)
184 /* Setup RSA_METHOD */
185 if ((dasync_rsa_method = RSA_meth_new("Dummy Async RSA method", 0)) == NULL
186 || RSA_meth_set_pub_enc(dasync_rsa_method, dasync_pub_enc) == 0
187 || RSA_meth_set_pub_dec(dasync_rsa_method, dasync_pub_dec) == 0
188 || RSA_meth_set_priv_enc(dasync_rsa_method, dasync_rsa_priv_enc) == 0
189 || RSA_meth_set_priv_dec(dasync_rsa_method, dasync_rsa_priv_dec) == 0
190 || RSA_meth_set_mod_exp(dasync_rsa_method, dasync_rsa_mod_exp) == 0
191 || RSA_meth_set_bn_mod_exp(dasync_rsa_method, BN_mod_exp_mont) == 0
192 || RSA_meth_set_init(dasync_rsa_method, dasync_rsa_init) == 0
193 || RSA_meth_set_finish(dasync_rsa_method, dasync_rsa_finish) == 0) {
194 DASYNCerr(DASYNC_F_BIND_DASYNC, DASYNC_R_INIT_FAILED);
198 /* Ensure the dasync error handling is set up */
199 ERR_load_DASYNC_strings();
201 if (!ENGINE_set_id(e, engine_dasync_id)
202 || !ENGINE_set_name(e, engine_dasync_name)
203 || !ENGINE_set_RSA(e, dasync_rsa_method)
204 || !ENGINE_set_digests(e, dasync_digests)
205 || !ENGINE_set_ciphers(e, dasync_ciphers)
206 || !ENGINE_set_destroy_function(e, dasync_destroy)
207 || !ENGINE_set_init_function(e, dasync_init)
208 || !ENGINE_set_finish_function(e, dasync_finish)) {
209 DASYNCerr(DASYNC_F_BIND_DASYNC, DASYNC_R_INIT_FAILED);
214 * Set up the EVP_CIPHER and EVP_MD objects for the ciphers/digests
215 * supplied by this engine
217 _hidden_sha1_md = EVP_MD_meth_new(NID_sha1, NID_sha1WithRSAEncryption);
218 if (_hidden_sha1_md == NULL
219 || !EVP_MD_meth_set_result_size(_hidden_sha1_md, SHA_DIGEST_LENGTH)
220 || !EVP_MD_meth_set_input_blocksize(_hidden_sha1_md, SHA_CBLOCK)
221 || !EVP_MD_meth_set_app_datasize(_hidden_sha1_md,
222 sizeof(EVP_MD *) + sizeof(SHA_CTX))
223 || !EVP_MD_meth_set_flags(_hidden_sha1_md, EVP_MD_FLAG_DIGALGID_ABSENT)
224 || !EVP_MD_meth_set_init(_hidden_sha1_md, dasync_sha1_init)
225 || !EVP_MD_meth_set_update(_hidden_sha1_md, dasync_sha1_update)
226 || !EVP_MD_meth_set_final(_hidden_sha1_md, dasync_sha1_final)) {
227 EVP_MD_meth_free(_hidden_sha1_md);
228 _hidden_sha1_md = NULL;
231 _hidden_aes_128_cbc = EVP_CIPHER_meth_new(NID_aes_128_cbc,
234 if (_hidden_aes_128_cbc == NULL
235 || !EVP_CIPHER_meth_set_iv_length(_hidden_aes_128_cbc,16)
236 || !EVP_CIPHER_meth_set_flags(_hidden_aes_128_cbc,
237 EVP_CIPH_FLAG_DEFAULT_ASN1
239 | EVP_CIPH_FLAG_PIPELINE)
240 || !EVP_CIPHER_meth_set_init(_hidden_aes_128_cbc,
241 dasync_aes128_init_key)
242 || !EVP_CIPHER_meth_set_do_cipher(_hidden_aes_128_cbc,
243 dasync_aes128_cbc_cipher)
244 || !EVP_CIPHER_meth_set_cleanup(_hidden_aes_128_cbc,
245 dasync_aes128_cbc_cleanup)
246 || !EVP_CIPHER_meth_set_ctrl(_hidden_aes_128_cbc,
247 dasync_aes128_cbc_ctrl)
248 || !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_aes_128_cbc,
249 sizeof(struct dasync_pipeline_ctx))) {
250 EVP_CIPHER_meth_free(_hidden_aes_128_cbc);
251 _hidden_aes_128_cbc = NULL;
254 _hidden_aes_128_cbc_hmac_sha1 = EVP_CIPHER_meth_new(
255 NID_aes_128_cbc_hmac_sha1,
258 if (_hidden_aes_128_cbc_hmac_sha1 == NULL
259 || !EVP_CIPHER_meth_set_iv_length(_hidden_aes_128_cbc_hmac_sha1,16)
260 || !EVP_CIPHER_meth_set_flags(_hidden_aes_128_cbc_hmac_sha1,
262 | EVP_CIPH_FLAG_DEFAULT_ASN1
263 | EVP_CIPH_FLAG_AEAD_CIPHER
264 | EVP_CIPH_FLAG_PIPELINE)
265 || !EVP_CIPHER_meth_set_init(_hidden_aes_128_cbc_hmac_sha1,
266 dasync_aes128_cbc_hmac_sha1_init_key)
267 || !EVP_CIPHER_meth_set_do_cipher(_hidden_aes_128_cbc_hmac_sha1,
268 dasync_aes128_cbc_hmac_sha1_cipher)
269 || !EVP_CIPHER_meth_set_cleanup(_hidden_aes_128_cbc_hmac_sha1,
270 dasync_aes128_cbc_hmac_sha1_cleanup)
271 || !EVP_CIPHER_meth_set_ctrl(_hidden_aes_128_cbc_hmac_sha1,
272 dasync_aes128_cbc_hmac_sha1_ctrl)
273 || !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_aes_128_cbc_hmac_sha1,
274 sizeof(struct dasync_pipeline_ctx))) {
275 EVP_CIPHER_meth_free(_hidden_aes_128_cbc_hmac_sha1);
276 _hidden_aes_128_cbc_hmac_sha1 = NULL;
282 # ifndef OPENSSL_NO_DYNAMIC_ENGINE
283 static int bind_helper(ENGINE *e, const char *id)
285 if (id && (strcmp(id, engine_dasync_id) != 0))
292 IMPLEMENT_DYNAMIC_CHECK_FN()
293 IMPLEMENT_DYNAMIC_BIND_FN(bind_helper)
296 static ENGINE *engine_dasync(void)
298 ENGINE *ret = ENGINE_new();
301 if (!bind_dasync(ret)) {
308 void engine_load_dasync_int(void)
310 ENGINE *toadd = engine_dasync();
318 static int dasync_init(ENGINE *e)
324 static int dasync_finish(ENGINE *e)
330 static int dasync_destroy(ENGINE *e)
334 RSA_meth_free(dasync_rsa_method);
335 ERR_unload_DASYNC_strings();
339 static int dasync_digests(ENGINE *e, const EVP_MD **digest,
340 const int **nids, int nid)
344 /* We are returning a list of supported nids */
345 return dasync_digest_nids(nids);
347 /* We are being asked for a specific digest */
350 *digest = dasync_sha1();
360 static int dasync_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
361 const int **nids, int nid)
364 if (cipher == NULL) {
365 /* We are returning a list of supported nids */
366 *nids = dasync_cipher_nids;
367 return (sizeof(dasync_cipher_nids) -
368 1) / sizeof(dasync_cipher_nids[0]);
370 /* We are being asked for a specific cipher */
372 case NID_aes_128_cbc:
373 *cipher = dasync_aes_128_cbc();
375 case NID_aes_128_cbc_hmac_sha1:
376 *cipher = dasync_aes_128_cbc_hmac_sha1();
386 static void wait_cleanup(ASYNC_WAIT_CTX *ctx, const void *key,
387 OSSL_ASYNC_FD readfd, void *pvwritefd)
389 OSSL_ASYNC_FD *pwritefd = (OSSL_ASYNC_FD *)pvwritefd;
390 #if defined(ASYNC_WIN)
392 CloseHandle(*pwritefd);
393 #elif defined(ASYNC_POSIX)
397 OPENSSL_free(pwritefd);
400 #define DUMMY_CHAR 'X'
402 static void dummy_pause_job(void) {
404 ASYNC_WAIT_CTX *waitctx;
405 OSSL_ASYNC_FD pipefds[2] = {0, 0};
406 OSSL_ASYNC_FD *writefd;
407 #if defined(ASYNC_WIN)
408 DWORD numwritten, numread;
409 char buf = DUMMY_CHAR;
410 #elif defined(ASYNC_POSIX)
411 char buf = DUMMY_CHAR;
414 if ((job = ASYNC_get_current_job()) == NULL)
417 waitctx = ASYNC_get_wait_ctx(job);
419 if (ASYNC_WAIT_CTX_get_fd(waitctx, engine_dasync_id, &pipefds[0],
420 (void **)&writefd)) {
421 pipefds[1] = *writefd;
423 writefd = OPENSSL_malloc(sizeof(*writefd));
426 #if defined(ASYNC_WIN)
427 if (CreatePipe(&pipefds[0], &pipefds[1], NULL, 256) == 0) {
428 OPENSSL_free(writefd);
431 #elif defined(ASYNC_POSIX)
432 if (pipe(pipefds) != 0) {
433 OPENSSL_free(writefd);
437 *writefd = pipefds[1];
439 if (!ASYNC_WAIT_CTX_set_wait_fd(waitctx, engine_dasync_id, pipefds[0],
440 writefd, wait_cleanup)) {
441 wait_cleanup(waitctx, engine_dasync_id, pipefds[0], writefd);
446 * In the Dummy async engine we are cheating. We signal that the job
447 * is complete by waking it before the call to ASYNC_pause_job(). A real
448 * async engine would only wake when the job was actually complete
450 #if defined(ASYNC_WIN)
451 WriteFile(pipefds[1], &buf, 1, &numwritten, NULL);
452 #elif defined(ASYNC_POSIX)
453 if (write(pipefds[1], &buf, 1) < 0)
457 /* Ignore errors - we carry on anyway */
460 /* Clear the wake signal */
461 #if defined(ASYNC_WIN)
462 ReadFile(pipefds[0], &buf, 1, &numread, NULL);
463 #elif defined(ASYNC_POSIX)
464 if (read(pipefds[0], &buf, 1) < 0)
470 * SHA1 implementation. At the moment we just defer to the standard
474 #define data(ctx) ((SHA_CTX *)EVP_MD_CTX_md_data(ctx))
475 static int dasync_sha1_init(EVP_MD_CTX *ctx)
479 return SHA1_Init(data(ctx));
482 static int dasync_sha1_update(EVP_MD_CTX *ctx, const void *data,
487 return SHA1_Update(data(ctx), data, (size_t)count);
490 static int dasync_sha1_final(EVP_MD_CTX *ctx, unsigned char *md)
494 return SHA1_Final(md, data(ctx));
501 static int dasync_pub_enc(int flen, const unsigned char *from,
502 unsigned char *to, RSA *rsa, int padding) {
503 /* Ignore errors - we carry on anyway */
505 return RSA_meth_get_pub_enc(RSA_PKCS1_OpenSSL())
506 (flen, from, to, rsa, padding);
509 static int dasync_pub_dec(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_dec(RSA_PKCS1_OpenSSL())
514 (flen, from, to, rsa, padding);
517 static int dasync_rsa_priv_enc(int flen, const unsigned char *from,
518 unsigned char *to, RSA *rsa, int padding)
520 /* Ignore errors - we carry on anyway */
522 return RSA_meth_get_priv_enc(RSA_PKCS1_OpenSSL())
523 (flen, from, to, rsa, padding);
526 static int dasync_rsa_priv_dec(int flen, const unsigned char *from,
527 unsigned char *to, RSA *rsa, int padding)
529 /* Ignore errors - we carry on anyway */
531 return RSA_meth_get_priv_dec(RSA_PKCS1_OpenSSL())
532 (flen, from, to, rsa, padding);
535 static int dasync_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
537 /* Ignore errors - we carry on anyway */
539 return RSA_meth_get_mod_exp(RSA_PKCS1_OpenSSL())(r0, I, rsa, ctx);
542 static int dasync_rsa_init(RSA *rsa)
544 return RSA_meth_get_init(RSA_PKCS1_OpenSSL())(rsa);
546 static int dasync_rsa_finish(RSA *rsa)
548 return RSA_meth_get_finish(RSA_PKCS1_OpenSSL())(rsa);
551 /* Cipher helper functions */
553 static int dasync_cipher_ctrl_helper(EVP_CIPHER_CTX *ctx, int type, int arg,
554 void *ptr, int aeadcapable)
557 struct dasync_pipeline_ctx *pipe_ctx =
558 (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx);
560 if (pipe_ctx == NULL)
564 case EVP_CTRL_SET_PIPELINE_OUTPUT_BUFS:
565 pipe_ctx->numpipes = arg;
566 pipe_ctx->outbufs = (unsigned char **)ptr;
569 case EVP_CTRL_SET_PIPELINE_INPUT_BUFS:
570 pipe_ctx->numpipes = arg;
571 pipe_ctx->inbufs = (unsigned char **)ptr;
574 case EVP_CTRL_SET_PIPELINE_INPUT_LENS:
575 pipe_ctx->numpipes = arg;
576 pipe_ctx->lens = (size_t *)ptr;
579 case EVP_CTRL_AEAD_SET_MAC_KEY:
582 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx->inner_cipher_data);
583 ret = EVP_CIPHER_meth_get_ctrl(EVP_aes_128_cbc_hmac_sha1())
584 (ctx, type, arg, ptr);
585 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx);
588 case EVP_CTRL_AEAD_TLS1_AAD:
590 unsigned char *p = ptr;
593 if (!aeadcapable || arg != EVP_AEAD_TLS1_AAD_LEN)
596 if (pipe_ctx->aadctr >= SSL_MAX_PIPELINES)
599 memcpy(pipe_ctx->tlsaad[pipe_ctx->aadctr], ptr,
600 EVP_AEAD_TLS1_AAD_LEN);
603 len = p[arg - 2] << 8 | p[arg - 1];
605 if (EVP_CIPHER_CTX_encrypting(ctx)) {
606 if ((p[arg - 4] << 8 | p[arg - 3]) >= TLS1_1_VERSION) {
607 if (len < AES_BLOCK_SIZE)
609 len -= AES_BLOCK_SIZE;
612 return ((len + SHA_DIGEST_LENGTH + AES_BLOCK_SIZE)
613 & -AES_BLOCK_SIZE) - len;
615 return SHA_DIGEST_LENGTH;
626 static int dasync_cipher_init_key_helper(EVP_CIPHER_CTX *ctx,
627 const unsigned char *key,
628 const unsigned char *iv, int enc,
629 const EVP_CIPHER *cipher)
632 struct dasync_pipeline_ctx *pipe_ctx =
633 (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx);
635 if (pipe_ctx->inner_cipher_data == NULL
636 && EVP_CIPHER_impl_ctx_size(cipher) != 0) {
637 pipe_ctx->inner_cipher_data = OPENSSL_zalloc(
638 EVP_CIPHER_impl_ctx_size(cipher));
639 if (pipe_ctx->inner_cipher_data == NULL) {
640 DASYNCerr(DASYNC_F_DASYNC_CIPHER_INIT_KEY_HELPER,
641 ERR_R_MALLOC_FAILURE);
646 pipe_ctx->numpipes = 0;
647 pipe_ctx->aadctr = 0;
649 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx->inner_cipher_data);
650 ret = EVP_CIPHER_meth_get_init(cipher)(ctx, key, iv, enc);
651 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx);
656 static int dasync_cipher_helper(EVP_CIPHER_CTX *ctx, unsigned char *out,
657 const unsigned char *in, size_t inl,
658 const EVP_CIPHER *cipher)
661 unsigned int i, pipes;
662 struct dasync_pipeline_ctx *pipe_ctx =
663 (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx);
665 pipes = pipe_ctx->numpipes;
666 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx->inner_cipher_data);
668 if (pipe_ctx->aadctr != 0) {
669 if (pipe_ctx->aadctr != 1)
671 EVP_CIPHER_meth_get_ctrl(cipher)
672 (ctx, EVP_CTRL_AEAD_TLS1_AAD,
673 EVP_AEAD_TLS1_AAD_LEN,
674 pipe_ctx->tlsaad[0]);
676 ret = EVP_CIPHER_meth_get_do_cipher(cipher)
679 if (pipe_ctx->aadctr > 0 && pipe_ctx->aadctr != pipes)
681 for (i = 0; i < pipes; i++) {
682 if (pipe_ctx->aadctr > 0) {
683 EVP_CIPHER_meth_get_ctrl(cipher)
684 (ctx, EVP_CTRL_AEAD_TLS1_AAD,
685 EVP_AEAD_TLS1_AAD_LEN,
686 pipe_ctx->tlsaad[i]);
688 ret = ret && EVP_CIPHER_meth_get_do_cipher(cipher)
689 (ctx, pipe_ctx->outbufs[i], pipe_ctx->inbufs[i],
692 pipe_ctx->numpipes = 0;
694 pipe_ctx->aadctr = 0;
695 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx);
699 static int dasync_cipher_cleanup_helper(EVP_CIPHER_CTX *ctx,
700 const EVP_CIPHER *cipher)
702 struct dasync_pipeline_ctx *pipe_ctx =
703 (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx);
705 OPENSSL_clear_free(pipe_ctx->inner_cipher_data,
706 EVP_CIPHER_impl_ctx_size(cipher));
712 * AES128 CBC Implementation
715 static int dasync_aes128_cbc_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg,
718 return dasync_cipher_ctrl_helper(ctx, type, arg, ptr, 0);
721 static int dasync_aes128_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
722 const unsigned char *iv, int enc)
724 return dasync_cipher_init_key_helper(ctx, key, iv, enc, EVP_aes_128_cbc());
727 static int dasync_aes128_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
728 const unsigned char *in, size_t inl)
730 return dasync_cipher_helper(ctx, out, in, inl, EVP_aes_128_cbc());
733 static int dasync_aes128_cbc_cleanup(EVP_CIPHER_CTX *ctx)
735 return dasync_cipher_cleanup_helper(ctx, EVP_aes_128_cbc());
740 * AES128 CBC HMAC SHA1 Implementation
743 static int dasync_aes128_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type,
746 return dasync_cipher_ctrl_helper(ctx, type, arg, ptr, 1);
749 static int dasync_aes128_cbc_hmac_sha1_init_key(EVP_CIPHER_CTX *ctx,
750 const unsigned char *key,
751 const unsigned char *iv,
754 return dasync_cipher_init_key_helper(ctx, key, iv, enc,
755 EVP_aes_128_cbc_hmac_sha1());
758 static int dasync_aes128_cbc_hmac_sha1_cipher(EVP_CIPHER_CTX *ctx,
760 const unsigned char *in,
763 return dasync_cipher_helper(ctx, out, in, inl, EVP_aes_128_cbc_hmac_sha1());
766 static int dasync_aes128_cbc_hmac_sha1_cleanup(EVP_CIPHER_CTX *ctx)
768 return dasync_cipher_cleanup_helper(ctx, EVP_aes_128_cbc_hmac_sha1());