Skip to content

Commit

Permalink
Merge pull request #7489 from anhu/zero_len_hash
Browse files Browse the repository at this point in the history
Allow for zero length hash.  Its not an error.
  • Loading branch information
douzzer authored May 9, 2024
2 parents d53abc2 + 529b6a1 commit af928fa
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
20 changes: 19 additions & 1 deletion wolfcrypt/src/sha256.c
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,14 @@ static int InitSha256(wc_Sha256* sha256)
{
int ret = 0;

if (sha256 == NULL || (data == NULL && len > 0)) {
if (sha256 == NULL) {
return BAD_FUNC_ARG;
}
if (data == NULL && len == 0) {
/* valid, but do nothing */
return 0;
}
if (data == NULL) {
return BAD_FUNC_ARG;
}

Expand Down Expand Up @@ -876,6 +883,17 @@ static int InitSha256(wc_Sha256* sha256)

int wc_Sha256Update(wc_Sha256* sha256, const byte* data, word32 len)
{
if (sha256 == NULL) {
return BAD_FUNC_ARG;
}
if (data == NULL && len == 0) {
/* valid, but do nothing */
return 0;
}
if (data == NULL) {
return BAD_FUNC_ARG;
}

return se050_hash_update(&sha256->se050Ctx, data, len);
}

Expand Down
41 changes: 39 additions & 2 deletions wolfcrypt/src/sha512.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@
}
int wc_Sha512Update(wc_Sha512* sha512, const byte* data, word32 len)
{
if (sha512 == NULL) {
return BAD_FUNC_ARG;
}
if (data == NULL && len == 0) {
/* valid, but do nothing */
return 0;
}
if (data == NULL) {
return BAD_FUNC_ARG;
}

return se050_hash_update(&sha512->se050Ctx, data, len);
}
int wc_Sha512Final(wc_Sha512* sha512, byte* hash)
Expand Down Expand Up @@ -1096,7 +1107,14 @@ static WC_INLINE int Sha512Update(wc_Sha512* sha512, const byte* data, word32 le

int wc_Sha512Update(wc_Sha512* sha512, const byte* data, word32 len)
{
if (sha512 == NULL || (data == NULL && len > 0)) {
if (sha512 == NULL) {
return BAD_FUNC_ARG;
}
if (data == NULL && len == 0) {
/* valid, but do nothing */
return 0;
}
if (data == NULL) {
return BAD_FUNC_ARG;
}

Expand Down Expand Up @@ -1497,6 +1515,17 @@ int wc_Sha512Transform(wc_Sha512* sha, const unsigned char* data)
}
int wc_Sha384Update(wc_Sha384* sha384, const byte* data, word32 len)
{
if (sha384 == NULL) {
return BAD_FUNC_ARG;
}
if (data == NULL && len == 0) {
/* valid, but do nothing */
return 0;
}
if (data == NULL) {
return BAD_FUNC_ARG;
}

return se050_hash_update(&sha384->se050Ctx, data, len);

}
Expand Down Expand Up @@ -1582,7 +1611,15 @@ static int InitSha384(wc_Sha384* sha384)

int wc_Sha384Update(wc_Sha384* sha384, const byte* data, word32 len)
{
if (sha384 == NULL || (data == NULL && len > 0)) {

if (sha384 == NULL) {
return BAD_FUNC_ARG;
}
if (data == NULL && len == 0) {
/* valid, but do nothing */
return 0;
}
if (data == NULL) {
return BAD_FUNC_ARG;
}

Expand Down

0 comments on commit af928fa

Please sign in to comment.