Skip to content

Commit

Permalink
revert sha2_ossl.c
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 9fecaa8 commit 7662f00
Showing 1 changed file with 16 additions and 45 deletions.
61 changes: 16 additions & 45 deletions src/common/sha2/sha2_ossl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
}

Expand All @@ -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;
}
Expand All @@ -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) {
Expand All @@ -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;
}
Expand All @@ -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) {
Expand All @@ -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;
}
Expand All @@ -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) {
Expand Down

0 comments on commit 7662f00

Please sign in to comment.