2 * Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (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 ASYNC_callback_fn callback;
407 OSSL_ASYNC_FD pipefds[2] = {0, 0};
408 OSSL_ASYNC_FD *writefd;
409 #if defined(ASYNC_WIN)
410 DWORD numwritten, numread;
411 char buf = DUMMY_CHAR;
412 #elif defined(ASYNC_POSIX)
413 char buf = DUMMY_CHAR;
416 if ((job = ASYNC_get_current_job()) == NULL)
419 waitctx = ASYNC_get_wait_ctx(job);
421 if (ASYNC_WAIT_CTX_get_callback(waitctx, &callback, &callback_arg) && callback != NULL) {
423 * In the Dummy async engine we are cheating. We call the callback that the job
424 * is complete before the call to ASYNC_pause_job(). A real
425 * async engine would only call the callback when the job was actually complete
427 (*callback)(callback_arg);
433 if (ASYNC_WAIT_CTX_get_fd(waitctx, engine_dasync_id, &pipefds[0],
434 (void **)&writefd)) {
435 pipefds[1] = *writefd;
437 writefd = OPENSSL_malloc(sizeof(*writefd));
440 #if defined(ASYNC_WIN)
441 if (CreatePipe(&pipefds[0], &pipefds[1], NULL, 256) == 0) {
442 OPENSSL_free(writefd);
445 #elif defined(ASYNC_POSIX)
446 if (pipe(pipefds) != 0) {
447 OPENSSL_free(writefd);
451 *writefd = pipefds[1];
453 if (!ASYNC_WAIT_CTX_set_wait_fd(waitctx, engine_dasync_id, pipefds[0],
454 writefd, wait_cleanup)) {
455 wait_cleanup(waitctx, engine_dasync_id, pipefds[0], writefd);
460 * In the Dummy async engine we are cheating. We signal that the job
461 * is complete by waking it before the call to ASYNC_pause_job(). A real
462 * async engine would only wake when the job was actually complete
464 #if defined(ASYNC_WIN)
465 WriteFile(pipefds[1], &buf, 1, &numwritten, NULL);
466 #elif defined(ASYNC_POSIX)
467 if (write(pipefds[1], &buf, 1) < 0)
471 /* Ignore errors - we carry on anyway */
474 /* Clear the wake signal */
475 #if defined(ASYNC_WIN)
476 ReadFile(pipefds[0], &buf, 1, &numread, NULL);
477 #elif defined(ASYNC_POSIX)
478 if (read(pipefds[0], &buf, 1) < 0)
484 * SHA1 implementation. At the moment we just defer to the standard
488 #define data(ctx) ((SHA_CTX *)EVP_MD_CTX_md_data(ctx))
489 static int dasync_sha1_init(EVP_MD_CTX *ctx)
493 return SHA1_Init(data(ctx));
496 static int dasync_sha1_update(EVP_MD_CTX *ctx, const void *data,
501 return SHA1_Update(data(ctx), data, (size_t)count);
504 static int dasync_sha1_final(EVP_MD_CTX *ctx, unsigned char *md)
508 return SHA1_Final(md, data(ctx));
515 static int dasync_pub_enc(int flen, const unsigned char *from,
516 unsigned char *to, RSA *rsa, int padding) {
517 /* Ignore errors - we carry on anyway */
519 return RSA_meth_get_pub_enc(RSA_PKCS1_OpenSSL())
520 (flen, from, to, rsa, padding);
523 static int dasync_pub_dec(int flen, const unsigned char *from,
524 unsigned char *to, RSA *rsa, int padding) {
525 /* Ignore errors - we carry on anyway */
527 return RSA_meth_get_pub_dec(RSA_PKCS1_OpenSSL())
528 (flen, from, to, rsa, padding);
531 static int dasync_rsa_priv_enc(int flen, const unsigned char *from,
532 unsigned char *to, RSA *rsa, int padding)
534 /* Ignore errors - we carry on anyway */
536 return RSA_meth_get_priv_enc(RSA_PKCS1_OpenSSL())
537 (flen, from, to, rsa, padding);
540 static int dasync_rsa_priv_dec(int flen, const unsigned char *from,
541 unsigned char *to, RSA *rsa, int padding)
543 /* Ignore errors - we carry on anyway */
545 return RSA_meth_get_priv_dec(RSA_PKCS1_OpenSSL())
546 (flen, from, to, rsa, padding);
549 static int dasync_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
551 /* Ignore errors - we carry on anyway */
553 return RSA_meth_get_mod_exp(RSA_PKCS1_OpenSSL())(r0, I, rsa, ctx);
556 static int dasync_rsa_init(RSA *rsa)
558 return RSA_meth_get_init(RSA_PKCS1_OpenSSL())(rsa);
560 static int dasync_rsa_finish(RSA *rsa)
562 return RSA_meth_get_finish(RSA_PKCS1_OpenSSL())(rsa);
565 /* Cipher helper functions */
567 static int dasync_cipher_ctrl_helper(EVP_CIPHER_CTX *ctx, int type, int arg,
568 void *ptr, int aeadcapable)
571 struct dasync_pipeline_ctx *pipe_ctx =
572 (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx);
574 if (pipe_ctx == NULL)
578 case EVP_CTRL_SET_PIPELINE_OUTPUT_BUFS:
579 pipe_ctx->numpipes = arg;
580 pipe_ctx->outbufs = (unsigned char **)ptr;
583 case EVP_CTRL_SET_PIPELINE_INPUT_BUFS:
584 pipe_ctx->numpipes = arg;
585 pipe_ctx->inbufs = (unsigned char **)ptr;
588 case EVP_CTRL_SET_PIPELINE_INPUT_LENS:
589 pipe_ctx->numpipes = arg;
590 pipe_ctx->lens = (size_t *)ptr;
593 case EVP_CTRL_AEAD_SET_MAC_KEY:
596 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx->inner_cipher_data);
597 ret = EVP_CIPHER_meth_get_ctrl(EVP_aes_128_cbc_hmac_sha1())
598 (ctx, type, arg, ptr);
599 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx);
602 case EVP_CTRL_AEAD_TLS1_AAD:
604 unsigned char *p = ptr;
607 if (!aeadcapable || arg != EVP_AEAD_TLS1_AAD_LEN)
610 if (pipe_ctx->aadctr >= SSL_MAX_PIPELINES)
613 memcpy(pipe_ctx->tlsaad[pipe_ctx->aadctr], ptr,
614 EVP_AEAD_TLS1_AAD_LEN);
617 len = p[arg - 2] << 8 | p[arg - 1];
619 if (EVP_CIPHER_CTX_encrypting(ctx)) {
620 if ((p[arg - 4] << 8 | p[arg - 3]) >= TLS1_1_VERSION) {
621 if (len < AES_BLOCK_SIZE)
623 len -= AES_BLOCK_SIZE;
626 return ((len + SHA_DIGEST_LENGTH + AES_BLOCK_SIZE)
627 & -AES_BLOCK_SIZE) - len;
629 return SHA_DIGEST_LENGTH;
640 static int dasync_cipher_init_key_helper(EVP_CIPHER_CTX *ctx,
641 const unsigned char *key,
642 const unsigned char *iv, int enc,
643 const EVP_CIPHER *cipher)
646 struct dasync_pipeline_ctx *pipe_ctx =
647 (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx);
649 if (pipe_ctx->inner_cipher_data == NULL
650 && EVP_CIPHER_impl_ctx_size(cipher) != 0) {
651 pipe_ctx->inner_cipher_data = OPENSSL_zalloc(
652 EVP_CIPHER_impl_ctx_size(cipher));
653 if (pipe_ctx->inner_cipher_data == NULL) {
654 DASYNCerr(DASYNC_F_DASYNC_CIPHER_INIT_KEY_HELPER,
655 ERR_R_MALLOC_FAILURE);
660 pipe_ctx->numpipes = 0;
661 pipe_ctx->aadctr = 0;
663 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx->inner_cipher_data);
664 ret = EVP_CIPHER_meth_get_init(cipher)(ctx, key, iv, enc);
665 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx);
670 static int dasync_cipher_helper(EVP_CIPHER_CTX *ctx, unsigned char *out,
671 const unsigned char *in, size_t inl,
672 const EVP_CIPHER *cipher)
675 unsigned int i, pipes;
676 struct dasync_pipeline_ctx *pipe_ctx =
677 (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx);
679 pipes = pipe_ctx->numpipes;
680 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx->inner_cipher_data);
682 if (pipe_ctx->aadctr != 0) {
683 if (pipe_ctx->aadctr != 1)
685 EVP_CIPHER_meth_get_ctrl(cipher)
686 (ctx, EVP_CTRL_AEAD_TLS1_AAD,
687 EVP_AEAD_TLS1_AAD_LEN,
688 pipe_ctx->tlsaad[0]);
690 ret = EVP_CIPHER_meth_get_do_cipher(cipher)
693 if (pipe_ctx->aadctr > 0 && pipe_ctx->aadctr != pipes)
695 for (i = 0; i < pipes; i++) {
696 if (pipe_ctx->aadctr > 0) {
697 EVP_CIPHER_meth_get_ctrl(cipher)
698 (ctx, EVP_CTRL_AEAD_TLS1_AAD,
699 EVP_AEAD_TLS1_AAD_LEN,
700 pipe_ctx->tlsaad[i]);
702 ret = ret && EVP_CIPHER_meth_get_do_cipher(cipher)
703 (ctx, pipe_ctx->outbufs[i], pipe_ctx->inbufs[i],
706 pipe_ctx->numpipes = 0;
708 pipe_ctx->aadctr = 0;
709 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx);
713 static int dasync_cipher_cleanup_helper(EVP_CIPHER_CTX *ctx,
714 const EVP_CIPHER *cipher)
716 struct dasync_pipeline_ctx *pipe_ctx =
717 (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx);
719 OPENSSL_clear_free(pipe_ctx->inner_cipher_data,
720 EVP_CIPHER_impl_ctx_size(cipher));
726 * AES128 CBC Implementation
729 static int dasync_aes128_cbc_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg,
732 return dasync_cipher_ctrl_helper(ctx, type, arg, ptr, 0);
735 static int dasync_aes128_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
736 const unsigned char *iv, int enc)
738 return dasync_cipher_init_key_helper(ctx, key, iv, enc, EVP_aes_128_cbc());
741 static int dasync_aes128_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
742 const unsigned char *in, size_t inl)
744 return dasync_cipher_helper(ctx, out, in, inl, EVP_aes_128_cbc());
747 static int dasync_aes128_cbc_cleanup(EVP_CIPHER_CTX *ctx)
749 return dasync_cipher_cleanup_helper(ctx, EVP_aes_128_cbc());
754 * AES128 CBC HMAC SHA1 Implementation
757 static int dasync_aes128_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type,
760 return dasync_cipher_ctrl_helper(ctx, type, arg, ptr, 1);
763 static int dasync_aes128_cbc_hmac_sha1_init_key(EVP_CIPHER_CTX *ctx,
764 const unsigned char *key,
765 const unsigned char *iv,
768 return dasync_cipher_init_key_helper(ctx, key, iv, enc,
769 EVP_aes_128_cbc_hmac_sha1());
772 static int dasync_aes128_cbc_hmac_sha1_cipher(EVP_CIPHER_CTX *ctx,
774 const unsigned char *in,
777 return dasync_cipher_helper(ctx, out, in, inl, EVP_aes_128_cbc_hmac_sha1());
780 static int dasync_aes128_cbc_hmac_sha1_cleanup(EVP_CIPHER_CTX *ctx)
782 return dasync_cipher_cleanup_helper(ctx, EVP_aes_128_cbc_hmac_sha1());