1 /*
2  * Copyright (c) 2001-2022, Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 
8 #ifndef _CC_RSA_ERROR_H
9 #define _CC_RSA_ERROR_H
10 
11 #ifdef CC_IOT
12 #include "mbedtls/build_info.h"
13 #endif
14 
15 #include "cc_error.h"
16 
17 #ifdef __cplusplus
18 extern "C"
19 {
20 #endif
21 
22 /*! @file
23 @brief This file contains the definitions of the CryptoCell RSA errors.
24 @defgroup cc_rsa_error CryptoCell RSA specific errors
25 @{
26 @ingroup cc_rsa
27 
28 */
29 
30 /************************ Defines ******************************/
31 
32 /* PKI RSA module on the CryptoCell layer base address - 0x00F00400 */
33 
34 /*! CryptoCell RSA module errors */
35 /*! Illegal modulus size. */
36 #define CC_RSA_INVALID_MODULUS_SIZE                        (CC_RSA_MODULE_ERROR_BASE + 0x0UL)
37 /*! Illegal modulus pointer. */
38 #define CC_RSA_INVALID_MODULUS_POINTER_ERROR               (CC_RSA_MODULE_ERROR_BASE + 0x1UL)
39 /*! Illegal exponent pointer. */
40 #define CC_RSA_INVALID_EXPONENT_POINTER_ERROR              (CC_RSA_MODULE_ERROR_BASE + 0x2UL)
41 /*! Illegal public key structure pointer. */
42 #define CC_RSA_INVALID_PUB_KEY_STRUCT_POINTER_ERROR        (CC_RSA_MODULE_ERROR_BASE + 0x3UL)
43 /*! Illegal private key structure pointer. */
44 #define CC_RSA_INVALID_PRIV_KEY_STRUCT_POINTER_ERROR       (CC_RSA_MODULE_ERROR_BASE + 0x4UL)
45 /*! Illegal exponent value. */
46 #define CC_RSA_INVALID_EXPONENT_VAL                        (CC_RSA_MODULE_ERROR_BASE + 0x5UL)
47 /*! Illegal exponent size. */
48 #define CC_RSA_INVALID_EXPONENT_SIZE                       (CC_RSA_MODULE_ERROR_BASE + 0x6UL)
49 /*! Illegal CRT first factor pointer (P_ptr) . */
50 #define CC_RSA_INVALID_CRT_FIRST_FACTOR_POINTER_ERROR      (CC_RSA_MODULE_ERROR_BASE + 0x7UL)
51 /*! Illegal CRT second factor pointer (Q_ptr) . */
52 #define CC_RSA_INVALID_CRT_SECOND_FACTOR_POINTER_ERROR     (CC_RSA_MODULE_ERROR_BASE + 0x8UL)
53 /*! Illegal CRT first exponent factor pointer (dP_ptr) . */
54 #define CC_RSA_INVALID_CRT_FIRST_FACTOR_EXP_PTR_ERROR      (CC_RSA_MODULE_ERROR_BASE + 0x9UL)
55 /*! Illegal CRT second exponent factor pointer (dQ_ptr) . */
56 #define CC_RSA_INVALID_CRT_SECOND_FACTOR_EXP_PTR_ERROR     (CC_RSA_MODULE_ERROR_BASE + 0xAUL)
57 /*! Illegal CRT coefficient pointer (qInv_ptr) . */
58 #define CC_RSA_INVALID_CRT_COEFFICIENT_PTR_ERROR           (CC_RSA_MODULE_ERROR_BASE + 0xBUL)
59 /*! Illegal CRT first factor size (Psize). */
60 #define CC_RSA_INVALID_CRT_FIRST_FACTOR_SIZE               (CC_RSA_MODULE_ERROR_BASE + 0xCUL)
61 /*! Illegal CRT second factor size (Qsize). */
62 #define CC_RSA_INVALID_CRT_SECOND_FACTOR_SIZE              (CC_RSA_MODULE_ERROR_BASE + 0xDUL)
63 /*! Illegal CRT first and second factor size (Psize + Qsize). */
64 #define CC_RSA_INVALID_CRT_FIRST_AND_SECOND_FACTOR_SIZE    (CC_RSA_MODULE_ERROR_BASE + 0xEUL)
65 /*! Illegal CRT first factor exponent value (dP). */
66 #define CC_RSA_INVALID_CRT_FIRST_FACTOR_EXPONENT_VAL       (CC_RSA_MODULE_ERROR_BASE + 0xFUL)
67 /*! Illegal CRT first factor exponent value (dQ). */
68 #define CC_RSA_INVALID_CRT_SECOND_FACTOR_EXPONENT_VAL      (CC_RSA_MODULE_ERROR_BASE + 0x10UL)
69 /*! Illegal CRT coefficient value (qInv). */
70 #define CC_RSA_INVALID_CRT_COEFF_VAL                       (CC_RSA_MODULE_ERROR_BASE + 0x11UL)
71 /*! Illegal data in. */
72 #define CC_RSA_DATA_POINTER_INVALID_ERROR                  (CC_RSA_MODULE_ERROR_BASE + 0x12UL)
73 /*! Illegal message data size. */
74 #define CC_RSA_INVALID_MESSAGE_DATA_SIZE                   (CC_RSA_MODULE_ERROR_BASE + 0x13UL)
75 /*! Illegal message value. */
76 #define CC_RSA_INVALID_MESSAGE_VAL                         (CC_RSA_MODULE_ERROR_BASE + 0x14UL)
77 /*! Modulus even error. */
78 #define CC_RSA_MODULUS_EVEN_ERROR                          (CC_RSA_MODULE_ERROR_BASE + 0x15UL)
79 /*! Illegal context pointer. */
80 #define CC_RSA_INVALID_USER_CONTEXT_POINTER_ERROR          (CC_RSA_MODULE_ERROR_BASE + 0x16UL)
81 /*! Illegal hash operation mode. */
82 #define CC_RSA_HASH_ILLEGAL_OPERATION_MODE_ERROR           (CC_RSA_MODULE_ERROR_BASE + 0x17UL)
83 /*! Illegal MGF value. */
84 #define CC_RSA_MGF_ILLEGAL_ARG_ERROR                       (CC_RSA_MODULE_ERROR_BASE + 0x18UL)
85 /*! Illegal PKCS1 version. */
86 #define CC_RSA_PKCS1_VER_ARG_ERROR                         (CC_RSA_MODULE_ERROR_BASE + 0x19UL)
87 /*! Invalid private key. */
88 #define CC_RSA_PRIV_KEY_VALIDATION_TAG_ERROR               (CC_RSA_MODULE_ERROR_BASE + 0x1AUL)
89 /*! Invalid public key. */
90 #define CC_RSA_PUB_KEY_VALIDATION_TAG_ERROR                (CC_RSA_MODULE_ERROR_BASE + 0x1BUL)
91 /*! Invalid context. */
92 #define CC_RSA_USER_CONTEXT_VALIDATION_TAG_ERROR           (CC_RSA_MODULE_ERROR_BASE + 0x1CUL)
93 /*! Illegal output pointer. */
94 #define CC_RSA_INVALID_OUTPUT_POINTER_ERROR                (CC_RSA_MODULE_ERROR_BASE + 0x1DUL)
95 /*! Illegal output size pointer. */
96 #define CC_RSA_INVALID_OUTPUT_SIZE_POINTER_ERROR           (CC_RSA_MODULE_ERROR_BASE + 0x1FUL)
97 /*! Illegal temporary buffer pointer. */
98 #define CC_RSA_CONV_TO_CRT_INVALID_TEMP_BUFF_POINTER_ERROR (CC_RSA_MODULE_ERROR_BASE + 0x20UL)
99 /*! OAEP encode parameter string is too long. */
100 #define CC_RSA_BASE_OAEP_ENCODE_PARAMETER_STRING_TOO_LONG  (CC_RSA_MODULE_ERROR_BASE + 0x22UL)
101 /*! OAEP decode parameter string is too long. */
102 #define CC_RSA_BASE_OAEP_DECODE_PARAMETER_STRING_TOO_LONG  (CC_RSA_MODULE_ERROR_BASE + 0x23UL)
103 /*! OAEP encode message is too long. */
104 #define CC_RSA_BASE_OAEP_ENCODE_MESSAGE_TOO_LONG           (CC_RSA_MODULE_ERROR_BASE + 0x24UL)
105 /*! OAEP decode message is too long. */
106 #define CC_RSA_BASE_OAEP_DECODE_MESSAGE_TOO_LONG           (CC_RSA_MODULE_ERROR_BASE + 0x25UL)
107 /*! Illegal key generation data struct pointer. */
108 #define CC_RSA_KEY_GEN_DATA_STRUCT_POINTER_INVALID         (CC_RSA_MODULE_ERROR_BASE + 0x26UL)
109 /*! Illegal PRIM data struct pointer. */
110 #define CC_RSA_PRIM_DATA_STRUCT_POINTER_INVALID            (CC_RSA_MODULE_ERROR_BASE + 0x27UL)
111 /*! Illegal message buffer size. */
112 #define CC_RSA_INVALID_MESSAGE_BUFFER_SIZE                 (CC_RSA_MODULE_ERROR_BASE + 0x28UL)
113 /*! Illegal signature buffer size. */
114 #define CC_RSA_INVALID_SIGNATURE_BUFFER_SIZE               (CC_RSA_MODULE_ERROR_BASE + 0x29UL)
115 /*! Illegal modulus size pointer. */
116 #define CC_RSA_INVALID_MOD_BUFFER_SIZE_POINTER             (CC_RSA_MODULE_ERROR_BASE + 0x2AUL)
117 /*! Illegal exponent size pointer. */
118 #define CC_RSA_INVALID_EXP_BUFFER_SIZE_POINTER             (CC_RSA_MODULE_ERROR_BASE + 0x2BUL)
119 /*! Illegal signature pointer. */
120 #define CC_RSA_INVALID_SIGNATURE_BUFFER_POINTER            (CC_RSA_MODULE_ERROR_BASE + 0x2CUL)
121 /*! Wrong private key type. */
122 #define CC_RSA_WRONG_PRIVATE_KEY_TYPE                      (CC_RSA_MODULE_ERROR_BASE + 0x2DUL)
123 /*! Illegal CRT first factor size pointer (Psize) . */
124 #define CC_RSA_INVALID_CRT_FIRST_FACTOR_SIZE_POINTER_ERROR (CC_RSA_MODULE_ERROR_BASE + 0x2EUL)
125 /*! Illegal CRT second factor size pointer (Qsize) . */
126 #define CC_RSA_INVALID_CRT_SECOND_FACTOR_SIZE_POINTER_ERROR (CC_RSA_MODULE_ERROR_BASE + 0x2FUL)
127 /*! Illegal CRT first factor exponent size pointer (dPsize) . */
128 #define CC_RSA_INVALID_CRT_FIRST_FACTOR_EXP_SIZE_PTR_ERROR (CC_RSA_MODULE_ERROR_BASE + 0x30UL)
129 /*! Illegal CRT second factor exponent size pointer (dQsize) . */
130 #define CC_RSA_INVALID_CRT_SECOND_FACTOR_EXP_SIZE_PTR_ERROR (CC_RSA_MODULE_ERROR_BASE + 0x31UL)
131 /*! Illegal CRT coefficient size pointer (qInvsize) . */
132 #define CC_RSA_INVALID_CRT_COEFFICIENT_SIZE_PTR_ERROR        (CC_RSA_MODULE_ERROR_BASE + 0x32UL)
133 /*! Illegal CRT first factor size (Psize) . */
134 #define CC_RSA_INVALID_CRT_FIRST_FACTOR_SIZE_ERROR         (CC_RSA_MODULE_ERROR_BASE + 0x33UL)
135 /*! Illegal CRT second factor size (Qsize) . */
136 #define CC_RSA_INVALID_CRT_SECOND_FACTOR_SIZE_ERROR        (CC_RSA_MODULE_ERROR_BASE + 0x34UL)
137 /*! Illegal CRT first factor exponent size (dPsize) . */
138 #define CC_RSA_INVALID_CRT_FIRST_FACTOR_EXP_SIZE_ERROR     (CC_RSA_MODULE_ERROR_BASE + 0x35UL)
139 /*! Illegal CRT second factor exponent size (dQsize) . */
140 #define CC_RSA_INVALID_CRT_SECOND_FACTOR_EXP_SIZE_ERROR    (CC_RSA_MODULE_ERROR_BASE + 0x36UL)
141 /*! Illegal CRT coefficient size (qInvsize) . */
142 #define CC_RSA_INVALID_CRT_COEFFICIENT_SIZE_ERROR            (CC_RSA_MODULE_ERROR_BASE + 0x37UL)
143 /*! Key generation conditional test failed. */
144 #define CC_RSA_KEY_GEN_CONDITIONAL_TEST_FAIL_ERROR       (CC_RSA_MODULE_ERROR_BASE + 0x38UL)
145 /*! Random generation in range failed. */
146 #define CC_RSA_CAN_NOT_GENERATE_RAND_IN_RANGE            (CC_RSA_MODULE_ERROR_BASE + 0x39UL)
147 /*! Illegal CRT parameter size. */
148 #define CC_RSA_INVALID_CRT_PARAMETR_SIZE_ERROR             (CC_RSA_MODULE_ERROR_BASE + 0x3AUL)
149 /*! Illegal modulus. */
150 #define CC_RSA_INVALID_MODULUS_ERROR                       (CC_RSA_MODULE_ERROR_BASE + 0x40UL)
151 /*! Illegal pointer. */
152 #define CC_RSA_INVALID_PTR_ERROR                           (CC_RSA_MODULE_ERROR_BASE + 0x41UL)
153 /*! Illegal decryption mode. */
154 #define CC_RSA_INVALID_DECRYPRION_MODE_ERROR               (CC_RSA_MODULE_ERROR_BASE + 0x42UL)
155 /*! Illegal generated private key. */
156 #define CC_RSA_GENERATED_PRIV_KEY_IS_TOO_LOW               (CC_RSA_MODULE_ERROR_BASE + 0x43UL)
157 /*! Key generation error. */
158 #define CC_RSA_KEY_GENERATION_FAILURE_ERROR                (CC_RSA_MODULE_ERROR_BASE + 0x44UL)
159 #define CC_RSA_INTERNAL_ERROR                              (CC_RSA_MODULE_ERROR_BASE + 0x45UL)
160 
161 
162 /****************************************************************************************
163  * PKCS#1 VERSION 1.5 ERRORS
164  ****************************************************************************************/
165 /*! BER encoding passed. */
166 #define CC_RSA_BER_ENCODING_OK                            CC_OK
167 /*! Error in BER parsing. */
168 #define CC_RSA_ERROR_BER_PARSING                         (CC_RSA_MODULE_ERROR_BASE+0x51UL)
169 /*! Error in PKCS15 message. */
170 #define CC_RSA_ENCODE_15_MSG_OUT_OF_RANGE                (CC_RSA_MODULE_ERROR_BASE+0x52UL)
171 /*! Error in PKCS15 PS. */
172 #define CC_RSA_ENCODE_15_PS_TOO_SHORT                    (CC_RSA_MODULE_ERROR_BASE+0x53UL)
173 /*! PKCS15 block type is not supported. */
174 #define CC_RSA_PKCS1_15_BLOCK_TYPE_NOT_SUPPORTED         (CC_RSA_MODULE_ERROR_BASE+0x54UL)
175 /*! Error in PKCS15 decrypted block parsing. */
176 #define CC_RSA_15_ERROR_IN_DECRYPTED_BLOCK_PARSING       (CC_RSA_MODULE_ERROR_BASE+0x55UL)
177 /*! Error in random operation. */
178 #define CC_RSA_ERROR_IN_RANDOM_OPERATION_FOR_ENCODE      (CC_RSA_MODULE_ERROR_BASE+0x56UL)
179 /*! PKCS15 verification failed. */
180 #define CC_RSA_ERROR_VER15_INCONSISTENT_VERIFY           (CC_RSA_MODULE_ERROR_BASE+0x57UL)
181 /*! Illegal message size (in no hash operation case). */
182 #define CC_RSA_INVALID_MESSAGE_DATA_SIZE_IN_NO_HASH_CASE (CC_RSA_MODULE_ERROR_BASE+0x58UL)
183 /*! Illegal message size. */
184 #define CC_RSA_INVALID_MESSAGE_DATA_SIZE_IN_SSL_CASE       (CC_RSA_MODULE_ERROR_BASE+0x59UL)
185 /*! PKCS#1 Ver 1.5 verify hash input inconsistent with hash mode derived from signature. */
186 #define CC_RSA_PKCS15_VERIFY_BER_ENCODING_HASH_TYPE    (CC_RSA_MODULE_ERROR_BASE+0x60UL)  /*!< \internal PKCS#1 Ver 1.5 verify hash input inconsistent with hash mode derived from signature*/
187 /*! Illegal DER hash mode */
188 #define CC_RSA_GET_DER_HASH_MODE_ILLEGAL                 (CC_RSA_MODULE_ERROR_BASE+0x61UL)
189 
190 /****************************************************************************************
191  * PKCS#1 VERSION 2.1 ERRORS
192  ****************************************************************************************/
193  /*! Illegal salt length. */
194 #define CC_RSA_PSS_ENCODING_MODULUS_HASH_SALT_LENGTHS_ERROR  (CC_RSA_MODULE_ERROR_BASE+0x80UL)
195 /*! Illegal MGF mask. */
196 #define CC_RSA_BASE_MGF_MASK_TOO_LONG                   (CC_RSA_MODULE_ERROR_BASE+0x81UL)
197 /*! PSS verification failed. */
198 #define CC_RSA_ERROR_PSS_INCONSISTENT_VERIFY            (CC_RSA_MODULE_ERROR_BASE+0x82UL)
199 /*! OAEP message too long. */
200 #define CC_RSA_OAEP_VER21_MESSAGE_TOO_LONG              (CC_RSA_MODULE_ERROR_BASE+0x83UL)
201 /*! OAEP error in decrypted block parsing. */
202 #define CC_RSA_ERROR_IN_DECRYPTED_BLOCK_PARSING         (CC_RSA_MODULE_ERROR_BASE+0x84UL)
203 /*! OAEP decoding error. */
204 #define CC_RSA_OAEP_DECODE_ERROR                        (CC_RSA_MODULE_ERROR_BASE+0x85UL)
205 /*! Error in decrypted data size. */
206 #define CC_RSA_15_ERROR_IN_DECRYPTED_DATA_SIZE          (CC_RSA_MODULE_ERROR_BASE+0x86UL)
207 /*! Error in decrypted data. */
208 #define CC_RSA_15_ERROR_IN_DECRYPTED_DATA               (CC_RSA_MODULE_ERROR_BASE+0x87UL)
209 /*! Illegal L pointer. */
210 #define CC_RSA_OAEP_L_POINTER_ERROR                     (CC_RSA_MODULE_ERROR_BASE+0x88UL)
211 /*! Illegal output size. */
212 #define CC_RSA_DECRYPT_INVALID_OUTPUT_SIZE              (CC_RSA_MODULE_ERROR_BASE+0x89UL)
213 /*! Illegal output size pointer. */
214 #define CC_RSA_DECRYPT_OUTPUT_SIZE_POINTER_ERROR        (CC_RSA_MODULE_ERROR_BASE+0x8AUL)
215 /*! Illegal parameters. */
216 #define CC_RSA_ILLEGAL_PARAMS_ACCORDING_TO_PRIV_ERROR   (CC_RSA_MODULE_ERROR_BASE + 0x93UL)
217 /*! RSA is not supported. */
218 #define CC_RSA_IS_NOT_SUPPORTED                         (CC_RSA_MODULE_ERROR_BASE+0xFFUL)
219 
220 
221 /************************ Enums ********************************/
222 
223 
224 /************************ Typedefs  ****************************/
225 
226 
227 /************************ Structs  ******************************/
228 
229 
230 /************************ Public Variables **********************/
231 
232 
233 /************************ Public Functions **********************/
234 
235 #ifdef __cplusplus
236 }
237 #endif
238 /**
239 @}
240  */
241 
242 #endif /* _CC_RSA_ERROR_H */
243 
244