From 8ab2e63ecbb2188a4c4f97874943c6596e1ac84b Mon Sep 17 00:00:00 2001 From: Songling Han Date: Sun, 22 Sep 2024 13:58:25 +0000 Subject: [PATCH] format code Signed-off-by: Songling Han --- src/common/sha2/sha2_ossl.c | 138 ++++++++++++++++++------------------ 1 file changed, 69 insertions(+), 69 deletions(-) diff --git a/src/common/sha2/sha2_ossl.c b/src/common/sha2/sha2_ossl.c index 0f7e81065..c809c1807 100644 --- a/src/common/sha2/sha2_ossl.c +++ b/src/common/sha2/sha2_ossl.c @@ -24,8 +24,8 @@ static void do_hash(uint8_t *output, const uint8_t *input, size_t inplen, const } if (OSSL_FUNC(EVP_DigestInit_ex)(mdctx, md, NULL) != 1 || - OSSL_FUNC(EVP_DigestUpdate)(mdctx, input, inplen) != 1 || - OSSL_FUNC(EVP_DigestFinal_ex)(mdctx, output, &outlen) != 1) { + OSSL_FUNC(EVP_DigestUpdate)(mdctx, input, inplen) != 1 || + OSSL_FUNC(EVP_DigestFinal_ex)(mdctx, output, &outlen) != 1) { OSSL_FUNC(EVP_MD_CTX_free)(mdctx); OQS_EXIT_IF_NULLPTR(NULL, "OpenSSL digest operation failed"); return; @@ -126,91 +126,91 @@ static void SHA2_sha256_inc_ctx_clone(OQS_SHA2_sha256_ctx *dest, const OQS_SHA2_ } static void SHA2_sha384_inc_init(OQS_SHA2_sha384_ctx *state) { - if (state == NULL) { - return; - } - EVP_MD_CTX *mdctx; - const EVP_MD *md = NULL; - md = oqs_sha384(); - if (md == NULL) { - OQS_EXIT_IF_NULLPTR(md, "OpenSSL"); - return; - } - mdctx = OSSL_FUNC(EVP_MD_CTX_new)(); - if (mdctx == NULL) { - OQS_EXIT_IF_NULLPTR(mdctx, "OpenSSL"); - return; - } - if (OSSL_FUNC(EVP_DigestInit_ex)(mdctx, md, NULL) != 1) { - OSSL_FUNC(EVP_MD_CTX_free)(mdctx); - OQS_EXIT_IF_NULLPTR(NULL, "OpenSSL digest initialization failed"); - return; - } - state->ctx = mdctx; + if (state == NULL) { + return; + } + EVP_MD_CTX *mdctx; + const EVP_MD *md = NULL; + md = oqs_sha384(); + if (md == NULL) { + OQS_EXIT_IF_NULLPTR(md, "OpenSSL"); + return; + } + mdctx = OSSL_FUNC(EVP_MD_CTX_new)(); + if (mdctx == NULL) { + OQS_EXIT_IF_NULLPTR(mdctx, "OpenSSL"); + return; + } + if (OSSL_FUNC(EVP_DigestInit_ex)(mdctx, md, NULL) != 1) { + OSSL_FUNC(EVP_MD_CTX_free)(mdctx); + OQS_EXIT_IF_NULLPTR(NULL, "OpenSSL digest initialization failed"); + return; + } + state->ctx = mdctx; } static void SHA2_sha384_inc_blocks(OQS_SHA2_sha384_ctx *state, const uint8_t *in, size_t inblocks) { - if (state && state->ctx && in) { - OQS_OPENSSL_GUARD(OSSL_FUNC(EVP_DigestUpdate)((EVP_MD_CTX *) state->ctx, in, inblocks * SHA2_BLOCK_SIZE)); - } + if (state && state->ctx && in) { + OQS_OPENSSL_GUARD(OSSL_FUNC(EVP_DigestUpdate)((EVP_MD_CTX *) state->ctx, in, inblocks * SHA2_BLOCK_SIZE)); + } } static void SHA2_sha384_inc_finalize(uint8_t *out, OQS_SHA2_sha384_ctx *state, const uint8_t *in, size_t inlen) { - if (state && state->ctx && out) { - unsigned int md_len; - if (inlen > 0 && in) { - OQS_OPENSSL_GUARD(OSSL_FUNC(EVP_DigestUpdate)((EVP_MD_CTX *) state->ctx, in, inlen)); - } - 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; - } + if (state && state->ctx && out) { + unsigned int md_len; + if (inlen > 0 && in) { + OQS_OPENSSL_GUARD(OSSL_FUNC(EVP_DigestUpdate)((EVP_MD_CTX *) state->ctx, in, inlen)); + } + 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 && state->ctx) { - OSSL_FUNC(EVP_MD_CTX_free)((EVP_MD_CTX *) state->ctx); - state->ctx = NULL; - } + if (state && state->ctx) { + 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) { - if (dest && src && src->ctx) { - SHA2_sha384_inc_init(dest); - if (dest->ctx) { - OQS_OPENSSL_GUARD(OSSL_FUNC(EVP_MD_CTX_copy_ex)((EVP_MD_CTX *) dest->ctx, (EVP_MD_CTX *) src->ctx)); - } - } + if (dest && src && src->ctx) { + SHA2_sha384_inc_init(dest); + if (dest->ctx) { + OQS_OPENSSL_GUARD(OSSL_FUNC(EVP_MD_CTX_copy_ex)((EVP_MD_CTX *) dest->ctx, (EVP_MD_CTX *) src->ctx)); + } + } } static void SHA2_sha512_inc_init(OQS_SHA2_sha512_ctx *state) { - if (state == NULL) { - return; - } - EVP_MD_CTX *mdctx; - const EVP_MD *md = NULL; - md = oqs_sha512(); - if (md == NULL) { - OQS_EXIT_IF_NULLPTR(md, "OpenSSL"); - return; - } - mdctx = OSSL_FUNC(EVP_MD_CTX_new)(); - if (mdctx == NULL) { - OQS_EXIT_IF_NULLPTR(mdctx, "OpenSSL"); - return; - } - if (OSSL_FUNC(EVP_DigestInit_ex)(mdctx, md, NULL) != 1) { - OSSL_FUNC(EVP_MD_CTX_free)(mdctx); - OQS_EXIT_IF_NULLPTR(NULL, "OpenSSL digest initialization failed"); - return; - } - state->ctx = mdctx; + if (state == NULL) { + return; + } + EVP_MD_CTX *mdctx; + const EVP_MD *md = NULL; + md = oqs_sha512(); + if (md == NULL) { + OQS_EXIT_IF_NULLPTR(md, "OpenSSL"); + return; + } + mdctx = OSSL_FUNC(EVP_MD_CTX_new)(); + if (mdctx == NULL) { + OQS_EXIT_IF_NULLPTR(mdctx, "OpenSSL"); + return; + } + if (OSSL_FUNC(EVP_DigestInit_ex)(mdctx, md, NULL) != 1) { + OSSL_FUNC(EVP_MD_CTX_free)(mdctx); + OQS_EXIT_IF_NULLPTR(NULL, "OpenSSL digest initialization failed"); + return; + } + state->ctx = mdctx; } static void SHA2_sha512_inc_blocks(OQS_SHA2_sha512_ctx *state, const uint8_t *in, size_t inblocks) { - if (state && state->ctx && in) { - OQS_OPENSSL_GUARD(OSSL_FUNC(EVP_DigestUpdate)((EVP_MD_CTX *) state->ctx, in, inblocks * 2 * SHA2_BLOCK_SIZE)); - } + if (state && state->ctx && in) { + OQS_OPENSSL_GUARD(OSSL_FUNC(EVP_DigestUpdate)((EVP_MD_CTX *) state->ctx, in, inblocks * 2 * SHA2_BLOCK_SIZE)); + } } static void SHA2_sha512_inc_finalize(uint8_t *out, OQS_SHA2_sha512_ctx *state, const uint8_t *in, size_t inlen) {