static int dasync_cipher_helper(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl, const EVP_CIPHER *cipher) { int ret = 1; unsigned int i, pipes; struct dasync_pipeline_ctx *pipe_ctx = (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx); pipes = pipe_ctx->numpipes; EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx->inner_cipher_data); if (pipes == 0) { if (pipe_ctx->aadctr != 0) { if (pipe_ctx->aadctr != 1) return -1; EVP_CIPHER_meth_get_ctrl(cipher) (ctx, EVP_CTRL_AEAD_TLS1_AAD, EVP_AEAD_TLS1_AAD_LEN, pipe_ctx->tlsaad[0]); } ret = EVP_CIPHER_meth_get_do_cipher(cipher) (ctx, out, in, inl); } else { if (pipe_ctx->aadctr > 0 && pipe_ctx->aadctr != pipes) return -1; for (i = 0; i < pipes; i++) { if (pipe_ctx->aadctr > 0) { EVP_CIPHER_meth_get_ctrl(cipher) (ctx, EVP_CTRL_AEAD_TLS1_AAD, EVP_AEAD_TLS1_AAD_LEN, pipe_ctx->tlsaad[i]); } ret = ret && EVP_CIPHER_meth_get_do_cipher(cipher) (ctx, pipe_ctx->outbufs[i], pipe_ctx->inbufs[i], pipe_ctx->lens[i]); } pipe_ctx->numpipes = 0; } pipe_ctx->aadctr = 0; EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx); return ret; }
int ossltest_aes128_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) { unsigned char *tmpbuf; int ret; tmpbuf = OPENSSL_malloc(inl); if (tmpbuf == NULL) return -1; /* Remember what we were asked to encrypt */ memcpy(tmpbuf, in, inl); /* Go through the motions of encrypting it */ ret = EVP_CIPHER_meth_get_do_cipher(EVP_aes_128_cbc())(ctx, out, in, inl); /* Throw it all away and just use the plaintext as the output */ memcpy(out, tmpbuf, inl); OPENSSL_free(tmpbuf); return ret; }