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;
142 unsigned char tlsaad[SSL_MAX_PIPELINES][EVP_AEAD_TLS1_AAD_LEN];
147 * Holds the EVP_CIPHER object for aes_128_cbc in this engine. Set up once only
148 * during engine bind and can then be reused many times.
150 static EVP_CIPHER *_hidden_aes_128_cbc = NULL;
151 static const EVP_CIPHER *dasync_aes_128_cbc(void)
153 return _hidden_aes_128_cbc;
157 * Holds the EVP_CIPHER object for aes_128_cbc_hmac_sha1 in this engine. Set up
158 * once only during engine bind and can then be reused many times.
160 static EVP_CIPHER *_hidden_aes_128_cbc_hmac_sha1 = NULL;
161 static const EVP_CIPHER *dasync_aes_128_cbc_hmac_sha1(void)
163 return _hidden_aes_128_cbc_hmac_sha1;
166 static void destroy_ciphers(void)
168 EVP_CIPHER_meth_free(_hidden_aes_128_cbc);
169 EVP_CIPHER_meth_free(_hidden_aes_128_cbc_hmac_sha1);
170 _hidden_aes_128_cbc = NULL;
171 _hidden_aes_128_cbc_hmac_sha1 = NULL;
174 static int dasync_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
175 const int **nids, int nid);
177 static int dasync_cipher_nids[] = {
179 NID_aes_128_cbc_hmac_sha1,
183 static int bind_dasync(ENGINE *e)
185 /* Setup RSA_METHOD */
186 if ((dasync_rsa_method = RSA_meth_new("Dummy Async RSA method", 0)) == NULL
187 || RSA_meth_set_pub_enc(dasync_rsa_method, dasync_pub_enc) == 0
188 || RSA_meth_set_pub_dec(dasync_rsa_method, dasync_pub_dec) == 0
189 || RSA_meth_set_priv_enc(dasync_rsa_method, dasync_rsa_priv_enc) == 0
190 || RSA_meth_set_priv_dec(dasync_rsa_method, dasync_rsa_priv_dec) == 0
191 || RSA_meth_set_mod_exp(dasync_rsa_method, dasync_rsa_mod_exp) == 0
192 || RSA_meth_set_bn_mod_exp(dasync_rsa_method, BN_mod_exp_mont) == 0
193 || RSA_meth_set_init(dasync_rsa_method, dasync_rsa_init) == 0
194 || RSA_meth_set_finish(dasync_rsa_method, dasync_rsa_finish) == 0) {
195 DASYNCerr(DASYNC_F_BIND_DASYNC, DASYNC_R_INIT_FAILED);
199 /* Ensure the dasync error handling is set up */
200 ERR_load_DASYNC_strings();
202 if (!ENGINE_set_id(e, engine_dasync_id)
203 || !ENGINE_set_name(e, engine_dasync_name)
204 || !ENGINE_set_RSA(e, dasync_rsa_method)
205 || !ENGINE_set_digests(e, dasync_digests)
206 || !ENGINE_set_ciphers(e, dasync_ciphers)
207 || !ENGINE_set_destroy_function(e, dasync_destroy)
208 || !ENGINE_set_init_function(e, dasync_init)
209 || !ENGINE_set_finish_function(e, dasync_finish)) {
210 DASYNCerr(DASYNC_F_BIND_DASYNC, DASYNC_R_INIT_FAILED);
215 * Set up the EVP_CIPHER and EVP_MD objects for the ciphers/digests
216 * supplied by this engine
218 _hidden_sha1_md = EVP_MD_meth_new(NID_sha1, NID_sha1WithRSAEncryption);
219 if (_hidden_sha1_md == NULL
220 || !EVP_MD_meth_set_result_size(_hidden_sha1_md, SHA_DIGEST_LENGTH)
221 || !EVP_MD_meth_set_input_blocksize(_hidden_sha1_md, SHA_CBLOCK)
222 || !EVP_MD_meth_set_app_datasize(_hidden_sha1_md,
223 sizeof(EVP_MD *) + sizeof(SHA_CTX))
224 || !EVP_MD_meth_set_flags(_hidden_sha1_md, EVP_MD_FLAG_DIGALGID_ABSENT)
225 || !EVP_MD_meth_set_init(_hidden_sha1_md, dasync_sha1_init)
226 || !EVP_MD_meth_set_update(_hidden_sha1_md, dasync_sha1_update)
227 || !EVP_MD_meth_set_final(_hidden_sha1_md, dasync_sha1_final)) {
228 EVP_MD_meth_free(_hidden_sha1_md);
229 _hidden_sha1_md = NULL;
232 _hidden_aes_128_cbc = EVP_CIPHER_meth_new(NID_aes_128_cbc,
235 if (_hidden_aes_128_cbc == NULL
236 || !EVP_CIPHER_meth_set_iv_length(_hidden_aes_128_cbc,16)
237 || !EVP_CIPHER_meth_set_flags(_hidden_aes_128_cbc,
238 EVP_CIPH_FLAG_DEFAULT_ASN1
240 | EVP_CIPH_FLAG_PIPELINE)
241 || !EVP_CIPHER_meth_set_init(_hidden_aes_128_cbc,
242 dasync_aes128_init_key)
243 || !EVP_CIPHER_meth_set_do_cipher(_hidden_aes_128_cbc,
244 dasync_aes128_cbc_cipher)
245 || !EVP_CIPHER_meth_set_cleanup(_hidden_aes_128_cbc,
246 dasync_aes128_cbc_cleanup)
247 || !EVP_CIPHER_meth_set_ctrl(_hidden_aes_128_cbc,
248 dasync_aes128_cbc_ctrl)
249 || !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_aes_128_cbc,
250 sizeof(struct dasync_pipeline_ctx))) {
251 EVP_CIPHER_meth_free(_hidden_aes_128_cbc);
252 _hidden_aes_128_cbc = NULL;
255 _hidden_aes_128_cbc_hmac_sha1 = EVP_CIPHER_meth_new(
256 NID_aes_128_cbc_hmac_sha1,
259 if (_hidden_aes_128_cbc_hmac_sha1 == NULL
260 || !EVP_CIPHER_meth_set_iv_length(_hidden_aes_128_cbc_hmac_sha1,16)
261 || !EVP_CIPHER_meth_set_flags(_hidden_aes_128_cbc_hmac_sha1,
263 | EVP_CIPH_FLAG_DEFAULT_ASN1
264 | EVP_CIPH_FLAG_AEAD_CIPHER
265 | EVP_CIPH_FLAG_PIPELINE)
266 || !EVP_CIPHER_meth_set_init(_hidden_aes_128_cbc_hmac_sha1,
267 dasync_aes128_cbc_hmac_sha1_init_key)
268 || !EVP_CIPHER_meth_set_do_cipher(_hidden_aes_128_cbc_hmac_sha1,
269 dasync_aes128_cbc_hmac_sha1_cipher)
270 || !EVP_CIPHER_meth_set_cleanup(_hidden_aes_128_cbc_hmac_sha1,
271 dasync_aes128_cbc_hmac_sha1_cleanup)
272 || !EVP_CIPHER_meth_set_ctrl(_hidden_aes_128_cbc_hmac_sha1,
273 dasync_aes128_cbc_hmac_sha1_ctrl)
274 || !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_aes_128_cbc_hmac_sha1,
275 sizeof(struct dasync_pipeline_ctx))) {
276 EVP_CIPHER_meth_free(_hidden_aes_128_cbc_hmac_sha1);
277 _hidden_aes_128_cbc_hmac_sha1 = NULL;
283 # ifndef OPENSSL_NO_DYNAMIC_ENGINE
284 static int bind_helper(ENGINE *e, const char *id)
286 if (id && (strcmp(id, engine_dasync_id) != 0))
293 IMPLEMENT_DYNAMIC_CHECK_FN()
294 IMPLEMENT_DYNAMIC_BIND_FN(bind_helper)
297 static ENGINE *engine_dasync(void)
299 ENGINE *ret = ENGINE_new();
302 if (!bind_dasync(ret)) {
309 void engine_load_dasync_int(void)
311 ENGINE *toadd = engine_dasync();
319 static int dasync_init(ENGINE *e)
325 static int dasync_finish(ENGINE *e)
331 static int dasync_destroy(ENGINE *e)
335 RSA_meth_free(dasync_rsa_method);
336 ERR_unload_DASYNC_strings();
340 static int dasync_digests(ENGINE *e, const EVP_MD **digest,
341 const int **nids, int nid)
345 /* We are returning a list of supported nids */
346 return dasync_digest_nids(nids);
348 /* We are being asked for a specific digest */
351 *digest = dasync_sha1();
361 static int dasync_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
362 const int **nids, int nid)
365 if (cipher == NULL) {
366 /* We are returning a list of supported nids */
367 *nids = dasync_cipher_nids;
368 return (sizeof(dasync_cipher_nids) -
369 1) / sizeof(dasync_cipher_nids[0]);
371 /* We are being asked for a specific cipher */
373 case NID_aes_128_cbc:
374 *cipher = dasync_aes_128_cbc();
376 case NID_aes_128_cbc_hmac_sha1:
377 *cipher = dasync_aes_128_cbc_hmac_sha1();
387 static void wait_cleanup(ASYNC_WAIT_CTX *ctx, const void *key,
388 OSSL_ASYNC_FD readfd, void *pvwritefd)
390 OSSL_ASYNC_FD *pwritefd = (OSSL_ASYNC_FD *)pvwritefd;
391 #if defined(ASYNC_WIN)
393 CloseHandle(*pwritefd);
394 #elif defined(ASYNC_POSIX)
398 OPENSSL_free(pwritefd);
401 #define DUMMY_CHAR 'X'
403 static void dummy_pause_job(void) {
405 ASYNC_WAIT_CTX *waitctx;
406 ASYNC_callback_fn callback;
408 OSSL_ASYNC_FD pipefds[2] = {0, 0};
409 OSSL_ASYNC_FD *writefd;
410 #if defined(ASYNC_WIN)
411 DWORD numwritten, numread;
412 char buf = DUMMY_CHAR;
413 #elif defined(ASYNC_POSIX)
414 char buf = DUMMY_CHAR;
417 if ((job = ASYNC_get_current_job()) == NULL)
420 waitctx = ASYNC_get_wait_ctx(job);
422 if (ASYNC_WAIT_CTX_get_callback(waitctx, &callback, &callback_arg) && callback != NULL) {
424 * In the Dummy async engine we are cheating. We call the callback that the job
425 * is complete before the call to ASYNC_pause_job(). A real
426 * async engine would only call the callback when the job was actually complete
428 (*callback)(callback_arg);
434 if (ASYNC_WAIT_CTX_get_fd(waitctx, engine_dasync_id, &pipefds[0],
435 (void **)&writefd)) {
436 pipefds[1] = *writefd;
438 writefd = OPENSSL_malloc(sizeof(*writefd));
441 #if defined(ASYNC_WIN)
442 if (CreatePipe(&pipefds[0], &pipefds[1], NULL, 256) == 0) {
443 OPENSSL_free(writefd);
446 #elif defined(ASYNC_POSIX)
447 if (pipe(pipefds) != 0) {
448 OPENSSL_free(writefd);
452 *writefd = pipefds[1];
454 if (!ASYNC_WAIT_CTX_set_wait_fd(waitctx, engine_dasync_id, pipefds[0],
455 writefd, wait_cleanup)) {
456 wait_cleanup(waitctx, engine_dasync_id, pipefds[0], writefd);
461 * In the Dummy async engine we are cheating. We signal that the job
462 * is complete by waking it before the call to ASYNC_pause_job(). A real
463 * async engine would only wake when the job was actually complete
465 #if defined(ASYNC_WIN)
466 WriteFile(pipefds[1], &buf, 1, &numwritten, NULL);
467 #elif defined(ASYNC_POSIX)
468 if (write(pipefds[1], &buf, 1) < 0)
472 /* Ignore errors - we carry on anyway */
475 /* Clear the wake signal */
476 #if defined(ASYNC_WIN)
477 ReadFile(pipefds[0], &buf, 1, &numread, NULL);
478 #elif defined(ASYNC_POSIX)
479 if (read(pipefds[0], &buf, 1) < 0)
485 * SHA1 implementation. At the moment we just defer to the standard
489 #define data(ctx) ((SHA_CTX *)EVP_MD_CTX_md_data(ctx))
490 static int dasync_sha1_init(EVP_MD_CTX *ctx)
494 return SHA1_Init(data(ctx));
497 static int dasync_sha1_update(EVP_MD_CTX *ctx, const void *data,
502 return SHA1_Update(data(ctx), data, (size_t)count);
505 static int dasync_sha1_final(EVP_MD_CTX *ctx, unsigned char *md)
509 return SHA1_Final(md, data(ctx));
516 static int dasync_pub_enc(int flen, const unsigned char *from,
517 unsigned char *to, RSA *rsa, int padding) {
518 /* Ignore errors - we carry on anyway */
520 return RSA_meth_get_pub_enc(RSA_PKCS1_OpenSSL())
521 (flen, from, to, rsa, padding);
524 static int dasync_pub_dec(int flen, const unsigned char *from,
525 unsigned char *to, RSA *rsa, int padding) {
526 /* Ignore errors - we carry on anyway */
528 return RSA_meth_get_pub_dec(RSA_PKCS1_OpenSSL())
529 (flen, from, to, rsa, padding);
532 static int dasync_rsa_priv_enc(int flen, const unsigned char *from,
533 unsigned char *to, RSA *rsa, int padding)
535 /* Ignore errors - we carry on anyway */
537 return RSA_meth_get_priv_enc(RSA_PKCS1_OpenSSL())
538 (flen, from, to, rsa, padding);
541 static int dasync_rsa_priv_dec(int flen, const unsigned char *from,
542 unsigned char *to, RSA *rsa, int padding)
544 /* Ignore errors - we carry on anyway */
546 return RSA_meth_get_priv_dec(RSA_PKCS1_OpenSSL())
547 (flen, from, to, rsa, padding);
550 static int dasync_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
552 /* Ignore errors - we carry on anyway */
554 return RSA_meth_get_mod_exp(RSA_PKCS1_OpenSSL())(r0, I, rsa, ctx);
557 static int dasync_rsa_init(RSA *rsa)
559 return RSA_meth_get_init(RSA_PKCS1_OpenSSL())(rsa);
561 static int dasync_rsa_finish(RSA *rsa)
563 return RSA_meth_get_finish(RSA_PKCS1_OpenSSL())(rsa);
566 /* Cipher helper functions */
568 static int dasync_cipher_ctrl_helper(EVP_CIPHER_CTX *ctx, int type, int arg,
569 void *ptr, int aeadcapable)
572 struct dasync_pipeline_ctx *pipe_ctx =
573 (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx);
575 if (pipe_ctx == NULL)
579 case EVP_CTRL_SET_PIPELINE_OUTPUT_BUFS:
580 pipe_ctx->numpipes = arg;
581 pipe_ctx->outbufs = (unsigned char **)ptr;
584 case EVP_CTRL_SET_PIPELINE_INPUT_BUFS:
585 pipe_ctx->numpipes = arg;
586 pipe_ctx->inbufs = (unsigned char **)ptr;
589 case EVP_CTRL_SET_PIPELINE_INPUT_LENS:
590 pipe_ctx->numpipes = arg;
591 pipe_ctx->lens = (size_t *)ptr;
594 case EVP_CTRL_AEAD_SET_MAC_KEY:
597 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx->inner_cipher_data);
598 ret = EVP_CIPHER_meth_get_ctrl(EVP_aes_128_cbc_hmac_sha1())
599 (ctx, type, arg, ptr);
600 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx);
603 case EVP_CTRL_AEAD_TLS1_AAD:
605 unsigned char *p = ptr;
608 if (!aeadcapable || arg != EVP_AEAD_TLS1_AAD_LEN)
611 if (pipe_ctx->aadctr >= SSL_MAX_PIPELINES)
614 memcpy(pipe_ctx->tlsaad[pipe_ctx->aadctr], ptr,
615 EVP_AEAD_TLS1_AAD_LEN);
618 len = p[arg - 2] << 8 | p[arg - 1];
621 if ((p[arg - 4] << 8 | p[arg - 3]) >= TLS1_1_VERSION) {
622 if (len < AES_BLOCK_SIZE)
624 len -= AES_BLOCK_SIZE;
627 return ((len + SHA_DIGEST_LENGTH + AES_BLOCK_SIZE)
628 & -AES_BLOCK_SIZE) - len;
630 return SHA_DIGEST_LENGTH;
641 static int dasync_cipher_init_key_helper(EVP_CIPHER_CTX *ctx,
642 const unsigned char *key,
643 const unsigned char *iv, int enc,
644 const EVP_CIPHER *cipher)
647 struct dasync_pipeline_ctx *pipe_ctx =
648 (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx);
650 if (pipe_ctx->inner_cipher_data == NULL
651 && EVP_CIPHER_impl_ctx_size(cipher) != 0) {
652 pipe_ctx->inner_cipher_data = OPENSSL_zalloc(
653 EVP_CIPHER_impl_ctx_size(cipher));
654 if (pipe_ctx->inner_cipher_data == NULL) {
655 DASYNCerr(DASYNC_F_DASYNC_CIPHER_INIT_KEY_HELPER,
656 ERR_R_MALLOC_FAILURE);
661 pipe_ctx->numpipes = 0;
662 pipe_ctx->aadctr = 0;
664 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx->inner_cipher_data);
665 ret = EVP_CIPHER_meth_get_init(cipher)(ctx, key, iv, enc);
666 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx);
671 static int dasync_cipher_helper(EVP_CIPHER_CTX *ctx, unsigned char *out,
672 const unsigned char *in, size_t inl,
673 const EVP_CIPHER *cipher)
676 unsigned int i, pipes;
677 struct dasync_pipeline_ctx *pipe_ctx =
678 (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx);
680 pipes = pipe_ctx->numpipes;
681 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx->inner_cipher_data);
683 if (pipe_ctx->aadctr != 0) {
684 if (pipe_ctx->aadctr != 1)
686 EVP_CIPHER_meth_get_ctrl(cipher)
687 (ctx, EVP_CTRL_AEAD_TLS1_AAD,
688 EVP_AEAD_TLS1_AAD_LEN,
689 pipe_ctx->tlsaad[0]);
691 ret = EVP_CIPHER_meth_get_do_cipher(cipher)
694 if (pipe_ctx->aadctr > 0 && pipe_ctx->aadctr != pipes)
696 for (i = 0; i < pipes; i++) {
697 if (pipe_ctx->aadctr > 0) {
698 EVP_CIPHER_meth_get_ctrl(cipher)
699 (ctx, EVP_CTRL_AEAD_TLS1_AAD,
700 EVP_AEAD_TLS1_AAD_LEN,
701 pipe_ctx->tlsaad[i]);
703 ret = ret && EVP_CIPHER_meth_get_do_cipher(cipher)
704 (ctx, pipe_ctx->outbufs[i], pipe_ctx->inbufs[i],
707 pipe_ctx->numpipes = 0;
709 pipe_ctx->aadctr = 0;
710 EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx);
714 static int dasync_cipher_cleanup_helper(EVP_CIPHER_CTX *ctx,
715 const EVP_CIPHER *cipher)
717 struct dasync_pipeline_ctx *pipe_ctx =
718 (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx);
720 OPENSSL_clear_free(pipe_ctx->inner_cipher_data,
721 EVP_CIPHER_impl_ctx_size(cipher));
727 * AES128 CBC Implementation
730 static int dasync_aes128_cbc_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg,
733 return dasync_cipher_ctrl_helper(ctx, type, arg, ptr, 0);
736 static int dasync_aes128_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
737 const unsigned char *iv, int enc)
739 return dasync_cipher_init_key_helper(ctx, key, iv, enc, EVP_aes_128_cbc());
742 static int dasync_aes128_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
743 const unsigned char *in, size_t inl)
745 return dasync_cipher_helper(ctx, out, in, inl, EVP_aes_128_cbc());
748 static int dasync_aes128_cbc_cleanup(EVP_CIPHER_CTX *ctx)
750 return dasync_cipher_cleanup_helper(ctx, EVP_aes_128_cbc());
755 * AES128 CBC HMAC SHA1 Implementation
758 static int dasync_aes128_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type,
761 return dasync_cipher_ctrl_helper(ctx, type, arg, ptr, 1);
764 static int dasync_aes128_cbc_hmac_sha1_init_key(EVP_CIPHER_CTX *ctx,
765 const unsigned char *key,
766 const unsigned char *iv,
769 return dasync_cipher_init_key_helper(ctx, key, iv, enc,
770 EVP_aes_128_cbc_hmac_sha1());
773 static int dasync_aes128_cbc_hmac_sha1_cipher(EVP_CIPHER_CTX *ctx,
775 const unsigned char *in,
778 return dasync_cipher_helper(ctx, out, in, inl, EVP_aes_128_cbc_hmac_sha1());
781 static int dasync_aes128_cbc_hmac_sha1_cleanup(EVP_CIPHER_CTX *ctx)
783 return dasync_cipher_cleanup_helper(ctx, EVP_aes_128_cbc_hmac_sha1());