Add implementation of psa_crypto_output_alloc()

Signed-off-by: David Horstmann <david.horstmann@arm.com>
diff --git a/library/psa_crypto.c b/library/psa_crypto.c
index d4c566d..669087c 100644
--- a/library/psa_crypto.c
+++ b/library/psa_crypto.c
@@ -5591,4 +5591,28 @@
     input_copy->len = 0;
 }
 
+psa_status_t psa_crypto_output_copy_alloc(uint8_t *output, size_t output_len,
+                                          psa_crypto_output_copy_t *output_copy)
+{
+    output_copy->original = NULL;
+    output_copy->buffer = NULL;
+    output_copy->len = 0;
+
+    /* Treat NULL and zero-length input the same.
+     * This is simpler than potentially calling calloc(0). */
+    if (output == NULL || output_len == 0) {
+        return PSA_SUCCESS;
+    }
+    output_copy->buffer = mbedtls_calloc(output_len, 1);
+    if (output_copy->buffer == NULL) {
+        /* Since we dealt with the zero-length case above, we know that
+         * a NULL return value means a failure of allocation. */
+        return PSA_ERROR_INSUFFICIENT_MEMORY;
+    }
+    output_copy->len = output_len;
+    output_copy->original = output;
+
+    return PSA_SUCCESS;
+}
+
 #endif /* MBEDTLS_PSA_CRYPTO_C */