Skip to content

Commit

Permalink
Allow for zero length hash. Its not an error.
Browse files Browse the repository at this point in the history
Fixes ZD17910
  • Loading branch information
anhu committed Apr 30, 2024
1 parent 6e49aa7 commit 529b6a1
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 @@ -777,7 +777,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 @@ -828,6 +835,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 @@ -167,6 +167,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 @@ -1024,7 +1035,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 @@ -1414,6 +1432,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 @@ -1489,7 +1518,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 529b6a1

Please sign in to comment.