Skip to content

Commit

Permalink
revert sha2.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 7a1fa56 commit 32e6c30
Showing 1 changed file with 21 additions and 60 deletions.
81 changes: 21 additions & 60 deletions src/common/sha2/sha2.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,121 +7,82 @@
static struct OQS_SHA2_callbacks *callbacks = &sha2_default_callbacks;

OQS_API void OQS_SHA2_set_callbacks(struct OQS_SHA2_callbacks *new_callbacks) {
if (new_callbacks != NULL) {
callbacks = new_callbacks;
}
callbacks = new_callbacks;
}

void OQS_SHA2_sha256_inc_init(OQS_SHA2_sha256_ctx *state) {
if (state != NULL && callbacks != NULL && callbacks->SHA2_sha256_inc_init != NULL) {
callbacks->SHA2_sha256_inc_init(state);
}
callbacks->SHA2_sha256_inc_init(state);
}

void OQS_SHA2_sha256_inc_ctx_clone(OQS_SHA2_sha256_ctx *dest, const OQS_SHA2_sha256_ctx *src) {
if (dest != NULL && src != NULL && callbacks != NULL && callbacks->SHA2_sha256_inc_ctx_clone != NULL) {
callbacks->SHA2_sha256_inc_ctx_clone(dest, src);
}
callbacks->SHA2_sha256_inc_ctx_clone(dest, src);
}

void OQS_SHA2_sha256_inc_blocks(OQS_SHA2_sha256_ctx *state, const uint8_t *in, size_t inblocks) {
if (state != NULL && in != NULL && callbacks != NULL && callbacks->SHA2_sha256_inc_blocks != NULL) {
callbacks->SHA2_sha256_inc_blocks(state, in, inblocks);
}
callbacks->SHA2_sha256_inc_blocks(state, in, inblocks);
}

void OQS_SHA2_sha256_inc(OQS_SHA2_sha256_ctx *state, const uint8_t *in, size_t len) {
if (state != NULL && in != NULL && callbacks != NULL && callbacks->SHA2_sha256_inc != NULL) {
callbacks->SHA2_sha256_inc(state, in, len);
}
callbacks->SHA2_sha256_inc(state, in, len);
}

void OQS_SHA2_sha256_inc_finalize(uint8_t *out, OQS_SHA2_sha256_ctx *state, const uint8_t *in, size_t inlen) {
if (out != NULL && state != NULL && in != NULL && callbacks != NULL && callbacks->SHA2_sha256_inc_finalize != NULL) {
callbacks->SHA2_sha256_inc_finalize(out, state, in, inlen);
}
callbacks->SHA2_sha256_inc_finalize(out, state, in, inlen);
}

void OQS_SHA2_sha256_inc_ctx_release(OQS_SHA2_sha256_ctx *state) {
if (state != NULL && callbacks != NULL && callbacks->SHA2_sha256_inc_ctx_release != NULL) {
callbacks->SHA2_sha256_inc_ctx_release(state);
}
callbacks->SHA2_sha256_inc_ctx_release(state);
}

void OQS_SHA2_sha384_inc_init(OQS_SHA2_sha384_ctx *state) {
if (state != NULL && callbacks != NULL && callbacks->SHA2_sha384_inc_init != NULL) {
callbacks->SHA2_sha384_inc_init(state);
}
callbacks->SHA2_sha384_inc_init(state);
}

void OQS_SHA2_sha384_inc_ctx_clone(OQS_SHA2_sha384_ctx *dest, const OQS_SHA2_sha384_ctx *src) {
if (dest != NULL && src != NULL && callbacks != NULL && callbacks->SHA2_sha384_inc_ctx_clone != NULL) {
callbacks->SHA2_sha384_inc_ctx_clone(dest, src);
}
callbacks->SHA2_sha384_inc_ctx_clone(dest, src);
}

void OQS_SHA2_sha384_inc_blocks(OQS_SHA2_sha384_ctx *state, const uint8_t *in, size_t inblocks) {
if (state != NULL && in != NULL && callbacks != NULL && callbacks->SHA2_sha384_inc_blocks != NULL) {
callbacks->SHA2_sha384_inc_blocks(state, in, inblocks);
}
callbacks->SHA2_sha384_inc_blocks(state, in, inblocks);
}

void OQS_SHA2_sha384_inc_finalize(uint8_t *out, OQS_SHA2_sha384_ctx *state, const uint8_t *in, size_t inlen) {
if (out != NULL && state != NULL && in != NULL && callbacks != NULL && callbacks->SHA2_sha384_inc_finalize != NULL) {
callbacks->SHA2_sha384_inc_finalize(out, state, in, inlen);
}
callbacks->SHA2_sha384_inc_finalize(out, state, in, inlen);
}

void OQS_SHA2_sha384_inc_ctx_release(OQS_SHA2_sha384_ctx *state) {
if (state != NULL && callbacks != NULL && callbacks->SHA2_sha384_inc_ctx_release != NULL) {
callbacks->SHA2_sha384_inc_ctx_release(state);
}
callbacks->SHA2_sha384_inc_ctx_release(state);
}

void OQS_SHA2_sha512_inc_init(OQS_SHA2_sha512_ctx *state) {
if (state != NULL && callbacks != NULL && callbacks->SHA2_sha512_inc_init != NULL) {
callbacks->SHA2_sha512_inc_init(state);
}
callbacks->SHA2_sha512_inc_init(state);
}

void OQS_SHA2_sha512_inc_ctx_clone(OQS_SHA2_sha512_ctx *dest, const OQS_SHA2_sha512_ctx *src) {
if (dest != NULL && src != NULL && callbacks != NULL && callbacks->SHA2_sha512_inc_ctx_clone != NULL) {
callbacks->SHA2_sha512_inc_ctx_clone(dest, src);
}
callbacks->SHA2_sha512_inc_ctx_clone(dest, src);
}

void OQS_SHA2_sha512_inc_blocks(OQS_SHA2_sha512_ctx *state, const uint8_t *in, size_t inblocks) {
if (state != NULL && in != NULL && callbacks != NULL && callbacks->SHA2_sha512_inc_blocks != NULL) {
callbacks->SHA2_sha512_inc_blocks(state, in, inblocks);
}
callbacks->SHA2_sha512_inc_blocks(state, in, inblocks);
}

void OQS_SHA2_sha512_inc_finalize(uint8_t *out, OQS_SHA2_sha512_ctx *state, const uint8_t *in, size_t inlen) {
if (out != NULL && state != NULL && in != NULL && callbacks != NULL && callbacks->SHA2_sha512_inc_finalize != NULL) {
callbacks->SHA2_sha512_inc_finalize(out, state, in, inlen);
}
callbacks->SHA2_sha512_inc_finalize(out, state, in, inlen);
}

void OQS_SHA2_sha512_inc_ctx_release(OQS_SHA2_sha512_ctx *state) {
if (state != NULL && callbacks != NULL && callbacks->SHA2_sha512_inc_ctx_release != NULL) {
callbacks->SHA2_sha512_inc_ctx_release(state);
}
callbacks->SHA2_sha512_inc_ctx_release(state);
}

void OQS_SHA2_sha256(uint8_t *out, const uint8_t *in, size_t inlen) {
if (out != NULL && in != NULL && callbacks != NULL && callbacks->SHA2_sha256 != NULL) {
callbacks->SHA2_sha256(out, in, inlen);
}
callbacks->SHA2_sha256(out, in, inlen);
}

void OQS_SHA2_sha384(uint8_t *out, const uint8_t *in, size_t inlen) {
if (out != NULL && in != NULL && callbacks != NULL && callbacks->SHA2_sha384 != NULL) {
callbacks->SHA2_sha384(out, in, inlen);
}
callbacks->SHA2_sha384(out, in, inlen);
}

void OQS_SHA2_sha512(uint8_t *out, const uint8_t *in, size_t inlen) {
if (out != NULL && in != NULL && callbacks != NULL && callbacks->SHA2_sha512 != NULL) {
callbacks->SHA2_sha512(out, in, inlen);
}
callbacks->SHA2_sha512(out, in, inlen);
}

0 comments on commit 32e6c30

Please sign in to comment.