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
22 changes: 22 additions & 0 deletions wolfcrypt/src/sha256.c
Original file line number Diff line number Diff line change
Expand Up @@ -3425,11 +3425,22 @@ int wc_Sha224Reset(wc_Sha224* sha224) {
int wc_Sha224Copy(wc_Sha224* src, wc_Sha224* dst)
{
int ret = 0; /* assume success unless proven otherwise */
wc_ptr_t srcAddr;
wc_ptr_t dstAddr;

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

/* Reject if src and dst had overlapping */
srcAddr = (wc_ptr_t)src;
dstAddr = (wc_ptr_t)dst;

if ((srcAddr <= dstAddr && dstAddr - srcAddr < sizeof(*src)) ||
(dstAddr < srcAddr && srcAddr - dstAddr < sizeof(*dst))) {
return BAD_FUNC_ARG;
}

#if defined(WOLF_CRYPTO_CB) && defined(WOLF_CRYPTO_CB_COPY)
#ifndef WOLF_CRYPTO_CB_FIND
if (src->devId != INVALID_DEVID)
Expand Down Expand Up @@ -3574,11 +3585,22 @@ int wc_Sha256GetHash(wc_Sha256* sha256, byte* hash)
int wc_Sha256Copy(wc_Sha256* src, wc_Sha256* dst)
{
int ret = 0;
wc_ptr_t srcAddr;
wc_ptr_t dstAddr;

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

/* Reject if src and dst had overlapping */
srcAddr = (wc_ptr_t)src;
dstAddr = (wc_ptr_t)dst;

if ((srcAddr <= dstAddr && dstAddr - srcAddr < sizeof(*src)) ||
(dstAddr < srcAddr && srcAddr - dstAddr < sizeof(*dst))) {
return BAD_FUNC_ARG;
}

#if defined(WOLF_CRYPTO_CB) && defined(WOLF_CRYPTO_CB_COPY)
#ifndef WOLF_CRYPTO_CB_FIND
if (src->devId != INVALID_DEVID)
Expand Down
Loading