diff --git a/common/sha2.c b/common/sha2.c index 82accc08..c7214345 100644 --- a/common/sha2.c +++ b/common/sha2.c @@ -529,10 +529,22 @@ void sha512_inc_init(sha512ctx *state) { } } +void sha224_inc_clone_state(sha224ctx *stateout, const sha224ctx *statein) { + memcpy(stateout, statein, sizeof(sha224ctx)); +} + void sha256_inc_clone_state(sha256ctx *stateout, const sha256ctx *statein) { memcpy(stateout, statein, sizeof(sha256ctx)); } +void sha384_inc_clone_state(sha384ctx *stateout, const sha384ctx *statein) { + memcpy(stateout, statein, sizeof(sha384ctx)); +} + +void sha512_inc_clone_state(sha512ctx *stateout, const sha512ctx *statein) { + memcpy(stateout, statein, sizeof(sha512ctx)); +} + void sha256_inc_blocks(sha256ctx *state, const uint8_t *in, size_t inblocks) { uint64_t bytes = load_bigendian_64(state->ctx + 32); diff --git a/common/sha2.h b/common/sha2.h index b6bdd6a6..b7334810 100644 --- a/common/sha2.h +++ b/common/sha2.h @@ -25,6 +25,7 @@ typedef struct { } sha512ctx; void sha224_inc_init(sha224ctx *state); +void sha224_inc_clone_state(sha224ctx *stateout, const sha224ctx *statein); void sha224_inc_blocks(sha224ctx *state, const uint8_t *in, size_t inblocks); void sha224_inc_finalize(uint8_t *out, sha224ctx *state, const uint8_t *in, size_t inlen); void sha224(uint8_t *out, const uint8_t *in, size_t inlen); @@ -36,11 +37,13 @@ void sha256_inc_finalize(uint8_t *out, sha256ctx *state, const uint8_t *in, size void sha256(uint8_t *out, const uint8_t *in, size_t inlen); void sha384_inc_init(sha384ctx *state); +void sha384_inc_clone_state(sha384ctx *stateout, const sha384ctx *statein); void sha384_inc_blocks(sha384ctx *state, const uint8_t *in, size_t inblocks); void sha384_inc_finalize(uint8_t *out, sha384ctx *state, const uint8_t *in, size_t inlen); void sha384(uint8_t *out, const uint8_t *in, size_t inlen); void sha512_inc_init(sha512ctx *state); +void sha512_inc_clone_state(sha512ctx *stateout, const sha512ctx *statein); void sha512_inc_blocks(sha512ctx *state, const uint8_t *in, size_t inblocks); void sha512_inc_finalize(uint8_t *out, sha512ctx *state, const uint8_t *in, size_t inlen); void sha512(uint8_t *out, const uint8_t *in, size_t inlen);