Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
Signed-off-by: Songling Han <[email protected]>
  • Loading branch information
songlingatpan committed Sep 22, 2024
1 parent 3fa49f1 commit 8ab2e63
Showing 1 changed file with 69 additions and 69 deletions.
138 changes: 69 additions & 69 deletions src/common/sha2/sha2_ossl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 8ab2e63

Please sign in to comment.