blob: 1332a002779f32d4e7bd8f6c2107d34760fdec1f [file] [log] [blame]
Antonio de Angelis8908f472018-08-31 15:44:25 +01001/*
2 * Copyright (c) 2018, Arm Limited. All rights reserved.
3 *
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 */
28#define TFM_CRYPTO_MAX_KEY_LENGTH (16)
29
30/**
31 * \brief Define miscellaneous literal constants that are used in the module
32 *
33 */
34enum {
35 TFM_CRYPTO_NOT_IN_USE = 0,
36 TFM_CRYPTO_IN_USE = 1
37};
38
39enum tfm_crypto_err_t {
40 TFM_CRYPTO_ERR_PSA_SUCCESS = 0,
41 TFM_CRYPTO_ERR_PSA_ERROR_NOT_SUPPORTED = TFM_CRYPTO_ERR_PSA_ERROR_OFFSET,
42 TFM_CRYPTO_ERR_PSA_ERROR_NOT_PERMITTED,
43 TFM_CRYPTO_ERR_PSA_ERROR_BUFFER_TOO_SMALL,
44 TFM_CRYPTO_ERR_PSA_ERROR_OCCUPIED_SLOT,
45 TFM_CRYPTO_ERR_PSA_ERROR_EMPTY_SLOT,
46 TFM_CRYPTO_ERR_PSA_ERROR_BAD_STATE,
47 TFM_CRYPTO_ERR_PSA_ERROR_INVALID_ARGUMENT,
48 TFM_CRYPTO_ERR_PSA_ERROR_INSUFFICIENT_MEMORY,
49 TFM_CRYPTO_ERR_PSA_ERROR_INSUFFICIENT_STORAGE,
50 TFM_CRYPTO_ERR_PSA_ERROR_COMMUNICATION_FAILURE,
51 TFM_CRYPTO_ERR_PSA_ERROR_STORAGE_FAILURE,
52 TFM_CRYPTO_ERR_PSA_ERROR_HARDWARE_FAILURE,
53 TFM_CRYPTO_ERR_PSA_ERROR_TAMPERING_DETECTED,
54 TFM_CRYPTO_ERR_PSA_ERROR_INSUFFICIENT_ENTROPY,
55 TFM_CRYPTO_ERR_PSA_ERROR_INVALID_SIGNATURE,
56 TFM_CRYPTO_ERR_PSA_ERROR_INVALID_PADDING,
57 TFM_CRYPTO_ERR_PSA_ERROR_UNKNOWN_ERROR,
58
59 /* Add an invalid return code which forces the size of the type as well */
60 TFM_CRYPTO_ERR_INVALID = INT_MAX
61};
62
63/**
64 * \brief A macro to translate PSA API return values including the offset
65 * needed by TFM, to the corresponding PSA value
66 */
67#define TFM_CRYPTO_PSA_RETURN(val) \
68 ( (val == TFM_CRYPTO_ERR_PSA_SUCCESS) ? val : \
69 ((val >= TFM_CRYPTO_ERR_PSA_ERROR_NOT_SUPPORTED) ? \
70 (val - (TFM_CRYPTO_ERR_PSA_ERROR_NOT_SUPPORTED-1)) : \
71 TFM_CRYPTO_ERR_INVALID) )
72
73#ifdef __cplusplus
74}
75#endif
76
77#endif /* __TFM_CRYPTO_DEFS_H__ */