Index: azure_iot_hub_f767zi/trunk/wolfssl-4.7.0/wolfcrypt/src/sha512.c
===================================================================
--- azure_iot_hub_f767zi/trunk/wolfssl-4.4.0/wolfcrypt/src/sha512.c	(revision 457)
+++ azure_iot_hub_f767zi/trunk/wolfssl-4.7.0/wolfcrypt/src/sha512.c	(revision 464)
@@ -27,5 +27,5 @@
 #include <wolfssl/wolfcrypt/settings.h>
 
-#if (defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA384)) && !defined(WOLFSSL_ARMASM)
+#if (defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA384)) && !defined(WOLFSSL_ARMASM) && !defined(WOLFSSL_PSOC6_CRYPTO)
 
 #if defined(HAVE_FIPS) && \
@@ -188,4 +188,7 @@
 #if defined(WOLFSSL_IMX6_CAAM) && !defined(NO_IMX6_CAAM_HASH)
     /* functions defined in wolfcrypt/src/port/caam/caam_sha.c */
+
+#elif defined(WOLFSSL_SILABS_SHA384)
+    /* functions defined in wolfcrypt/src/port/silabs/silabs_hash.c */
 
 #else
@@ -338,9 +341,26 @@
     static int transform_check = 0;
     static int intel_flags;
-    #define Transform_Sha512(sha512)     (*Transform_Sha512_p)(sha512)
-    #define Transform_Sha512_Len(sha512, len) \
-                                          (*Transform_Sha512_Len_p)(sha512, len)
-
-    static void Sha512_SetTransform()
+    static int Transform_Sha512_is_vectorized = 0;
+
+    static WC_INLINE int Transform_Sha512(wc_Sha512 *sha512) {
+        int ret;
+        if (Transform_Sha512_is_vectorized)
+            SAVE_VECTOR_REGISTERS();
+        ret = (*Transform_Sha512_p)(sha512);
+        if (Transform_Sha512_is_vectorized)
+            RESTORE_VECTOR_REGISTERS();
+        return ret;
+    }
+    static WC_INLINE int Transform_Sha512_Len(wc_Sha512 *sha512, word32 len) {
+        int ret;
+        if (Transform_Sha512_is_vectorized)
+            SAVE_VECTOR_REGISTERS();
+        ret = (*Transform_Sha512_Len_p)(sha512, len);
+        if (Transform_Sha512_is_vectorized)
+            RESTORE_VECTOR_REGISTERS();
+        return ret;
+    }
+
+    static void Sha512_SetTransform(void)
     {
         if (transform_check)
@@ -355,4 +375,5 @@
                 Transform_Sha512_p = Transform_Sha512_AVX2_RORX;
                 Transform_Sha512_Len_p = Transform_Sha512_AVX2_RORX_Len;
+                Transform_Sha512_is_vectorized = 1;
             }
             else
@@ -361,4 +382,5 @@
                 Transform_Sha512_p = Transform_Sha512_AVX2;
                 Transform_Sha512_Len_p = Transform_Sha512_AVX2_Len;
+                Transform_Sha512_is_vectorized = 1;
             }
         #ifdef HAVE_INTEL_RORX
@@ -366,4 +388,5 @@
                 Transform_Sha512_p = Transform_Sha512_AVX1_RORX;
                 Transform_Sha512_Len_p = Transform_Sha512_AVX1_RORX_Len;
+                Transform_Sha512_is_vectorized = 1;
             }
         #endif
@@ -375,8 +398,12 @@
             Transform_Sha512_p = Transform_Sha512_AVX1;
             Transform_Sha512_Len_p = Transform_Sha512_AVX1_Len;
+            Transform_Sha512_is_vectorized = 1;
         }
         else
     #endif
+        {
             Transform_Sha512_p = _Transform_Sha512;
+            Transform_Sha512_is_vectorized = 1;
+        }
 
         transform_check = 1;
@@ -399,4 +426,7 @@
 
     sha512->heap = heap;
+#ifdef WOLFSSL_SMALL_STACK_CACHE
+    sha512->W = NULL;
+#endif
 
     ret = InitSha512(sha512);
@@ -406,8 +436,4 @@
 #if defined(HAVE_INTEL_AVX1) || defined(HAVE_INTEL_AVX2)
     Sha512_SetTransform();
-#endif
-
-#ifdef WOLFSSL_SMALL_STACK_CACHE
-    sha512->W = NULL;
 #endif
 
@@ -508,6 +534,5 @@
     word64* W = sha512->W;
     if (W == NULL) {
-        W = (word64*) XMALLOC(sizeof(word64) * 16, NULL,
-                                                       DYNAMIC_TYPE_TMP_BUFFER);
+        W = (word64*)XMALLOC(sizeof(word64) * 16, NULL,DYNAMIC_TYPE_TMP_BUFFER);
         if (W == NULL)
             return MEMORY_E;
@@ -693,5 +718,5 @@
 #endif
 
-    if (len > 0) {
+    if (ret == 0 && len > 0) {
         XMEMCPY(local, data, len);
         sha512->buffLen = len;
@@ -722,5 +747,5 @@
 #endif /* WOLFSSL_SHA512 */
 
-#endif /* WOLFSSL_IMX6_CAAM */
+#endif /* WOLFSSL_IMX6_CAAM || WOLFSSL_SILABS_SHA384 */
 
 static WC_INLINE int Sha512Final(wc_Sha512* sha512)
@@ -903,4 +928,7 @@
     /* functions defined in wolfcrypt/src/port/caam/caam_sha.c */
 
+#elif defined(WOLFSSL_SILABS_SHA512)
+    /* functions defined in wolfcrypt/src/port/silabs/silabs_hash.c */
+
 #else
 
@@ -1020,4 +1048,8 @@
 
     sha384->heap = heap;
+#ifdef WOLFSSL_SMALL_STACK_CACHE
+    sha384->W = NULL;
+#endif
+
     ret = InitSha384(sha384);
     if (ret != 0)
@@ -1026,7 +1058,4 @@
 #if defined(HAVE_INTEL_AVX1) || defined(HAVE_INTEL_AVX2)
     Sha512_SetTransform();
-#endif
-#ifdef WOLFSSL_SMALL_STACK_CACHE
-    sha384->W = NULL;
 #endif
 
@@ -1041,5 +1070,5 @@
 }
 
-#endif /* WOLFSSL_IMX6_CAAM */
+#endif /* WOLFSSL_IMX6_CAAM || WOLFSSL_SILABS_SHA512 */
 
 int wc_InitSha384(wc_Sha384* sha384)
@@ -1112,4 +1141,9 @@
 #endif
 
+#ifdef WOLFSSL_SILABS_SHA512
+    dst->silabsCtx.hash_ctx.cmd_ctx = &(dst->silabsCtx.cmd_ctx);
+    dst->silabsCtx.hash_ctx.hash_type_ctx = &(dst->silabsCtx.hash_type_ctx);
+#endif
+
 #ifdef WOLFSSL_ASYNC_CRYPT
     ret = wolfAsync_DevCopy(&src->asyncDev, &dst->asyncDev);
@@ -1188,4 +1222,9 @@
 #endif
 
+#ifdef WOLFSSL_SILABS_SHA384
+    dst->silabsCtx.hash_ctx.cmd_ctx = &(dst->silabsCtx.cmd_ctx);
+    dst->silabsCtx.hash_ctx.hash_type_ctx = &(dst->silabsCtx.hash_type_ctx);
+#endif
+
 #ifdef WOLFSSL_ASYNC_CRYPT
     ret = wolfAsync_DevCopy(&src->asyncDev, &dst->asyncDev);
