From 7662f00cfdc400961233d08ae734daa703855e43 Mon Sep 17 00:00:00 2001 From: Songling Han Date: Sun, 22 Sep 2024 06:17:09 +0000 Subject: [PATCH] revert sha2_ossl.c Signed-off-by: Songling Han --- src/common/sha2/sha2_ossl.c | 61 ++++++++++--------------------------- 1 file changed, 16 insertions(+), 45 deletions(-) diff --git a/src/common/sha2/sha2_ossl.c b/src/common/sha2/sha2_ossl.c index 54904e168..234d4b1e3 100644 --- a/src/common/sha2/sha2_ossl.c +++ b/src/common/sha2/sha2_ossl.c @@ -17,9 +17,7 @@ static void do_hash(uint8_t *output, const uint8_t *input, size_t inplen, const EVP_MD_CTX *mdctx; unsigned int outlen; mdctx = OSSL_FUNC(EVP_MD_CTX_new)(); - if (mdctx == NULL) { - OQS_EXIT("OpenSSL"); - } + OQS_EXIT_IF_NULLPTR(mdctx, "OpenSSL"); OQS_OPENSSL_GUARD(OSSL_FUNC(EVP_DigestInit_ex)(mdctx, md, NULL)); OQS_OPENSSL_GUARD(OSSL_FUNC(EVP_DigestUpdate)(mdctx, input, inplen)); OQS_OPENSSL_GUARD(OSSL_FUNC(EVP_DigestFinal_ex)(mdctx, output, &outlen)); @@ -29,27 +27,21 @@ static void do_hash(uint8_t *output, const uint8_t *input, size_t inplen, const static void SHA2_sha256(uint8_t *output, const uint8_t *input, size_t inplen) { const EVP_MD *md; md = oqs_sha256(); - if (md == NULL) { - OQS_EXIT("OpenSSL"); - } + OQS_EXIT_IF_NULLPTR(md, "OpenSSL"); do_hash(output, input, inplen, md); } static void SHA2_sha384(uint8_t *output, const uint8_t *input, size_t inplen) { const EVP_MD *md; md = oqs_sha384(); - if (md == NULL) { - OQS_EXIT("OpenSSL"); - } + OQS_EXIT_IF_NULLPTR(md, "OpenSSL"); do_hash(output, input, inplen, md); } static void SHA2_sha512(uint8_t *output, const uint8_t *input, size_t inplen) { const EVP_MD *md; md = oqs_sha512(); - if (md == NULL) { - OQS_EXIT("OpenSSL"); - } + OQS_EXIT_IF_NULLPTR(md, "OpenSSL"); do_hash(output, input, inplen, md); } @@ -59,13 +51,9 @@ static void SHA2_sha256_inc_init(OQS_SHA2_sha256_ctx *state) { EVP_MD_CTX *mdctx; const EVP_MD *md = NULL; md = oqs_sha256(); - if (md == NULL) { - OQS_EXIT("OpenSSL"); - } + OQS_EXIT_IF_NULLPTR(md, "OpenSSL"); mdctx = OSSL_FUNC(EVP_MD_CTX_new)(); - if (mdctx == NULL) { - OQS_EXIT("OpenSSL"); - } + OQS_EXIT_IF_NULLPTR(mdctx, "OpenSSL"); OQS_OPENSSL_GUARD(OSSL_FUNC(EVP_DigestInit_ex)(mdctx, md, NULL)); state->ctx = mdctx; } @@ -85,14 +73,11 @@ static void SHA2_sha256_inc_finalize(uint8_t *out, OQS_SHA2_sha256_ctx *state, c } OQS_OPENSSL_GUARD(OSSL_FUNC(EVP_DigestFinal_ex)((EVP_MD_CTX *) state->ctx, out, &md_len)); OSSL_FUNC(EVP_MD_CTX_free)((EVP_MD_CTX *) state->ctx); - state->ctx = NULL; } static void SHA2_sha256_inc_ctx_release(OQS_SHA2_sha256_ctx *state) { - if (state->ctx != NULL) { - OSSL_FUNC(EVP_MD_CTX_free)((EVP_MD_CTX *) state->ctx); - state->ctx = NULL; - } + OSSL_FUNC(EVP_MD_CTX_free)((EVP_MD_CTX *) state->ctx); + state->ctx = NULL; } static void SHA2_sha256_inc_ctx_clone(OQS_SHA2_sha256_ctx *dest, const OQS_SHA2_sha256_ctx *src) { @@ -104,13 +89,9 @@ static void SHA2_sha384_inc_init(OQS_SHA2_sha384_ctx *state) { EVP_MD_CTX *mdctx; const EVP_MD *md = NULL; md = oqs_sha384(); - if (md == NULL) { - OQS_EXIT("OpenSSL"); - } + OQS_EXIT_IF_NULLPTR(md, "OpenSSL"); mdctx = OSSL_FUNC(EVP_MD_CTX_new)(); - if (mdctx == NULL) { - OQS_EXIT("OpenSSL"); - } + OQS_EXIT_IF_NULLPTR(mdctx, "OpenSSL"); OQS_OPENSSL_GUARD(OSSL_FUNC(EVP_DigestInit_ex)(mdctx, md, NULL)); state->ctx = mdctx; } @@ -126,14 +107,11 @@ static void SHA2_sha384_inc_finalize(uint8_t *out, OQS_SHA2_sha384_ctx *state, c } OQS_OPENSSL_GUARD(OSSL_FUNC(EVP_DigestFinal_ex)((EVP_MD_CTX *) state->ctx, out, &md_len)); OSSL_FUNC(EVP_MD_CTX_free)((EVP_MD_CTX *) state->ctx); - state->ctx = NULL; } static void SHA2_sha384_inc_ctx_release(OQS_SHA2_sha384_ctx *state) { - if (state->ctx != NULL) { - OSSL_FUNC(EVP_MD_CTX_free)((EVP_MD_CTX *) state->ctx); - state->ctx = NULL; - } + OSSL_FUNC(EVP_MD_CTX_free)((EVP_MD_CTX *) state->ctx); + state->ctx = NULL; } static void SHA2_sha384_inc_ctx_clone(OQS_SHA2_sha384_ctx *dest, const OQS_SHA2_sha384_ctx *src) { @@ -145,13 +123,9 @@ static void SHA2_sha512_inc_init(OQS_SHA2_sha512_ctx *state) { EVP_MD_CTX *mdctx; const EVP_MD *md = NULL; md = oqs_sha512(); - if (md == NULL) { - OQS_EXIT("OpenSSL"); - } + OQS_EXIT_IF_NULLPTR(md, "OpenSSL"); mdctx = OSSL_FUNC(EVP_MD_CTX_new)(); - if (mdctx == NULL) { - OQS_EXIT("OpenSSL"); - } + OQS_EXIT_IF_NULLPTR(mdctx, "OpenSSL"); OQS_OPENSSL_GUARD(OSSL_FUNC(EVP_DigestInit_ex)(mdctx, md, NULL)); state->ctx = mdctx; } @@ -167,14 +141,11 @@ static void SHA2_sha512_inc_finalize(uint8_t *out, OQS_SHA2_sha512_ctx *state, c } OQS_OPENSSL_GUARD(OSSL_FUNC(EVP_DigestFinal_ex)((EVP_MD_CTX *) state->ctx, out, &md_len)); OSSL_FUNC(EVP_MD_CTX_free)((EVP_MD_CTX *) state->ctx); - state->ctx = NULL; } static void SHA2_sha512_inc_ctx_release(OQS_SHA2_sha512_ctx *state) { - if (state->ctx != NULL) { - OSSL_FUNC(EVP_MD_CTX_free)((EVP_MD_CTX *) state->ctx); - state->ctx = NULL; - } + OSSL_FUNC(EVP_MD_CTX_free)((EVP_MD_CTX *) state->ctx); + state->ctx = NULL; } static void SHA2_sha512_inc_ctx_clone(OQS_SHA2_sha512_ctx *dest, const OQS_SHA2_sha512_ctx *src) {