Skip to content

Commit

Permalink
Merge pull request #8329 from douzzer/20250103-Sha512Final-no-scratch…
Browse files Browse the repository at this point in the history
…-digest

20250103-Sha512Final-no-scratch-digest
  • Loading branch information
dgarske authored Jan 7, 2025
2 parents 1679218 + 5172ff7 commit d2ea3c6
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions wolfcrypt/src/sha512.c
Original file line number Diff line number Diff line change
Expand Up @@ -1402,22 +1402,16 @@ static WC_INLINE int Sha512Final(wc_Sha512* sha512)

static int Sha512FinalRaw(wc_Sha512* sha512, byte* hash, size_t digestSz)
{
#ifdef LITTLE_ENDIAN_ORDER
word64 digest[WC_SHA512_DIGEST_SIZE / sizeof(word64)];
#endif

if (sha512 == NULL || hash == NULL) {
return BAD_FUNC_ARG;
}

#ifdef LITTLE_ENDIAN_ORDER
ByteReverseWords64((word64*)digest, (word64*)sha512->digest,
WC_SHA512_DIGEST_SIZE);
XMEMCPY(hash, digest, digestSz);
#else
XMEMCPY(hash, sha512->digest, digestSz);
ByteReverseWords64(sha512->digest, sha512->digest, WC_SHA512_DIGEST_SIZE);
#endif

XMEMCPY(hash, sha512->digest, digestSz);

return 0;
}

Expand Down Expand Up @@ -1807,22 +1801,16 @@ int wc_Sha384Update(wc_Sha384* sha384, const byte* data, word32 len)

int wc_Sha384FinalRaw(wc_Sha384* sha384, byte* hash)
{
#ifdef LITTLE_ENDIAN_ORDER
word64 digest[WC_SHA384_DIGEST_SIZE / sizeof(word64)];
#endif

if (sha384 == NULL || hash == NULL) {
return BAD_FUNC_ARG;
}

#ifdef LITTLE_ENDIAN_ORDER
ByteReverseWords64((word64*)digest, (word64*)sha384->digest,
WC_SHA384_DIGEST_SIZE);
XMEMCPY(hash, digest, WC_SHA384_DIGEST_SIZE);
#else
XMEMCPY(hash, sha384->digest, WC_SHA384_DIGEST_SIZE);
ByteReverseWords64(sha384->digest, sha384->digest, WC_SHA384_DIGEST_SIZE);
#endif

XMEMCPY(hash, sha384->digest, WC_SHA384_DIGEST_SIZE);

return 0;
}

Expand Down

0 comments on commit d2ea3c6

Please sign in to comment.