Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions doc/dox_comments/header_files/sha256.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,12 +402,16 @@ int wc_Sha256_Grow(wc_Sha256* sha256, const byte* in, int inSz);
\ingroup SHA
\brief Copies SHA256 context.

The memory regions occupied by the source and destination structures
must not overlap. If they overlap, including when src == dst, the
behavior is undefined.

\return 0 on success
\return negative on error

\param src Source SHA256 structure
\param dst Destination SHA256 structure;
(must be zeroed or previously initialized)
(must be zeroed or previously initialized and must not overlap src)

_Example_
\code
Expand Down Expand Up @@ -613,12 +617,16 @@ int wc_Sha224GetHash(wc_Sha224* sha224, byte* hash);
\ingroup SHA
\brief Copies SHA224 context.

The memory regions occupied by the source and destination structures
must not overlap. If they overlap, including when src == dst, the
behavior is undefined.

\return 0 on success
\return negative on error

\param src Source SHA224 structure
\param dst Destination SHA224 structure
(must be zeroed or previously initialized)
(must be zeroed or previously initialized and must not overlap src)

_Example_
\code
Expand Down
4 changes: 2 additions & 2 deletions wolfcrypt/src/sha256.c
Original file line number Diff line number Diff line change
Expand Up @@ -3426,7 +3426,7 @@ int wc_Sha224Reset(wc_Sha224* sha224) {
{
int ret = 0; /* assume success unless proven otherwise */

if (src == NULL || dst == NULL) {
if (src == NULL || dst == NULL || src == dst) {
return BAD_FUNC_ARG;
}

Expand Down Expand Up @@ -3575,7 +3575,7 @@ int wc_Sha256Copy(wc_Sha256* src, wc_Sha256* dst)
{
int ret = 0;

if (src == NULL || dst == NULL) {
if (src == NULL || dst == NULL || src == dst) {
return BAD_FUNC_ARG;
}

Expand Down
33 changes: 33 additions & 0 deletions wolfcrypt/test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -6573,6 +6573,20 @@ static wc_test_ret_t sha224_copy_test(wc_Sha224* sha, wc_Sha224* shaCopy)
ret = wc_Sha224Update(shaCopy, (byte*)b_input, (word32)XSTRLEN(b_input));
if (ret != 0)
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
/* The common implementation rejects self-copy with BAD_FUNC_ARG.
* Platform-specific implementations differ: some accept self-copy as a
* no-op, while others do not check for it. Keep this assertion limited
* to configurations that use the common implementation. */
#if !defined(WOLFSSL_TI_HASH) && !defined(WOLFSSL_RENESAS_RX64_HASH) && \
(!defined(WOLFSSL_RENESAS_RSIP) || \
defined(NO_WOLFSSL_RENESAS_FSPSM_HASH)) && \
(!defined(WOLFSSL_KCAPI_HASH) || defined(WOLFSSL_NO_KCAPI_SHA224)) && \
(!defined(WOLFSSL_HAVE_PSA) || defined(WOLFSSL_PSA_NO_HASH)) && \
!defined(MAX3266X_SHA)
ret = wc_Sha224Copy(sha, sha);
if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
#endif
ret = wc_Sha224Update(sha, (byte*)a_input, (word32)XSTRLEN(a_input));
if (ret != 0)
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
Expand Down Expand Up @@ -6876,6 +6890,25 @@ static wc_test_ret_t sha256_copy_test(wc_Sha256* sha, wc_Sha256* shaCopy)
ret = wc_Sha256Update(shaCopy, (byte*)b_input, (word32)XSTRLEN(b_input));
if (ret != 0)
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
#endif
/* The common implementation rejects self-copy with BAD_FUNC_ARG.
* Platform-specific implementations differ: some accept self-copy as a
* no-op, while others do not check for it. Keep this assertion limited
* to configurations that use the common implementation. */
#if !defined(WOLFSSL_TI_HASH) && !defined(WOLFSSL_AFALG_HASH) && \
!defined(WOLFSSL_DEVCRYPTO_HASH) && \
((!defined(WOLFSSL_RENESAS_TSIP_TLS) && \
!defined(WOLFSSL_RENESAS_TSIP_CRYPTONLY)) || \
defined(NO_WOLFSSL_RENESAS_TSIP_CRYPT_HASH)) && \
((!defined(WOLFSSL_RENESAS_SCEPROTECT) && \
!defined(WOLFSSL_RENESAS_RSIP)) || \
defined(NO_WOLFSSL_RENESAS_FSPSM_HASH)) && \
!defined(WOLFSSL_IMXRT_DCP) && !defined(WOLFSSL_KCAPI_HASH) && \
(!defined(WOLFSSL_HAVE_PSA) || defined(WOLFSSL_PSA_NO_HASH)) && \
!defined(WOLFSSL_RENESAS_RX64_HASH) && !defined(MAX3266X_SHA)
ret = wc_Sha256Copy(sha, sha);
if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
#endif
ret = wc_Sha256Update(sha, (byte*)a_input, (word32)XSTRLEN(a_input));
if (ret != 0)
Expand Down
Loading