summaryrefslogtreecommitdiffstats
path: root/crypto/evp/evp_enc.c
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2015-12-13 16:03:02 +0100
committerRichard Levitte <levitte@openssl.org>2016-01-12 13:52:22 +0100
commit8baf9968dfd8ef2bc20cf2bf3de09304eb2213c5 (patch)
tree2035740aa74629fb0d7fe7a3abd2c7d520ad081d /crypto/evp/evp_enc.c
parentbd4850df648bee9d8e0595b7e1147266e6f55a3e (diff)
Make EVP_CIPHER_CTX opaque and renew the creator / destructor functions
Following the method used for EVP_MD_CTX and HMAC_CTX, EVP_CIPHER_CTX_init and EVP_CIPHER_CTX_cleanup are joined together into one function, EVP_CIPHER_CTX_reset, with EVP_CIPHER_CTX_init kept as an alias. EVP_CIPHER_CTX_cleanup fills no purpose of its own any more and is therefore removed. Reviewed-by: Rich Salz <rsalz@openssl.org>
Diffstat (limited to 'crypto/evp/evp_enc.c')
-rw-r--r--crypto/evp/evp_enc.c64
1 files changed, 28 insertions, 36 deletions
diff --git a/crypto/evp/evp_enc.c b/crypto/evp/evp_enc.c
index 6523bf16cc..45237545a8 100644
--- a/crypto/evp/evp_enc.c
+++ b/crypto/evp/evp_enc.c
@@ -66,17 +66,39 @@
#endif
#include "evp_locl.h"
-void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx)
+int EVP_CIPHER_CTX_reset(EVP_CIPHER_CTX *c)
{
- memset(ctx, 0, sizeof(*ctx));
+ if (c == NULL)
+ return 1;
+ if (c->cipher != NULL) {
+ if (c->cipher->cleanup && !c->cipher->cleanup(c))
+ return 0;
+ /* Cleanse cipher context data */
+ if (c->cipher_data && c->cipher->ctx_size)
+ OPENSSL_cleanse(c->cipher_data, c->cipher->ctx_size);
+ }
+ OPENSSL_free(c->cipher_data);
+#ifndef OPENSSL_NO_ENGINE
+ if (c->engine)
+ /*
+ * The EVP_CIPHER we used belongs to an ENGINE, release the
+ * functional reference we held for this reason.
+ */
+ ENGINE_finish(c->engine);
+#endif
+ memset(c, 0, sizeof(*c));
+ return 1;
}
EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void)
{
- EVP_CIPHER_CTX *ctx = OPENSSL_malloc(sizeof(*ctx));
- if (ctx != NULL)
- EVP_CIPHER_CTX_init(ctx);
- return ctx;
+ return OPENSSL_zalloc(sizeof(EVP_CIPHER_CTX));
+}
+
+void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx)
+{
+ EVP_CIPHER_CTX_reset(ctx);
+ OPENSSL_free(ctx);
}
int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
@@ -515,36 +537,6 @@ int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
return (1);
}
-void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx)
-{
- EVP_CIPHER_CTX_cleanup(ctx);
- OPENSSL_free(ctx);
-}
-
-int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c)
-{
- if (!c)
- return 0;
- if (c->cipher != NULL) {
- if (c->cipher->cleanup && !c->cipher->cleanup(c))
- return 0;
- /* Cleanse cipher context data */
- if (c->cipher_data && c->cipher->ctx_size)
- OPENSSL_cleanse(c->cipher_data, c->cipher->ctx_size);
- }
- OPENSSL_free(c->cipher_data);
-#ifndef OPENSSL_NO_ENGINE
- if (c->engine)
- /*
- * The EVP_CIPHER we used belongs to an ENGINE, release the
- * functional reference we held for this reason.
- */
- ENGINE_finish(c->engine);
-#endif
- memset(c, 0, sizeof(*c));
- return 1;
-}
-
int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *c, int keylen)
{
if (c->cipher->flags & EVP_CIPH_CUSTOM_KEY_LENGTH)