1 /*
2  * Copyright (c) 2001-2019, Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 
8 
9 /*!
10  @addtogroup cc_error
11  @{
12  */
13 
14 /*!
15  @file
16  @brief This file defines the error return code types and the numbering spaces
17         for each module of the layers listed.
18 */
19 
20 
21 #ifndef _CC_ERROR_H
22 #define _CC_ERROR_H
23 
24 #include "cc_pal_types.h"
25 
26 #ifdef __cplusplus
27 extern "C"
28 {
29 #endif
30 
31 /*! The definitions of the error number-space used for the different modules */
32 
33 /* ........... Error base numeric mapping definitions ................... */
34 /* ----------------------------------------------------------------------- */
35 
36  /*! The error base number for CryptoCell. */
37 #define CC_ERROR_BASE          0x00F00000UL
38 
39 /*! The error range number assigned for each layer. */
40 #define CC_ERROR_LAYER_RANGE   0x00010000UL
41 
42 /*! The error range number assigned to each module on its specified layer. */
43 #define CC_ERROR_MODULE_RANGE  0x00000100UL
44 
45 /* Defines the layer index for the error mapping. */
46 /*! The CryptoCell error-layer index. */
47 #define CC_LAYER_ERROR_IDX     0x00UL
48 /*! The error-layer index for low-level functions. */
49 #define LLF_LAYER_ERROR_IDX      0x01UL
50 /*! The generic error-layer index. */
51 #define GENERIC_ERROR_IDX        0x05UL
52 
53 /* Defines the module index for error mapping */
54 /*! The AES error index.*/
55 #define AES_ERROR_IDX            0x00UL
56 /*! The DES error index.*/
57 #define DES_ERROR_IDX            0x01UL
58 /*! The hash error index.*/
59 #define HASH_ERROR_IDX           0x02UL
60 /*! The HMAC error index.*/
61 #define HMAC_ERROR_IDX           0x03UL
62 /*! The RSA error index.*/
63 #define RSA_ERROR_IDX            0x04UL
64 /*! The DH error index.*/
65 #define DH_ERROR_IDX             0x05UL
66 /*! The ECPKI error index.*/
67 #define ECPKI_ERROR_IDX          0x08UL
68 /*! The RND error index.*/
69 #define RND_ERROR_IDX            0x0CUL
70 /*! The Common error index.*/
71 #define COMMON_ERROR_IDX         0x0DUL
72 /*! The KDF error index.*/
73 #define KDF_ERROR_IDX            0x11UL
74 /*! The HKDF error index.*/
75 #define HKDF_ERROR_IDX           0x12UL
76 /*! The AESCCM error index.*/
77 #define AESCCM_ERROR_IDX         0x15UL
78 /*! The FIPS error index.*/
79 #define FIPS_ERROR_IDX           0x17UL
80 /*! The PKA error index.*/
81 
82 #define PKA_MODULE_ERROR_IDX     0x21UL
83 /*! The ChaCha error index.*/
84 #define CHACHA_ERROR_IDX         0x22UL
85 /*! The EC Montgomery and Edwards error index.*/
86 #define EC_MONT_EDW_ERROR_IDX    0x23UL
87 /*! The ChaCha-POLY error index.*/
88 #define CHACHA_POLY_ERROR_IDX    0x24UL
89 /*! The POLY error index.*/
90 #define POLY_ERROR_IDX           0x25UL
91 /*! The SRP error index.*/
92 #define SRP_ERROR_IDX            0x26UL
93 
94 
95 /*! The AESGCM error index.*/
96 #define AESGCM_ERROR_IDX         0x27UL
97 
98 /*! The AES key-wrap error index.*/
99 #define AES_KEYWRAP_ERROR_IDX    0x28UL
100 
101 /*! Management error index.*/
102 #define MNG_ERROR_IDX            0x29UL
103 
104 /*! Production error index.*/
105 #define PROD_ERROR_IDX           0x2AUL
106 
107 /*! The FFCDH error index. */
108 #define FFCDH_ERROR_IDX          0x2BUL
109 /*! The FFC domain error index. */
110 #define FFC_DOMAIN_ERROR_IDX     0x2CUL
111 
112 /*! Do not change! Error definition, reserved for Secure Boot ECDSA */
113 #define SB_ECC_ERROR_IDX_        0x2DUL
114 /*! External DMA error index. */
115 #define EXT_DMA_ERROR_IDX        0x2EUL
116 
117 
118 
119 /* .......... defining the error spaces for each module on each layer ........... */
120 /* ------------------------------------------------------------------------------ */
121 
122 /*! The error base address of the AES module - 0x00F00000. */
123 #define CC_AES_MODULE_ERROR_BASE  (CC_ERROR_BASE + \
124                                      (CC_ERROR_LAYER_RANGE * CC_LAYER_ERROR_IDX) + \
125                                      (CC_ERROR_MODULE_RANGE * AES_ERROR_IDX ) )
126 
127 /*! The error base address of the DES module - 0x00F00100. */
128 #define CC_DES_MODULE_ERROR_BASE  (CC_ERROR_BASE + \
129                                      (CC_ERROR_LAYER_RANGE * CC_LAYER_ERROR_IDX) + \
130                                      (CC_ERROR_MODULE_RANGE * DES_ERROR_IDX ) )
131 
132 /*! The error base address of the hash module - 0x00F00200. */
133 #define CC_HASH_MODULE_ERROR_BASE (CC_ERROR_BASE + \
134                                      (CC_ERROR_LAYER_RANGE * CC_LAYER_ERROR_IDX) + \
135                                      (CC_ERROR_MODULE_RANGE * HASH_ERROR_IDX ) )
136 
137 /*! The error base address of the HMAC module - 0x00F00300. */
138 #define CC_HMAC_MODULE_ERROR_BASE (CC_ERROR_BASE + \
139                                      (CC_ERROR_LAYER_RANGE * CC_LAYER_ERROR_IDX) + \
140                                      (CC_ERROR_MODULE_RANGE * HMAC_ERROR_IDX ) )
141 
142 /*! The error base address of the RSA module - 0x00F00400. */
143 #define CC_RSA_MODULE_ERROR_BASE (CC_ERROR_BASE + \
144                                    (CC_ERROR_LAYER_RANGE * CC_LAYER_ERROR_IDX) + \
145                                    (CC_ERROR_MODULE_RANGE * RSA_ERROR_IDX ) )
146 
147 /*! The error base address of the DH module - 0x00F00500. */
148 #define CC_DH_MODULE_ERROR_BASE  (CC_ERROR_BASE + \
149                                    (CC_ERROR_LAYER_RANGE * CC_LAYER_ERROR_IDX) + \
150                                    (CC_ERROR_MODULE_RANGE * DH_ERROR_IDX ) )
151 
152 /*! The error base address of the ECPKI module - 0x00F00800. */
153 #define CC_ECPKI_MODULE_ERROR_BASE (CC_ERROR_BASE + \
154                                      (CC_ERROR_LAYER_RANGE * CC_LAYER_ERROR_IDX) + \
155                                      (CC_ERROR_MODULE_RANGE * ECPKI_ERROR_IDX ) )
156 
157 /*! The error base address of the low-level ECPKI module -  0x00F10800. */
158 #define LLF_ECPKI_MODULE_ERROR_BASE  (CC_ERROR_BASE + \
159                                      (CC_ERROR_LAYER_RANGE * LLF_LAYER_ERROR_IDX) + \
160                                      (CC_ERROR_MODULE_RANGE * ECPKI_ERROR_IDX ) )
161 
162 /*! The error base address of the RND module - 0x00F00C00. */
163 #define CC_RND_MODULE_ERROR_BASE   (CC_ERROR_BASE + \
164                                      (CC_ERROR_LAYER_RANGE * CC_LAYER_ERROR_IDX) + \
165                                      (CC_ERROR_MODULE_RANGE * RND_ERROR_IDX ) )
166 
167 /*! The error base address of the low-level RND module -  0x00F10C00. */
168 #define LLF_RND_MODULE_ERROR_BASE    (CC_ERROR_BASE + \
169                                      (CC_ERROR_LAYER_RANGE * LLF_LAYER_ERROR_IDX) + \
170                                      (CC_ERROR_MODULE_RANGE * RND_ERROR_IDX ) )
171 
172 /*! The error base address of the common module - 0x00F00D00. */
173 #define CC_COMMON_MODULE_ERROR_BASE (CC_ERROR_BASE + \
174                                      (CC_ERROR_LAYER_RANGE * CC_LAYER_ERROR_IDX) + \
175                                      (CC_ERROR_MODULE_RANGE * COMMON_ERROR_IDX ) )
176 
177 /*! The error base address of the KDF module - 0x00F01100. */
178 #define CC_KDF_MODULE_ERROR_BASE (CC_ERROR_BASE + \
179                                   (CC_ERROR_LAYER_RANGE * CC_LAYER_ERROR_IDX) + \
180                                   (CC_ERROR_MODULE_RANGE * KDF_ERROR_IDX ) )
181 
182 /*! The error base address of the HKDF module - 0x00F01100. */
183 #define CC_HKDF_MODULE_ERROR_BASE (CC_ERROR_BASE + \
184                                   (CC_ERROR_LAYER_RANGE * CC_LAYER_ERROR_IDX) + \
185                                   (CC_ERROR_MODULE_RANGE * HKDF_ERROR_IDX ) )
186 
187 /*! The error base address of the AESCCM module - 0x00F01500. */
188 #define CC_AESCCM_MODULE_ERROR_BASE  (CC_ERROR_BASE + \
189                                        (CC_ERROR_LAYER_RANGE * CC_LAYER_ERROR_IDX) + \
190                                        (CC_ERROR_MODULE_RANGE * AESCCM_ERROR_IDX ) )
191 
192 /*! The error base address of the FIPS module - 0x00F01700. */
193 #define CC_FIPS_MODULE_ERROR_BASE  (CC_ERROR_BASE + \
194                                        (CC_ERROR_LAYER_RANGE * CC_LAYER_ERROR_IDX) + \
195                                        (CC_ERROR_MODULE_RANGE * FIPS_ERROR_IDX ) )
196 
197 /*! The error base address of the PKA module - 0x00F02100. */
198 #define PKA_MODULE_ERROR_BASE             (CC_ERROR_BASE + \
199                                            (CC_ERROR_LAYER_RANGE * CC_LAYER_ERROR_IDX) + \
200                                            (CC_ERROR_MODULE_RANGE * PKA_MODULE_ERROR_IDX ) )
201 
202 /*! The error base address of the ChaCha module - 0x00F02200. */
203 #define CC_CHACHA_MODULE_ERROR_BASE  (CC_ERROR_BASE + \
204                                            (CC_ERROR_LAYER_RANGE * CC_LAYER_ERROR_IDX) + \
205                                            (CC_ERROR_MODULE_RANGE * CHACHA_ERROR_IDX ) )
206 /*! The error base address of the EC MONT_EDW module - 0x00F02300.  */
207 #define CC_EC_MONT_EDW_MODULE_ERROR_BASE (CC_ERROR_BASE + \
208                                            (CC_ERROR_LAYER_RANGE * CC_LAYER_ERROR_IDX) + \
209                                            (CC_ERROR_MODULE_RANGE * EC_MONT_EDW_ERROR_IDX ) )
210 
211 /*! The error base address of the Chacha-POLY module - 0x00F02400. */
212 #define CC_CHACHA_POLY_MODULE_ERROR_BASE  (CC_ERROR_BASE + \
213                                            (CC_ERROR_LAYER_RANGE * CC_LAYER_ERROR_IDX) + \
214                                            (CC_ERROR_MODULE_RANGE * CHACHA_POLY_ERROR_IDX ) )
215 /*! The error base address of the POLY module - 0x00F02500. */
216 #define CC_POLY_MODULE_ERROR_BASE  (CC_ERROR_BASE + \
217                                            (CC_ERROR_LAYER_RANGE * CC_LAYER_ERROR_IDX) + \
218                                            (CC_ERROR_MODULE_RANGE * POLY_ERROR_IDX ) )
219 
220 /*! The error base address of the SRP module - 0x00F02600. */
221 #define CC_SRP_MODULE_ERROR_BASE (CC_ERROR_BASE + \
222                                            (CC_ERROR_LAYER_RANGE * CC_LAYER_ERROR_IDX) + \
223                                            (CC_ERROR_MODULE_RANGE * SRP_ERROR_IDX ) )
224 
225 /*! The error base address of the AESGCM module - 0x00F02700. */
226 #define CC_AESGCM_MODULE_ERROR_BASE  (CC_ERROR_BASE + \
227                                        (CC_ERROR_LAYER_RANGE * CC_LAYER_ERROR_IDX) + \
228                                        (CC_ERROR_MODULE_RANGE * AESGCM_ERROR_IDX ) )
229 
230 /*! The error base address of the AES key-wrap module - 0x00F02800. */
231 #define CC_AES_KEYWRAP_MODULE_ERROR_BASE  (CC_ERROR_BASE + \
232                           (CC_ERROR_LAYER_RANGE * CC_LAYER_ERROR_IDX) + \
233                           (CC_ERROR_MODULE_RANGE * AES_KEYWRAP_ERROR_IDX ) )
234 
235 /*! The error base address of the Management module - 0x00F02900. */
236 #define CC_MNG_MODULE_ERROR_BASE      (CC_ERROR_BASE + \
237                         (CC_ERROR_LAYER_RANGE * CC_LAYER_ERROR_IDX) + \
238                         (CC_ERROR_MODULE_RANGE * MNG_ERROR_IDX ) )
239 
240 /*! The error base address of the production library - 0x00F02A00 */
241 #define CC_PROD_MODULE_ERROR_BASE  (CC_ERROR_BASE + \
242                                      (CC_ERROR_LAYER_RANGE * CC_LAYER_ERROR_IDX) + \
243                                      (CC_ERROR_MODULE_RANGE * PROD_ERROR_IDX ) )
244 
245 /*! The error base address of the FFCDH module - 0x00F02B00. */
246 #define CC_FFCDH_MODULE_ERROR_BASE (CC_ERROR_BASE + \
247                                            (CC_ERROR_LAYER_RANGE * CC_LAYER_ERROR_IDX) + \
248                                            (CC_ERROR_MODULE_RANGE * FFCDH_ERROR_IDX ) )
249 
250 /*! The error base address of the FFCDH module - 0x00F02B00. */
251 #define CC_FFC_DOMAIN_MODULE_ERROR_BASE (CC_ERROR_BASE + \
252                                            (CC_ERROR_LAYER_RANGE * CC_LAYER_ERROR_IDX) + \
253                                            (CC_ERROR_MODULE_RANGE * FFC_DOMAIN_ERROR_IDX ) )
254 
255 /*! The error base address of the External DMA module - 0x00F02B00. */
256 #define CC_EXT_DMA_MODULE_ERROR_BASE (CC_ERROR_BASE + \
257                                            (CC_ERROR_LAYER_RANGE * CC_LAYER_ERROR_IDX) + \
258                                            (CC_ERROR_MODULE_RANGE * EXT_DMA_ERROR_IDX ) )
259 
260 /*! The generic error base address of the user - 0x00F50000 */
261 #define GENERIC_ERROR_BASE ( CC_ERROR_BASE + (CC_ERROR_LAYER_RANGE * GENERIC_ERROR_IDX) )
262 /*! CryptoCell fatal error. */
263 #define CC_FATAL_ERROR          (GENERIC_ERROR_BASE + 0x00UL)
264 /*! CryptoCell out of resources error. */
265 #define CC_OUT_OF_RESOURCE_ERROR        (GENERIC_ERROR_BASE + 0x01UL)
266 /*! CryptoCell illegal resource value error. */
267 #define CC_ILLEGAL_RESOURCE_VAL_ERROR       (GENERIC_ERROR_BASE + 0x02UL)
268 
269 
270 
271 /* ............ The OK (success) definition ....................... */
272 
273 /*! A macro that defines the CryptoCell return value. */
274 #define CC_CRYPTO_RETURN_ERROR(retCode, retcodeInfo, funcHandler) \
275     ((retCode) == 0 ? CC_OK : funcHandler(retCode, retcodeInfo))
276 
277 /************************ Enums ********************************/
278 
279 
280 /************************ Typedefs  ****************************/
281 
282 
283 /************************ Structs  ******************************/
284 
285 
286 /************************ Public Variables **********************/
287 
288 
289 /************************ Public Functions **********************/
290 
291 #ifdef __cplusplus
292 }
293 #endif
294 
295 /*!
296 @}
297  */
298 
299 #endif
300