Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 1 | /* |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2019, Arm Limited. All rights reserved. |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #include "tfm_crypto_defs.h" |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 9 | #include "crypto_engine.h" |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 10 | #include "tfm_crypto_api.h" |
| 11 | |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 12 | static enum tfm_crypto_err_t tfm_crypto_module_init(void) |
| 13 | { |
| 14 | enum tfm_crypto_err_t err; |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 15 | |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 16 | /* Init the Key module */ |
| 17 | err = tfm_crypto_init_key(); |
| 18 | if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) { |
| 19 | return err; |
| 20 | } |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 21 | |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 22 | /* Init the Alloc module */ |
| 23 | err = tfm_crypto_init_alloc(); |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 24 | |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 25 | return err; |
| 26 | } |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 27 | |
| 28 | enum tfm_crypto_err_t tfm_crypto_init(void) |
| 29 | { |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 30 | psa_status_t status; |
| 31 | enum tfm_crypto_err_t err; |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 32 | |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 33 | /* 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 Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 49 | |
| 50 | return TFM_CRYPTO_ERR_PSA_SUCCESS; |
| 51 | } |