blob: 083ce84da0c6605d6b44bbc075373fc9dcbf58f5 [file] [log] [blame]
Antonio de Angelis8908f472018-08-31 15:44:25 +01001/*
Antonio de Angeliscf85ba22018-10-09 13:29:40 +01002 * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
Antonio de Angelis8908f472018-08-31 15:44:25 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#include "tfm_crypto_defs.h"
Antonio de Angeliscf85ba22018-10-09 13:29:40 +01009#include "crypto_engine.h"
Antonio de Angelis8908f472018-08-31 15:44:25 +010010#include "tfm_crypto_api.h"
11
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010012static enum tfm_crypto_err_t tfm_crypto_module_init(void)
13{
14 enum tfm_crypto_err_t err;
Antonio de Angelis8908f472018-08-31 15:44:25 +010015
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010016 /* Init the Key module */
17 err = tfm_crypto_init_key();
18 if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
19 return err;
20 }
Antonio de Angelis8908f472018-08-31 15:44:25 +010021
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010022 /* Init the Alloc module */
23 err = tfm_crypto_init_alloc();
Antonio de Angelis8908f472018-08-31 15:44:25 +010024
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010025 return err;
26}
Antonio de Angelis8908f472018-08-31 15:44:25 +010027
28enum tfm_crypto_err_t tfm_crypto_init(void)
29{
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010030 psa_status_t status;
31 enum tfm_crypto_err_t err;
Antonio de Angelis8908f472018-08-31 15:44:25 +010032
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010033 /* Initialise other modules of the service */
34 err = tfm_crypto_module_init();
35 if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
36 return err;
37 }
38
39 /* Initialise the engine interface module */
40 status = tfm_crypto_engine_init();
41 if (status != PSA_SUCCESS) {
42 /* FIXME: For the time being, keep returning success even if the engine
43 * is not initialised correctly. This can be used to test corner cases
44 * without triggering any TF-M recovery mechanism during boot-up if it
45 * recognises that a service has not completed booting correctly.
46 */
47 return TFM_CRYPTO_ERR_PSA_SUCCESS;
48 }
Antonio de Angelis8908f472018-08-31 15:44:25 +010049
50 return TFM_CRYPTO_ERR_PSA_SUCCESS;
51}