Implement hash functions

New header file crypto_struct.h. The main file crypto.sh declares
structures which are implementation-defined. These structures must be
defined in crypto_struct.h, which is included at the end so that the
structures can use types defined in crypto.h.

Implement psa_hash_start, psa_hash_update and psa_hash_final. This
should work for all hash algorithms supported by Mbed TLS, but has
only been smoke-tested for SHA-256, and only in the nominal case.
diff --git a/include/psa/crypto.h b/include/psa/crypto.h
index c1eb60f..90140d7 100644
--- a/include/psa/crypto.h
+++ b/include/psa/crypto.h
@@ -307,6 +307,54 @@
 
 /**@}*/
 
+/** \defgroup hash Message digests
+ * @{
+ */
+
+typedef struct psa_hash_operation_s psa_hash_operation_t;
+
+#define PSA_HASH_FINAL_SIZE(alg)                \
+    (                                           \
+        (alg) == PSA_ALG_MD2 ? 16 :             \
+        (alg) == PSA_ALG_MD4 ? 16 :             \
+        (alg) == PSA_ALG_MD5 ? 16 :             \
+        (alg) == PSA_ALG_SHA_256_128 ? 16 :     \
+        (alg) == PSA_ALG_RIPEMD160 ? 20 :       \
+        (alg) == PSA_ALG_SHA_1 ? 20 :           \
+        (alg) == PSA_ALG_SHA_256_160 ? 20 :     \
+        (alg) == PSA_ALG_SHA_224 ? 28 :         \
+        (alg) == PSA_ALG_SHA_256 ? 32 :         \
+        (alg) == PSA_ALG_SHA_384 ? 48 :         \
+        (alg) == PSA_ALG_SHA_512 ? 64 :         \
+        (alg) == PSA_ALG_SHA_512_224 ? 28 :     \
+        (alg) == PSA_ALG_SHA_512_256 ? 32 :     \
+        (alg) == PSA_ALG_SHA3_224 ? 28 :        \
+        (alg) == PSA_ALG_SHA3_256 ? 32 :        \
+        (alg) == PSA_ALG_SHA3_384 ? 48 :        \
+        (alg) == PSA_ALG_SHA3_512 ? 64 :        \
+        0)
+
+psa_status_t psa_hash_start(psa_hash_operation_t *operation,
+                            psa_algorithm_t alg);
+
+psa_status_t psa_hash_update(psa_hash_operation_t *operation,
+                             const uint8_t *input,
+                             size_t input_length);
+
+psa_status_t psa_hash_finish(psa_hash_operation_t *operation,
+                             uint8_t *hash,
+                             size_t hash_size,
+                             size_t *hash_length);
+
+psa_status_t psa_hash_verify(psa_hash_operation_t *operation,
+                             const uint8_t *hash,
+                             size_t hash_length);
+
+psa_status_t ps_hash_abort(psa_hash_operation_t *operation);
+
+/**@}*/
+
+/** \defgroup MAC Message authentication codes
 /** \defgroup asymmetric Asymmetric cryptography
  * @{
  */
@@ -379,6 +427,12 @@
 }
 #endif
 
+/* The file "crypto_struct.h" contains definitions for
+ * implementation-specific structs that are declared above. */
+#include "crypto_struct.h"
+
+/* The file "crypto_extra.h" contains vendor-specific definitions. This
+ * can include vendor-defined algorithms, extra functions, etc. */
 #include "crypto_extra.h"
 
 #endif /* PSA_CRYPTO_H */
diff --git a/include/psa/crypto_struct.h b/include/psa/crypto_struct.h
new file mode 100644
index 0000000..6bd4ed2
--- /dev/null
+++ b/include/psa/crypto_struct.h
@@ -0,0 +1,96 @@
+/**
+ * \file psa/crypto_struct.h
+ *
+ * \brief PSA cryptography module: Mbed TLS structured type implementations
+ */
+/*
+ *  Copyright (C) 2018, ARM Limited, All Rights Reserved
+ *  SPDX-License-Identifier: Apache-2.0
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License"); you may
+ *  not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *  This file is part of mbed TLS (https://tls.mbed.org)
+ */
+
+#ifndef PSA_CRYPTO_STRUCT_H
+#define PSA_CRYPTO_STRUCT_H
+
+/* Include the Mbed TLS configuration file, the way Mbed TLS does it
+ * in each of its header files. */
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "../mbedtls/config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
+#include "mbedtls/cipher.h"
+#include "mbedtls/cmac.h"
+#include "mbedtls/gcm.h"
+#include "mbedtls/md.h"
+#include "mbedtls/md2.h"
+#include "mbedtls/md4.h"
+#include "mbedtls/md5.h"
+#include "mbedtls/ripemd160.h"
+#include "mbedtls/sha1.h"
+#include "mbedtls/sha256.h"
+#include "mbedtls/sha512.h"
+
+struct psa_hash_operation_s
+{
+    psa_algorithm_t alg;
+    union
+    {
+#if defined(MBEDTLS_MD2_C)
+        mbedtls_md2_context md2;
+#endif
+#if defined(MBEDTLS_MD4_C)
+        mbedtls_md4_context md4;
+#endif
+#if defined(MBEDTLS_MD5_C)
+        mbedtls_md5_context md5;
+#endif
+#if defined(MBEDTLS_RIPEMD160_C)
+        mbedtls_ripemd160_context ripemd160;
+#endif
+#if defined(MBEDTLS_SHA1_C)
+        mbedtls_sha1_context sha1;
+#endif
+#if defined(MBEDTLS_SHA256_C)
+        mbedtls_sha256_context sha256;
+#endif
+#if defined(MBEDTLS_SHA512_C)
+        mbedtls_sha512_context sha512;
+#endif
+    } ctx;
+};
+
+struct psa_mac_operation_s
+{
+    psa_algorithm_t alg;
+    int key_set : 1;
+    int iv_required : 1;
+    int iv_set : 1;
+    int has_input : 1;
+    uint8_t mac_size;
+    union
+    {
+#if defined(MBEDTLS_MD_C)
+        mbedtls_md_context_t hmac;
+#endif
+#if defined(MBEDTLS_CMAC_C)
+        mbedtls_cipher_context_t cmac;
+#endif
+    } ctx;
+};
+
+#endif /* PSA_CRYPTO_STRUCT_H */