summaryrefslogtreecommitdiffstats
path: root/crypto/evp/bio_enc.c
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2015-12-13 22:08:41 +0100
committerRichard Levitte <levitte@openssl.org>2016-01-12 13:52:22 +0100
commit846ec07d904f9cc81d486db0db14fb84f61ff6e5 (patch)
tree95f8e06e1e66296e20ade5ce79e098216ddbdf99 /crypto/evp/bio_enc.c
parent936166aff21dafed33aeb92bad0a5b46d730221d (diff)
Adapt all EVP_CIPHER_CTX users for it becoming opaque
Reviewed-by: Rich Salz <rsalz@openssl.org>
Diffstat (limited to 'crypto/evp/bio_enc.c')
-rw-r--r--crypto/evp/bio_enc.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/crypto/evp/bio_enc.c b/crypto/evp/bio_enc.c
index 2e6ce33e4e..c4daf8b691 100644
--- a/crypto/evp/bio_enc.c
+++ b/crypto/evp/bio_enc.c
@@ -83,7 +83,7 @@ typedef struct enc_struct {
int cont; /* <= 0 when finished */
int finished;
int ok; /* bad decrypt */
- EVP_CIPHER_CTX cipher;
+ EVP_CIPHER_CTX *cipher;
/*
* buf is larger than ENC_BLOCK_SIZE because EVP_DecryptUpdate can return
* up to a block more data than is presented to it
@@ -114,15 +114,19 @@ static int enc_new(BIO *bi)
ctx = OPENSSL_zalloc(sizeof(*ctx));
if (ctx == NULL)
- return (0);
+ return 0;
- EVP_CIPHER_CTX_init(&ctx->cipher);
+ ctx->cipher = EVP_CIPHER_CTX_new();
+ if (ctx->cipher == NULL) {
+ OPENSSL_free(ctx);
+ return 0;
+ }
ctx->cont = 1;
ctx->ok = 1;
bi->init = 0;
bi->ptr = (char *)ctx;
bi->flags = 0;
- return (1);
+ return 1;
}
static int enc_free(BIO *a)
@@ -132,7 +136,7 @@ static int enc_free(BIO *a)
if (a == NULL)
return (0);
b = (BIO_ENC_CTX *)a->ptr;
- EVP_CIPHER_CTX_cleanup(&(b->cipher));
+ EVP_CIPHER_CTX_free(b->cipher);
OPENSSL_clear_free(a->ptr, sizeof(BIO_ENC_CTX));
a->ptr = NULL;
a->init = 0;
@@ -186,7 +190,7 @@ static int enc_read(BIO *b, char *out, int outl)
/* Should be continue next time we are called? */
if (!BIO_should_retry(b->next_bio)) {
ctx->cont = i;
- i = EVP_CipherFinal_ex(&(ctx->cipher),
+ i = EVP_CipherFinal_ex(ctx->cipher,
(unsigned char *)ctx->buf,
&(ctx->buf_len));
ctx->ok = i;
@@ -196,7 +200,7 @@ static int enc_read(BIO *b, char *out, int outl)
break;
}
} else {
- if (!EVP_CipherUpdate(&(ctx->cipher),
+ if (!EVP_CipherUpdate(ctx->cipher,
(unsigned char *)ctx->buf, &ctx->buf_len,
(unsigned char *)&(ctx->buf[BUF_OFFSET]),
i)) {
@@ -259,7 +263,7 @@ static int enc_write(BIO *b, const char *in, int inl)
ctx->buf_off = 0;
while (inl > 0) {
n = (inl > ENC_BLOCK_SIZE) ? ENC_BLOCK_SIZE : inl;
- if (!EVP_CipherUpdate(&(ctx->cipher),
+ if (!EVP_CipherUpdate(ctx->cipher,
(unsigned char *)ctx->buf, &ctx->buf_len,
(unsigned char *)in, n)) {
BIO_clear_retry_flags(b);
@@ -300,8 +304,8 @@ static long enc_ctrl(BIO *b, int cmd, long num, void *ptr)
case BIO_CTRL_RESET:
ctx->ok = 1;
ctx->finished = 0;
- if (!EVP_CipherInit_ex(&(ctx->cipher), NULL, NULL, NULL, NULL,
- ctx->cipher.encrypt))
+ if (!EVP_CipherInit_ex(ctx->cipher, NULL, NULL, NULL, NULL,
+ EVP_CIPHER_CTX_encrypting(ctx->cipher)))
return 0;
ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
break;
@@ -333,7 +337,7 @@ static long enc_ctrl(BIO *b, int cmd, long num, void *ptr)
if (!ctx->finished) {
ctx->finished = 1;
ctx->buf_off = 0;
- ret = EVP_CipherFinal_ex(&(ctx->cipher),
+ ret = EVP_CipherFinal_ex(ctx->cipher,
(unsigned char *)ctx->buf,
&(ctx->buf_len));
ctx->ok = (int)ret;
@@ -357,14 +361,16 @@ static long enc_ctrl(BIO *b, int cmd, long num, void *ptr)
break;
case BIO_C_GET_CIPHER_CTX:
c_ctx = (EVP_CIPHER_CTX **)ptr;
- (*c_ctx) = &(ctx->cipher);
+ *c_ctx = ctx->cipher;
b->init = 1;
break;
case BIO_CTRL_DUP:
dbio = (BIO *)ptr;
dctx = (BIO_ENC_CTX *)dbio->ptr;
- EVP_CIPHER_CTX_init(&dctx->cipher);
- ret = EVP_CIPHER_CTX_copy(&dctx->cipher, &ctx->cipher);
+ dctx->cipher = EVP_CIPHER_CTX_new();
+ if (dctx->cipher == NULL)
+ return 0;
+ ret = EVP_CIPHER_CTX_copy(dctx->cipher, ctx->cipher);
if (ret)
dbio->init = 1;
break;
@@ -424,7 +430,7 @@ int BIO_set_cipher(BIO *b, const EVP_CIPHER *c, const unsigned char *k,
b->init = 1;
ctx = (BIO_ENC_CTX *)b->ptr;
- if (!EVP_CipherInit_ex(&(ctx->cipher), c, NULL, k, i, e))
+ if (!EVP_CipherInit_ex(ctx->cipher, c, NULL, k, i, e))
return 0;
if (b->callback != NULL)