@@ -870,6 +870,10 @@ static int InitSha512_Family(wc_Sha512* sha512, void* heap, int devId,
870870
871871 sha512 -> heap = heap ;
872872#ifdef WOLFSSL_SMALL_STACK_CACHE
873+ /* This allocation combines the customary W buffer used by
874+ * _Transform_Sha512() with additional buffer space used by
875+ * wc_Sha512Transform().
876+ */
873877 sha512 -> W = (word64 * )XMALLOC ((sizeof (word64 ) * 16 ) + WC_SHA512_BLOCK_SIZE ,
874878 sha512 -> heap , DYNAMIC_TYPE_DIGEST );
875879 if (sha512 -> W == NULL )
@@ -1702,6 +1706,9 @@ int wc_Sha512Transform(wc_Sha512* sha, const unsigned char* data)
17021706#if defined(WOLFSSL_SMALL_STACK_CACHE )
17031707 if (sha -> W == NULL )
17041708 return BAD_FUNC_ARG ;
1709+ /* Skip over the initial `W' buffer at the start (used by
1710+ * _Transform_Sha512()).
1711+ */
17051712 buffer = sha -> W + 16 ;
17061713#elif defined(WOLFSSL_SMALL_STACK )
17071714 buffer = (word64 * )XMALLOC (WC_SHA512_BLOCK_SIZE , sha -> heap ,
@@ -1873,6 +1880,10 @@ static int InitSha384(wc_Sha384* sha384)
18731880
18741881#ifdef WOLFSSL_SMALL_STACK_CACHE
18751882 if (sha384 -> W == NULL ) {
1883+ /* This allocation combines the customary W buffer used by
1884+ * _Transform_Sha512() with additional buffer space used by
1885+ * wc_Sha512Transform().
1886+ */
18761887 sha384 -> W = (word64 * )XMALLOC ((sizeof (word64 ) * 16 ) + WC_SHA512_BLOCK_SIZE ,
18771888 sha384 -> heap , DYNAMIC_TYPE_DIGEST );
18781889 if (sha384 -> W == NULL )
@@ -2232,6 +2243,10 @@ int wc_Sha512Copy(wc_Sha512* src, wc_Sha512* dst)
22322243
22332244 XMEMCPY (dst , src , sizeof (wc_Sha512 ));
22342245#ifdef WOLFSSL_SMALL_STACK_CACHE
2246+ /* This allocation combines the customary W buffer used by
2247+ * _Transform_Sha512() with additional buffer space used by
2248+ * wc_Sha512Transform().
2249+ */
22352250 dst -> W = (word64 * )XMALLOC ((sizeof (word64 ) * 16 ) + WC_SHA512_BLOCK_SIZE ,
22362251 dst -> heap , DYNAMIC_TYPE_DIGEST );
22372252 if (dst -> W == NULL ) {
@@ -2667,6 +2682,10 @@ int wc_Sha384Copy(wc_Sha384* src, wc_Sha384* dst)
26672682 XMEMCPY (dst , src , sizeof (wc_Sha384 ));
26682683
26692684#ifdef WOLFSSL_SMALL_STACK_CACHE
2685+ /* This allocation combines the customary W buffer used by
2686+ * _Transform_Sha512() with additional buffer space used by
2687+ * wc_Sha512Transform().
2688+ */
26702689 dst -> W = (word64 * )XMALLOC ((sizeof (word64 ) * 16 ) + WC_SHA384_BLOCK_SIZE ,
26712690 dst -> heap , DYNAMIC_TYPE_DIGEST );
26722691 if (dst -> W == NULL ) {
0 commit comments