Update the dasync engine to add a pipeline cipher
[openssl.git] / engines / e_dasync.c
1 /*
2  * Written by Matt Caswell (matt@openssl.org) for the OpenSSL project.
3  */
4 /* ====================================================================
5  * Copyright (c) 2015 The OpenSSL Project.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in
16  *    the documentation and/or other materials provided with the
17  *    distribution.
18  *
19  * 3. All advertising materials mentioning features or use of this
20  *    software must display the following acknowledgment:
21  *    "This product includes software developed by the OpenSSL Project
22  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
23  *
24  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25  *    endorse or promote products derived from this software without
26  *    prior written permission. For written permission, please contact
27  *    licensing@OpenSSL.org.
28  *
29  * 5. Products derived from this software may not be called "OpenSSL"
30  *    nor may "OpenSSL" appear in their names without prior written
31  *    permission of the OpenSSL Project.
32  *
33  * 6. Redistributions of any form whatsoever must retain the following
34  *    acknowledgment:
35  *    "This product includes software developed by the OpenSSL Project
36  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
37  *
38  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
42  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49  * OF THE POSSIBILITY OF SUCH DAMAGE.
50  * ====================================================================
51  */
52
53 #include <stdio.h>
54 #include <string.h>
55
56 #include <openssl/engine.h>
57 #include <openssl/sha.h>
58 #include <openssl/rsa.h>
59 #include <openssl/evp.h>
60 #include <openssl/async.h>
61 #include <openssl/bn.h>
62 #include <openssl/crypto.h>
63 #include <openssl/ssl.h>
64 #include <openssl/modes.h>
65
66 #if (defined(OPENSSL_SYS_UNIX) || defined(OPENSSL_SYS_CYGWIN)) && defined(OPENSSL_THREADS)
67 # undef ASYNC_POSIX
68 # define ASYNC_POSIX
69 # include <unistd.h>
70 #elif defined(_WIN32)
71 # undef ASYNC_WIN
72 # define ASYNC_WIN
73 # include <windows.h>
74 #endif
75
76 #define DASYNC_LIB_NAME "DASYNC"
77 #include "e_dasync_err.c"
78
79 /* Engine Id and Name */
80 static const char *engine_dasync_id = "dasync";
81 static const char *engine_dasync_name = "Dummy Async engine support";
82
83
84 /* Engine Lifetime functions */
85 static int dasync_destroy(ENGINE *e);
86 static int dasync_init(ENGINE *e);
87 static int dasync_finish(ENGINE *e);
88 void engine_load_dasync_internal(void);
89
90
91 /* Set up digests. Just SHA1 for now */
92 static int dasync_digests(ENGINE *e, const EVP_MD **digest,
93                           const int **nids, int nid);
94
95 static void dummy_pause_job(void);
96
97 /* SHA1 */
98 static int dasync_sha1_init(EVP_MD_CTX *ctx);
99 static int dasync_sha1_update(EVP_MD_CTX *ctx, const void *data,
100                              size_t count);
101 static int dasync_sha1_final(EVP_MD_CTX *ctx, unsigned char *md);
102
103 static EVP_MD *_hidden_sha1_md = NULL;
104 static const EVP_MD *dasync_sha1(void)
105 {
106     if (_hidden_sha1_md == NULL) {
107         EVP_MD *md;
108
109         if ((md = EVP_MD_meth_new(NID_sha1, NID_sha1WithRSAEncryption)) == NULL
110             || !EVP_MD_meth_set_result_size(md, SHA_DIGEST_LENGTH)
111             || !EVP_MD_meth_set_input_blocksize(md, SHA_CBLOCK)
112             || !EVP_MD_meth_set_app_datasize(md,
113                                              sizeof(EVP_MD *) + sizeof(SHA_CTX))
114             || !EVP_MD_meth_set_flags(md, EVP_MD_FLAG_DIGALGID_ABSENT)
115             || !EVP_MD_meth_set_init(md, dasync_sha1_init)
116             || !EVP_MD_meth_set_update(md, dasync_sha1_update)
117             || !EVP_MD_meth_set_final(md, dasync_sha1_final)) {
118             EVP_MD_meth_free(md);
119             md = NULL;
120         }
121         _hidden_sha1_md = md;
122     }
123     return _hidden_sha1_md;
124 }
125 static void destroy_digests(void)
126 {
127     EVP_MD_meth_free(_hidden_sha1_md);
128     _hidden_sha1_md = NULL;
129 }
130 static int dasync_digest_nids(const int **nids)
131 {
132     static int digest_nids[2] = { 0, 0 };
133     static int pos = 0;
134     static int init = 0;
135
136     if (!init) {
137         const EVP_MD *md;
138         if ((md = dasync_sha1()) != NULL)
139             digest_nids[pos++] = EVP_MD_type(md);
140         digest_nids[pos] = 0;
141         init = 1;
142     }
143     *nids = digest_nids;
144     return pos;
145 }
146
147 /* RSA */
148
149 static int dasync_pub_enc(int flen, const unsigned char *from,
150                     unsigned char *to, RSA *rsa, int padding);
151 static int dasync_pub_dec(int flen, const unsigned char *from,
152                     unsigned char *to, RSA *rsa, int padding);
153 static int dasync_rsa_priv_enc(int flen, const unsigned char *from,
154                       unsigned char *to, RSA *rsa, int padding);
155 static int dasync_rsa_priv_dec(int flen, const unsigned char *from,
156                       unsigned char *to, RSA *rsa, int padding);
157 static int dasync_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa,
158                               BN_CTX *ctx);
159
160 static int dasync_rsa_init(RSA *rsa);
161 static int dasync_rsa_finish(RSA *rsa);
162
163 static RSA_METHOD dasync_rsa_method = {
164     "Dummy Async RSA method",
165     dasync_pub_enc,             /* pub_enc */
166     dasync_pub_dec,             /* pub_dec */
167     dasync_rsa_priv_enc,        /* priv_enc */
168     dasync_rsa_priv_dec,        /* priv_dec */
169     dasync_rsa_mod_exp,         /* rsa_mod_exp */
170     BN_mod_exp_mont,            /* bn_mod_exp */
171     dasync_rsa_init,            /* init */
172     dasync_rsa_finish,          /* finish */
173     0,                          /* flags */
174     NULL,                       /* app_data */
175     0,                          /* rsa_sign */
176     0,                          /* rsa_verify */
177     NULL                        /* rsa_keygen */
178 };
179
180
181 /* AES */
182
183 static int dasync_aes128_cbc_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg,
184                                   void *ptr);
185
186 static int dasync_aes128_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
187                                   const unsigned char *iv, int enc);
188
189 static int dasync_aes128_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
190                                     const unsigned char *in, size_t inl);
191
192 static int dasync_aes128_cbc_cleanup(EVP_CIPHER_CTX *ctx);
193
194 struct aes_128_cbc_pipeline_ctx {
195     void *inner_cipher_data;
196     unsigned char dummy[256];
197     unsigned int numpipes;
198     unsigned char **inbufs;
199     unsigned char **outbufs;
200     size_t *lens;
201 };
202
203 static EVP_CIPHER *_hidden_aes_128_cbc = NULL;
204 static const EVP_CIPHER *dasync_aes_128_cbc(void)
205 {
206     if (_hidden_aes_128_cbc == NULL)
207         _hidden_aes_128_cbc = EVP_CIPHER_meth_new(NID_aes_128_cbc,
208                                                   16 /* block size */,
209                                                   16 /* key len */);
210     if (_hidden_aes_128_cbc == NULL
211             || !EVP_CIPHER_meth_set_iv_length(_hidden_aes_128_cbc,16)
212             || !EVP_CIPHER_meth_set_flags(_hidden_aes_128_cbc,
213                                           EVP_CIPH_FLAG_DEFAULT_ASN1
214                                           | EVP_CIPH_CBC_MODE
215                                           | EVP_CIPH_FLAG_PIPELINE)
216             || !EVP_CIPHER_meth_set_init(_hidden_aes_128_cbc,
217                                          dasync_aes128_init_key)
218             || !EVP_CIPHER_meth_set_do_cipher(_hidden_aes_128_cbc,
219                                               dasync_aes128_cbc_cipher)
220             || !EVP_CIPHER_meth_set_cleanup(_hidden_aes_128_cbc,
221                                             dasync_aes128_cbc_cleanup)
222             || !EVP_CIPHER_meth_set_ctrl(_hidden_aes_128_cbc,
223                                          dasync_aes128_cbc_ctrl)
224             || !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_aes_128_cbc,
225                                 sizeof(struct aes_128_cbc_pipeline_ctx))) {
226         EVP_CIPHER_meth_free(_hidden_aes_128_cbc);
227         _hidden_aes_128_cbc = NULL;
228     }
229     return _hidden_aes_128_cbc;
230 }
231
232
233 static int dasync_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
234                                    const int **nids, int nid);
235
236 #  ifdef NID_aes_128_cbc_hmac_sha256
237 static int dasync_cipher_nids[] = {
238     NID_aes_128_cbc,
239     0
240 };
241 #  else
242 static int dasync_cipher_nids[] = { 0 };
243 #endif
244
245 static int bind_dasync(ENGINE *e)
246 {
247     /* Ensure the dasync error handling is set up */
248     ERR_load_DASYNC_strings();
249
250     if (!ENGINE_set_id(e, engine_dasync_id)
251         || !ENGINE_set_name(e, engine_dasync_name)
252         || !ENGINE_set_RSA(e, &dasync_rsa_method)
253         || !ENGINE_set_digests(e, dasync_digests)
254         || !ENGINE_set_ciphers(e, dasync_ciphers)
255         || !ENGINE_set_destroy_function(e, dasync_destroy)
256         || !ENGINE_set_init_function(e, dasync_init)
257         || !ENGINE_set_finish_function(e, dasync_finish)) {
258         DASYNCerr(DASYNC_F_BIND_DASYNC, DASYNC_R_INIT_FAILED);
259         return 0;
260     }
261
262     return 1;
263 }
264
265 # ifndef OPENSSL_NO_DYNAMIC_ENGINE
266 static int bind_helper(ENGINE *e, const char *id)
267 {
268     if (id && (strcmp(id, engine_dasync_id) != 0))
269         return 0;
270     if (!bind_dasync(e))
271         return 0;
272     return 1;
273 }
274
275 IMPLEMENT_DYNAMIC_CHECK_FN()
276     IMPLEMENT_DYNAMIC_BIND_FN(bind_helper)
277 # endif
278
279 static ENGINE *engine_dasync(void)
280 {
281     ENGINE *ret = ENGINE_new();
282     if (!ret)
283         return NULL;
284     if (!bind_dasync(ret)) {
285         ENGINE_free(ret);
286         return NULL;
287     }
288     return ret;
289 }
290
291 void engine_load_dasync_internal(void)
292 {
293     ENGINE *toadd = engine_dasync();
294     if (!toadd)
295         return;
296     ENGINE_add(toadd);
297     ENGINE_free(toadd);
298     ERR_clear_error();
299 }
300
301 static int dasync_init(ENGINE *e)
302 {
303     return 1;
304 }
305
306
307 static int dasync_finish(ENGINE *e)
308 {
309     return 1;
310 }
311
312
313 static int dasync_destroy(ENGINE *e)
314 {
315     destroy_digests();
316     ERR_unload_DASYNC_strings();
317     return 1;
318 }
319
320 static int dasync_digests(ENGINE *e, const EVP_MD **digest,
321                           const int **nids, int nid)
322 {
323     int ok = 1;
324     if (!digest) {
325         /* We are returning a list of supported nids */
326         return dasync_digest_nids(nids);
327     }
328     /* We are being asked for a specific digest */
329     switch (nid) {
330     case NID_sha1:
331         *digest = dasync_sha1();
332         break;
333     default:
334         ok = 0;
335         *digest = NULL;
336         break;
337     }
338     return ok;
339 }
340
341 static int dasync_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
342                                    const int **nids, int nid)
343 {
344     int ok = 1;
345     if (!cipher) {
346         /* We are returning a list of supported nids */
347         *nids = dasync_cipher_nids;
348         return (sizeof(dasync_cipher_nids) -
349                 1) / sizeof(dasync_cipher_nids[0]);
350     }
351     /* We are being asked for a specific cipher */
352     switch (nid) {
353     case NID_aes_128_cbc:
354         *cipher = dasync_aes_128_cbc();
355         break;
356     default:
357         ok = 0;
358         *cipher = NULL;
359         break;
360     }
361     return ok;
362 }
363
364 static void wait_cleanup(ASYNC_WAIT_CTX *ctx, const void *key,
365                          OSSL_ASYNC_FD readfd, void *pvwritefd)
366 {
367     OSSL_ASYNC_FD *pwritefd = (OSSL_ASYNC_FD *)pvwritefd;
368 #if defined(ASYNC_WIN)
369     CloseHandle(readfd);
370     CloseHandle(*pwritefd);
371 #elif defined(ASYNC_POSIX)
372     close(readfd);
373     close(*pwritefd);
374 #endif
375     OPENSSL_free(pwritefd);
376 }
377
378 #define DUMMY_CHAR 'X'
379
380 static void dummy_pause_job(void) {
381     ASYNC_JOB *job;
382     ASYNC_WAIT_CTX *waitctx;
383     OSSL_ASYNC_FD pipefds[2] = {0, 0};
384     OSSL_ASYNC_FD *writefd;
385 #if defined(ASYNC_WIN)
386     DWORD numwritten, numread;
387     char buf = DUMMY_CHAR;
388 #elif defined(ASYNC_POSIX)
389     char buf = DUMMY_CHAR;
390 #endif
391
392     if ((job = ASYNC_get_current_job()) == NULL)
393         return;
394
395     waitctx = ASYNC_get_wait_ctx(job);
396
397     if (ASYNC_WAIT_CTX_get_fd(waitctx, engine_dasync_id, &pipefds[0],
398                               (void **)&writefd)) {
399         pipefds[1] = *writefd;
400     } else {
401         writefd = OPENSSL_malloc(sizeof(*writefd));
402         if (writefd == NULL)
403             return;
404 #if defined(ASYNC_WIN)
405         if (CreatePipe(&pipefds[0], &pipefds[1], NULL, 256) == 0) {
406             OPENSSL_free(writefd);
407             return;
408         }
409 #elif defined(ASYNC_POSIX)
410         if (pipe(pipefds) != 0) {
411             OPENSSL_free(writefd);
412             return;
413         }
414 #endif
415         *writefd = pipefds[1];
416
417         if(!ASYNC_WAIT_CTX_set_wait_fd(waitctx, engine_dasync_id, pipefds[0],
418                                        writefd, wait_cleanup)) {
419             wait_cleanup(waitctx, engine_dasync_id, pipefds[0], writefd);
420             return;
421         }
422     }
423     /*
424      * In the Dummy async engine we are cheating. We signal that the job
425      * is complete by waking it before the call to ASYNC_pause_job(). A real
426      * async engine would only wake when the job was actually complete
427      */
428 #if defined(ASYNC_WIN)
429     WriteFile(pipefds[1], &buf, 1, &numwritten, NULL);
430 #elif defined(ASYNC_POSIX)
431     if (write(pipefds[1], &buf, 1) < 0)
432         return;
433 #endif
434
435     /* Ignore errors - we carry on anyway */
436     ASYNC_pause_job();
437
438     /* Clear the wake signal */
439 #if defined(ASYNC_WIN)
440     ReadFile(pipefds[0], &buf, 1, &numread, NULL);
441 #elif defined(ASYNC_POSIX)
442     if (read(pipefds[0], &buf, 1) < 0)
443         return;
444 #endif
445 }
446
447 /*
448  * SHA1 implementation. At the moment we just defer to the standard
449  * implementation
450  */
451 #undef data
452 #define data(ctx) ((SHA_CTX *)EVP_MD_CTX_md_data(ctx))
453 static int dasync_sha1_init(EVP_MD_CTX *ctx)
454 {
455     dummy_pause_job();
456
457     return SHA1_Init(data(ctx));
458 }
459
460 static int dasync_sha1_update(EVP_MD_CTX *ctx, const void *data,
461                              size_t count)
462 {
463     dummy_pause_job();
464
465     return SHA1_Update(data(ctx), data, (size_t)count);
466 }
467
468 static int dasync_sha1_final(EVP_MD_CTX *ctx, unsigned char *md)
469 {
470     dummy_pause_job();
471
472     return SHA1_Final(md, data(ctx));
473 }
474
475 /*
476  * RSA implementation
477  */
478
479 static int dasync_pub_enc(int flen, const unsigned char *from,
480                     unsigned char *to, RSA *rsa, int padding) {
481     /* Ignore errors - we carry on anyway */
482     dummy_pause_job();
483     return RSA_PKCS1_OpenSSL()->rsa_pub_enc(flen, from, to, rsa, padding);
484 }
485
486 static int dasync_pub_dec(int flen, const unsigned char *from,
487                     unsigned char *to, RSA *rsa, int padding) {
488     /* Ignore errors - we carry on anyway */
489     dummy_pause_job();
490     return RSA_PKCS1_OpenSSL()->rsa_pub_dec(flen, from, to, rsa, padding);
491 }
492
493 static int dasync_rsa_priv_enc(int flen, const unsigned char *from,
494                       unsigned char *to, RSA *rsa, int padding)
495 {
496     /* Ignore errors - we carry on anyway */
497     dummy_pause_job();
498     return RSA_PKCS1_OpenSSL()->rsa_priv_enc(flen, from, to, rsa, padding);
499 }
500
501 static int dasync_rsa_priv_dec(int flen, const unsigned char *from,
502                       unsigned char *to, RSA *rsa, int padding)
503 {
504     /* Ignore errors - we carry on anyway */
505     dummy_pause_job();
506     return RSA_PKCS1_OpenSSL()->rsa_priv_dec(flen, from, to, rsa, padding);
507 }
508
509 static int dasync_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
510 {
511     /* Ignore errors - we carry on anyway */
512     dummy_pause_job();
513     return RSA_PKCS1_OpenSSL()->rsa_mod_exp(r0, I, rsa, ctx);
514 }
515
516 static int dasync_rsa_init(RSA *rsa)
517 {
518     return RSA_PKCS1_OpenSSL()->init(rsa);
519 }
520 static int dasync_rsa_finish(RSA *rsa)
521 {
522     return RSA_PKCS1_OpenSSL()->finish(rsa);
523 }
524
525 /*
526  * AES128 Implementation
527  */
528
529 static int dasync_aes128_cbc_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg,
530                                   void *ptr)
531 {
532     struct aes_128_cbc_pipeline_ctx *pipe_ctx =
533         (struct aes_128_cbc_pipeline_ctx *)EVP_CIPHER_CTX_cipher_data(ctx);
534
535     if (pipe_ctx == NULL)
536         return 0;
537
538     switch (type) {
539         case EVP_CTRL_SET_PIPELINE_OUTPUT_BUFS:
540             pipe_ctx->numpipes = arg;
541             pipe_ctx->outbufs = (unsigned char **)ptr;
542             break;
543
544         case EVP_CTRL_SET_PIPELINE_INPUT_BUFS:
545             pipe_ctx->numpipes = arg;
546             pipe_ctx->inbufs = (unsigned char **)ptr;
547             break;
548
549         case EVP_CTRL_SET_PIPELINE_INPUT_LENS:
550             pipe_ctx->numpipes = arg;
551             pipe_ctx->lens = (size_t *)ptr;
552             break;
553
554         default:
555             return 0;
556     }
557
558     return 1;
559 }
560
561 static int dasync_aes128_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
562                              const unsigned char *iv, int enc)
563 {
564     int ret;
565     struct aes_128_cbc_pipeline_ctx *pipe_ctx =
566         (struct aes_128_cbc_pipeline_ctx *)EVP_CIPHER_CTX_cipher_data(ctx);
567
568     if (pipe_ctx->inner_cipher_data == NULL
569             && EVP_CIPHER_impl_ctx_size(EVP_aes_128_cbc()) != 0) {
570         pipe_ctx->inner_cipher_data = OPENSSL_zalloc(
571             EVP_CIPHER_impl_ctx_size(EVP_aes_128_cbc()));
572         if (pipe_ctx->inner_cipher_data == NULL) {
573             DASYNCerr(DASYNC_F_DASYNC_AES128_INIT_KEY,
574                         ERR_R_MALLOC_FAILURE);
575             return 0;
576         }
577     }
578
579     pipe_ctx->numpipes = 0;
580
581     EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx->inner_cipher_data);
582     ret = EVP_CIPHER_meth_get_init(EVP_aes_128_cbc())(ctx, key, iv, enc);
583     EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx);
584
585     return ret;
586 }
587
588 static int dasync_aes128_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
589                                const unsigned char *in, size_t inl)
590 {
591     int ret = 1;
592     unsigned int i, pipes;
593     struct aes_128_cbc_pipeline_ctx *pipe_ctx =
594         (struct aes_128_cbc_pipeline_ctx *)EVP_CIPHER_CTX_cipher_data(ctx);
595
596     pipes = pipe_ctx->numpipes;
597     EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx->inner_cipher_data);
598     if (pipes == 0) {
599         ret = EVP_CIPHER_meth_get_do_cipher(EVP_aes_128_cbc())
600                                            (ctx, out, in, inl);
601     } else {
602         for (i = 0; i < pipes; i++) {
603             ret = ret && EVP_CIPHER_meth_get_do_cipher(EVP_aes_128_cbc())
604                                    (ctx, pipe_ctx->outbufs[i],
605                                     pipe_ctx->inbufs[i],
606                                     pipe_ctx->lens[i]);
607         }
608         pipe_ctx->numpipes = 0;
609     }
610     EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx);
611     return ret;
612 }
613
614 static int dasync_aes128_cbc_cleanup(EVP_CIPHER_CTX *ctx)
615 {
616     struct aes_128_cbc_pipeline_ctx *pipe_ctx =
617         (struct aes_128_cbc_pipeline_ctx *)EVP_CIPHER_CTX_cipher_data(ctx);
618
619     OPENSSL_clear_free(pipe_ctx->inner_cipher_data,
620                        EVP_CIPHER_impl_ctx_size(EVP_aes_128_cbc()));
621
622     return 1;
623 }