Add support for SHA-3 in PSA

Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
diff --git a/library/psa_crypto_hash.c b/library/psa_crypto_hash.c
index ddf7094..44df552 100644
--- a/library/psa_crypto_hash.c
+++ b/library/psa_crypto_hash.c
@@ -74,6 +74,14 @@
             mbedtls_sha512_free(&operation->ctx.sha512);
             break;
 #endif
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_3)
+        case PSA_ALG_SHA3_224:
+        case PSA_ALG_SHA3_256:
+        case PSA_ALG_SHA3_384:
+        case PSA_ALG_SHA3_512:
+            mbedtls_sha3_free(&operation->ctx.sha3);
+            break;
+#endif
         default:
             return PSA_ERROR_BAD_STATE;
     }
@@ -135,6 +143,24 @@
             ret = mbedtls_sha512_starts(&operation->ctx.sha512, 0);
             break;
 #endif
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_3)
+        case PSA_ALG_SHA3_224:
+            mbedtls_sha3_init(&operation->ctx.sha3);
+            ret = mbedtls_sha3_starts(&operation->ctx.sha3, MBEDTLS_SHA3_224);
+            break;
+        case PSA_ALG_SHA3_256:
+            mbedtls_sha3_init(&operation->ctx.sha3);
+            ret = mbedtls_sha3_starts(&operation->ctx.sha3, MBEDTLS_SHA3_256);
+            break;
+        case PSA_ALG_SHA3_384:
+            mbedtls_sha3_init(&operation->ctx.sha3);
+            ret = mbedtls_sha3_starts(&operation->ctx.sha3, MBEDTLS_SHA3_384);
+            break;
+        case PSA_ALG_SHA3_512:
+            mbedtls_sha3_init(&operation->ctx.sha3);
+            ret = mbedtls_sha3_starts(&operation->ctx.sha3, MBEDTLS_SHA3_512);
+            break;
+#endif
         default:
             return PSA_ALG_IS_HASH(alg) ?
                    PSA_ERROR_NOT_SUPPORTED :
@@ -197,6 +223,15 @@
                                  &source_operation->ctx.sha512);
             break;
 #endif
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_3)
+        case PSA_ALG_SHA3_224:
+        case PSA_ALG_SHA3_256:
+        case PSA_ALG_SHA3_384:
+        case PSA_ALG_SHA3_512:
+            mbedtls_sha3_clone(&target_operation->ctx.sha3,
+                               &source_operation->ctx.sha3);
+            break;
+#endif
         default:
             (void) source_operation;
             (void) target_operation;
@@ -257,6 +292,15 @@
                                         input, input_length);
             break;
 #endif
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_3)
+        case PSA_ALG_SHA3_224:
+        case PSA_ALG_SHA3_256:
+        case PSA_ALG_SHA3_384:
+        case PSA_ALG_SHA3_512:
+            ret = mbedtls_sha3_update(&operation->ctx.sha3,
+                                        input, input_length);
+            break;
+#endif
         default:
             (void) input;
             (void) input_length;
@@ -327,6 +371,14 @@
             ret = mbedtls_sha512_finish(&operation->ctx.sha512, hash);
             break;
 #endif
+#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_3)
+        case PSA_ALG_SHA3_224:
+        case PSA_ALG_SHA3_256:
+        case PSA_ALG_SHA3_384:
+        case PSA_ALG_SHA3_512:
+            ret = mbedtls_sha3_finish(&operation->ctx.sha3, hash, hash_size);
+            break;
+#endif
         default:
             (void) hash;
             return PSA_ERROR_BAD_STATE;