blob: ed85dc877291293788f27b0dacbeb21bb709df63 [file] [log] [blame]
Antonio de Angelis8908f472018-08-31 15:44:25 +01001/*
Antonio de Angelis377a1552018-11-22 17:02:40 +00002 * 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#ifndef __TFM_CRYPTO_DEFS_H__
9#define __TFM_CRYPTO_DEFS_H__
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15#include <stdint.h>
16#include <limits.h>
17#include "tfm_api.h"
18
19/* The return value is shared with the TFM service status value. The Crypto
20 * return codes shouldn't overlap with predefined TFM status values.
21 */
22#define TFM_CRYPTO_ERR_PSA_ERROR_OFFSET (TFM_PARTITION_SPECIFIC_ERROR_MIN)
23
24/**
25 * \brief This defines the maximum supported key length in bytes
26 *
27 */
Louis Mayencourt7a36f782018-09-24 14:00:57 +010028#define TFM_CRYPTO_MAX_KEY_LENGTH (32)
29
30/**
31 * \brief This value is used to mark an handle as invalid.
32 *
33 */
34#define TFM_CRYPTO_INVALID_HANDLE (0xFFFFFFFF)
Antonio de Angelis8908f472018-08-31 15:44:25 +010035
36/**
Antonio de Angelis377a1552018-11-22 17:02:40 +000037 * \brief Define miscellaneous literal constants that are used in the module
38 *
39 */
Antonio de Angelis8908f472018-08-31 15:44:25 +010040enum {
41 TFM_CRYPTO_NOT_IN_USE = 0,
42 TFM_CRYPTO_IN_USE = 1
43};
44
Antonio de Angelis377a1552018-11-22 17:02:40 +000045/**
46 * \brief Possible return values from the TFM Crypto service. They must
47 * provide corresponding return values for psa_status_t possible
48 * values as specified in psa_crypto.h
49 */
Antonio de Angelis8908f472018-08-31 15:44:25 +010050enum tfm_crypto_err_t {
51 TFM_CRYPTO_ERR_PSA_SUCCESS = 0,
Antonio de Angelis377a1552018-11-22 17:02:40 +000052 TFM_CRYPTO_ERR_PSA_ERROR_UNKNOWN_ERROR = TFM_CRYPTO_ERR_PSA_ERROR_OFFSET,
53 TFM_CRYPTO_ERR_PSA_ERROR_NOT_SUPPORTED,
Antonio de Angelis8908f472018-08-31 15:44:25 +010054 TFM_CRYPTO_ERR_PSA_ERROR_NOT_PERMITTED,
55 TFM_CRYPTO_ERR_PSA_ERROR_BUFFER_TOO_SMALL,
56 TFM_CRYPTO_ERR_PSA_ERROR_OCCUPIED_SLOT,
57 TFM_CRYPTO_ERR_PSA_ERROR_EMPTY_SLOT,
58 TFM_CRYPTO_ERR_PSA_ERROR_BAD_STATE,
59 TFM_CRYPTO_ERR_PSA_ERROR_INVALID_ARGUMENT,
60 TFM_CRYPTO_ERR_PSA_ERROR_INSUFFICIENT_MEMORY,
61 TFM_CRYPTO_ERR_PSA_ERROR_INSUFFICIENT_STORAGE,
62 TFM_CRYPTO_ERR_PSA_ERROR_COMMUNICATION_FAILURE,
63 TFM_CRYPTO_ERR_PSA_ERROR_STORAGE_FAILURE,
64 TFM_CRYPTO_ERR_PSA_ERROR_HARDWARE_FAILURE,
65 TFM_CRYPTO_ERR_PSA_ERROR_TAMPERING_DETECTED,
66 TFM_CRYPTO_ERR_PSA_ERROR_INSUFFICIENT_ENTROPY,
67 TFM_CRYPTO_ERR_PSA_ERROR_INVALID_SIGNATURE,
68 TFM_CRYPTO_ERR_PSA_ERROR_INVALID_PADDING,
Antonio de Angelis8908f472018-08-31 15:44:25 +010069
70 /* Add an invalid return code which forces the size of the type as well */
71 TFM_CRYPTO_ERR_INVALID = INT_MAX
72};
73
74/**
Antonio de Angelis377a1552018-11-22 17:02:40 +000075 * \brief A macro to translate TFM Crypto service return values to the
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010076 * corresponding psa_status_t value. The user of this macro needs
Antonio de Angelis377a1552018-11-22 17:02:40 +000077 * to cast the produced value to psa_status_t explicitly if needed
78 *
79 * \return Values specified by \ref psa_status_t
Antonio de Angelis8908f472018-08-31 15:44:25 +010080 */
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010081#define TFM_CRYPTO_ERR_TO_PSA_STATUS(val) \
Antonio de Angelis377a1552018-11-22 17:02:40 +000082 ( (val == TFM_CRYPTO_ERR_PSA_SUCCESS) ? val : \
83 ((val >= (enum tfm_crypto_err_t)TFM_CRYPTO_ERR_PSA_ERROR_OFFSET) ? \
84 (val - ((enum tfm_crypto_err_t)TFM_CRYPTO_ERR_PSA_ERROR_OFFSET-1)) : \
85 TFM_CRYPTO_ERR_INVALID) )
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010086/**
87 * \brief A macro to translate psa_status_t values to the corresponding return
88 * values for the TFM Crypto service
89 *
90 * \return Values specified by \ref enum tfm_crypto_err_t
91 *
92 */
93#define PSA_STATUS_TO_TFM_CRYPTO_ERR(val) \
94 ( (val == PSA_SUCCESS) ? (enum tfm_crypto_err_t)val : \
95 (enum tfm_crypto_err_t)(val + TFM_CRYPTO_ERR_PSA_ERROR_OFFSET) )
Antonio de Angelis8908f472018-08-31 15:44:25 +010096
97#ifdef __cplusplus
98}
99#endif
100
101#endif /* __TFM_CRYPTO_DEFS_H__ */