From 8bbc7f2211bacd201b8f2b219aad067c17b8c2ec Mon Sep 17 00:00:00 2001 From: Dmitry Belyavskiy Date: Wed, 4 Sep 2019 22:49:09 +0300 Subject: [PATCH] Disallow change EVP_MD properties once set Reviewed-by: Richard Levitte (Merged from https://github.com/openssl/openssl/pull/9764) --- crypto/evp/evp_lib.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/crypto/evp/evp_lib.c b/crypto/evp/evp_lib.c index acb90f222b..9c3edb3322 100644 --- a/crypto/evp/evp_lib.c +++ b/crypto/evp/evp_lib.c @@ -574,26 +574,41 @@ void EVP_MD_meth_free(EVP_MD *md) } int EVP_MD_meth_set_input_blocksize(EVP_MD *md, int blocksize) { + if (md->block_size != 0) + return 0; + md->block_size = blocksize; return 1; } int EVP_MD_meth_set_result_size(EVP_MD *md, int resultsize) { + if (md->md_size != 0) + return 0; + md->md_size = resultsize; return 1; } int EVP_MD_meth_set_app_datasize(EVP_MD *md, int datasize) { + if (md->ctx_size != 0) + return 0; + md->ctx_size = datasize; return 1; } int EVP_MD_meth_set_flags(EVP_MD *md, unsigned long flags) { + if (md->flags != 0) + return 0; + md->flags = flags; return 1; } int EVP_MD_meth_set_init(EVP_MD *md, int (*init)(EVP_MD_CTX *ctx)) { + if (md->init != NULL) + return 0; + md->init = init; return 1; } @@ -601,29 +616,44 @@ int EVP_MD_meth_set_update(EVP_MD *md, int (*update)(EVP_MD_CTX *ctx, const void *data, size_t count)) { + if (md->update != NULL) + return 0; + md->update = update; return 1; } int EVP_MD_meth_set_final(EVP_MD *md, int (*final)(EVP_MD_CTX *ctx, unsigned char *md)) { + if (md->final != NULL) + return 0; + md->final = final; return 1; } int EVP_MD_meth_set_copy(EVP_MD *md, int (*copy)(EVP_MD_CTX *to, const EVP_MD_CTX *from)) { + if (md->copy != NULL) + return 0; + md->copy = copy; return 1; } int EVP_MD_meth_set_cleanup(EVP_MD *md, int (*cleanup)(EVP_MD_CTX *ctx)) { + if (md->cleanup != NULL) + return 0; + md->cleanup = cleanup; return 1; } int EVP_MD_meth_set_ctrl(EVP_MD *md, int (*ctrl)(EVP_MD_CTX *ctx, int cmd, int p1, void *p2)) { + if (md->md_ctrl != NULL) + return 0; + md->md_ctrl = ctrl; return 1; } -- 2.25.1