Lines Matching refs:ctx
66 BIO_ENC_CTX *ctx; in enc_new() local
68 if ((ctx = OPENSSL_zalloc(sizeof(*ctx))) == NULL) { in enc_new()
73 ctx->cipher = EVP_CIPHER_CTX_new(); in enc_new()
74 if (ctx->cipher == NULL) { in enc_new()
75 OPENSSL_free(ctx); in enc_new()
78 ctx->cont = 1; in enc_new()
79 ctx->ok = 1; in enc_new()
80 ctx->read_end = ctx->read_start = &(ctx->buf[BUF_OFFSET]); in enc_new()
81 BIO_set_data(bi, ctx); in enc_new()
109 BIO_ENC_CTX *ctx; in enc_read() local
114 ctx = BIO_get_data(b); in enc_read()
117 if ((ctx == NULL) || (next == NULL)) in enc_read()
121 if (ctx->buf_len > 0) { in enc_read()
122 i = ctx->buf_len - ctx->buf_off; in enc_read()
125 memcpy(out, &(ctx->buf[ctx->buf_off]), i); in enc_read()
129 ctx->buf_off += i; in enc_read()
130 if (ctx->buf_len == ctx->buf_off) { in enc_read()
131 ctx->buf_len = 0; in enc_read()
132 ctx->buf_off = 0; in enc_read()
136 blocksize = EVP_CIPHER_CTX_get_block_size(ctx->cipher); in enc_read()
146 if (ctx->cont <= 0) in enc_read()
149 if (ctx->read_start == ctx->read_end) { /* time to read more data */ in enc_read()
150 ctx->read_end = ctx->read_start = &(ctx->buf[BUF_OFFSET]); in enc_read()
151 i = BIO_read(next, ctx->read_start, ENC_BLOCK_SIZE); in enc_read()
153 ctx->read_end += i; in enc_read()
155 i = ctx->read_end - ctx->read_start; in enc_read()
161 ctx->cont = i; in enc_read()
162 i = EVP_CipherFinal_ex(ctx->cipher, in enc_read()
163 ctx->buf, &(ctx->buf_len)); in enc_read()
164 ctx->ok = i; in enc_read()
165 ctx->buf_off = 0; in enc_read()
179 if (!EVP_CipherUpdate(ctx->cipher, in enc_read()
181 ctx->read_start, i > j ? j : i)) { in enc_read()
190 ctx->read_start = ctx->read_end; in enc_read()
193 ctx->read_start += j; in enc_read()
197 if (!EVP_CipherUpdate(ctx->cipher, in enc_read()
198 ctx->buf, &ctx->buf_len, in enc_read()
199 ctx->read_start, i)) { in enc_read()
201 ctx->ok = 0; in enc_read()
204 ctx->read_start += i; in enc_read()
205 ctx->cont = 1; in enc_read()
212 if (ctx->buf_len == 0) in enc_read()
216 if (ctx->buf_len <= outl) in enc_read()
217 i = ctx->buf_len; in enc_read()
222 memcpy(out, ctx->buf, i); in enc_read()
224 ctx->buf_off = i; in enc_read()
231 return ((ret == 0) ? ctx->cont : ret); in enc_read()
237 BIO_ENC_CTX *ctx; in enc_write() local
240 ctx = BIO_get_data(b); in enc_write()
242 if ((ctx == NULL) || (next == NULL)) in enc_write()
248 n = ctx->buf_len - ctx->buf_off; in enc_write()
250 i = BIO_write(next, &(ctx->buf[ctx->buf_off]), n); in enc_write()
255 ctx->buf_off += i; in enc_write()
263 ctx->buf_off = 0; in enc_write()
266 if (!EVP_CipherUpdate(ctx->cipher, in enc_write()
267 ctx->buf, &ctx->buf_len, in enc_write()
270 ctx->ok = 0; in enc_write()
276 ctx->buf_off = 0; in enc_write()
277 n = ctx->buf_len; in enc_write()
279 i = BIO_write(next, &(ctx->buf[ctx->buf_off]), n); in enc_write()
285 ctx->buf_off += i; in enc_write()
287 ctx->buf_len = 0; in enc_write()
288 ctx->buf_off = 0; in enc_write()
297 BIO_ENC_CTX *ctx, *dctx; in enc_ctrl() local
303 ctx = BIO_get_data(b); in enc_ctrl()
305 if (ctx == NULL) in enc_ctrl()
310 ctx->ok = 1; in enc_ctrl()
311 ctx->finished = 0; in enc_ctrl()
312 if (!EVP_CipherInit_ex(ctx->cipher, NULL, NULL, NULL, NULL, in enc_ctrl()
313 EVP_CIPHER_CTX_is_encrypting(ctx->cipher))) in enc_ctrl()
318 if (ctx->cont <= 0) in enc_ctrl()
324 ret = ctx->buf_len - ctx->buf_off; in enc_ctrl()
329 ret = ctx->buf_len - ctx->buf_off; in enc_ctrl()
336 while (ctx->buf_len != ctx->buf_off) { in enc_ctrl()
342 if (!ctx->finished) { in enc_ctrl()
343 ctx->finished = 1; in enc_ctrl()
344 ctx->buf_off = 0; in enc_ctrl()
345 ret = EVP_CipherFinal_ex(ctx->cipher, in enc_ctrl()
346 (unsigned char *)ctx->buf, in enc_ctrl()
347 &(ctx->buf_len)); in enc_ctrl()
348 ctx->ok = (int)ret; in enc_ctrl()
360 ret = (long)ctx->ok; in enc_ctrl()
369 *c_ctx = ctx->cipher; in enc_ctrl()
378 ret = EVP_CIPHER_CTX_copy(dctx->cipher, ctx->cipher); in enc_ctrl()
402 BIO_ENC_CTX *ctx; in BIO_set_cipher() local
408 ctx = BIO_get_data(b); in BIO_set_cipher()
409 if (ctx == NULL) in BIO_set_cipher()
430 if (!EVP_CipherInit_ex(ctx->cipher, c, NULL, k, i, e)) in BIO_set_cipher()