nRF Connect SDK API 3.3.99
Loading...
Searching...
No Matches
sx_error.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
17#include <stdint.h>
18#include <errno.h>
19#include <cracen/statuscodes.h>
20
28inline __attribute__((always_inline)) int sx_err2errno(int sx_err)
29{
30 switch (sx_err) {
31 case SX_OK:
32 /* The function or operation succeeded */
33 return 0;
34 /* Error codes from sxsymcrypt */
36 /* Waiting on the hardware to process this operation */
37 return -EBUSY;
38 case SX_ERR_RETRY:
39 /* Waiting on the hardware to process this operation */
40 return -EAGAIN;
49 return -ENOTSUP;
51 /* Invalid authentication tag in authenticated decryption */
52 return -EBADMSG;
61 return -EFAULT;
71 return -EINVAL;
84 return -EINVAL;
86 /* Fatal error, trying to create instance with not enough memory
87 */
88 return -ENOMEM;
89 case SX_ERR_TOO_BIG:
90 /* Input or output buffer size too large */
91 return -EINVAL;
94 /* Input or output buffer size too small */
95 return -EINVAL;
97 /* The given key size is not supported by the algorithm or the
98 * hardware
99 */
100 return -EINVAL;
102 /* Input tag size is invalid */
103 return -EINVAL;
105 /* Input nonce size is invalid */
106 return -EINVAL;
108 /* Too many feeds were inputed */
109 return -ENOMSG;
111 /* Input data size granularity is incorrect */
112 return -EINVAL;
114 /* Attempt to use HW keys with a mode that does not support HW
115 * keys
116 */
117 return -ENOTSUP;
119 /* Attempt to use a mode or engine that does not support context
120 * saving
121 */
122 return -ENOTSUP;
124 /* Attempt to feed AAD after input data was fed */
125 return -ENOMSG;
134 return -EHOSTDOWN;
135 /* End of error codes from sxsymcrypt */
136 /* Error codes from silexpk */
138 /* The function or operation was given an invalid parameter */
139 return -EINVAL;
141 /* Unknown error */
142 return -EFAULT;
143 case SX_ERR_BUSY:
144 /* The operation is still executing */
145 return -EBUSY;
147 /* The input operand is not a quadratic residue */
148 return -EINVAL;
150 /* The input value for Rabin-Miller test is a composite value */
151 return -EINVAL;
153 /* Inversion of non-invertible value */
154 return -EINVAL;
162 return -EBADMSG;
164 /* The functionality or operation is not supported */
165 return -ENOTSUP;
167 /* The output operand is a point at infinity */
168 return -EDOM;
170 /* The input value is outside the expected range */
171 return -EDOM;
179 return -EDOM;
181 /* The input point is not on the defined elliptic curve */
182 return -EDOM;
193 return -EDOM;
195 /* A platform specific error */
196 return -EFAULT;
197 case SX_ERR_EXPIRED:
198 /* The evaluation period for the product expired */
199 return -ETIME;
200 case SX_ERR_IK_MODE:
209 return -ENOMSG;
211 /* The parameters of the elliptic curve are not valid. */
212 return -EDOM;
221 return -EBUSY;
222 case SX_ERR_PK_RETRY:
223 /* Resources not available for a new operation. Retry later */
224 return -EBUSY;
225 /* End of codes from silexpk */
226 /* Error codes that used to be from sicrypto */
229 return -EINVAL;
232 return -EHOSTDOWN;
235 return -EINVAL;
236 case SX_ERR_READY:
239 return 0;
242 return -EINVAL;
245 return -EBADMSG;
250 return -ECONNREFUSED;
255 return -EDOM;
259 return -ENOMEM;
262 return -EINVAL;
263 /* End of error codes from sicrypto */
264 default:
269 return -ENOTSUP;
270 }
271}
272
281inline __attribute__((always_inline)) const char *sx_err2str(int sx_err)
282{
283 switch (sx_err) {
284 case SX_OK:
285 /* The function or operation succeeded */
286 return "SX_OK";
287 /* Error codes from sxsymcrypt */
289 /* Waiting on the hardware to process this operation */
290 return "SX_ERR_HW_PROCESSING";
291 case SX_ERR_RETRY:
293 return "SX_ERR_RETRY";
302 return "SX_ERR_INCOMPATIBLE_HW";
304 /* Invalid authentication tag in authenticated decryption */
305 return "SX_ERR_INVALID_TAG";
314 return "SX_ERR_DMA_FAILED";
324 return "SX_ERR_UNINITIALIZED_OBJ";
337 return "SX_ERR_INVALID_KEYREF";
339 /* Fatal error, trying to create instance with not enough memory
340 */
341 return "SX_ERR_ALLOCATION_TOO_SMALL";
342 case SX_ERR_TOO_BIG:
343 /* Input or output buffer size too large */
344 return "SX_ERR_TOO_BIG";
346 /* Input buffer size too small */
347 return "SX_ERR_INPUT_BUFFER_TOO_SMALL";
349 /* Output buffer size too small */
350 return "SX_ERR_OUTPUT_BUFFER_TOO_SMALL";
352 /* The given key size is not supported by the algorithm or the
353 * hardware
354 */
355 return "SX_ERR_INVALID_KEY_SZ";
357 /* Input tag size is invalid */
358 return "SX_ERR_INVALID_TAG_SIZE";
360 /* Input nonce size is invalid */
361 return "SX_ERR_INVALID_NONCE_SIZE";
363 /* Too many feeds were inputed */
364 return "SX_ERR_FEED_COUNT_EXCEEDED";
366 /* Input data size granularity is incorrect */
367 return "SX_ERR_WRONG_SIZE_GRANULARITY";
369 /* Attempt to use HW keys with a mode that does not support HW
370 * keys
371 */
372 return "SX_ERR_HW_KEY_NOT_SUPPORTED";
374 /* Attempt to use a mode or engine that does not support context
375 * saving
376 */
377 return "SX_ERR_CONTEXT_SAVING_NOT_SUPPORTED";
379 /* Attempt to feed AAD after input data was fed */
380 return "SX_ERR_FEED_AFTER_DATA";
389 return "SX_ERR_RESET_NEEDED";
390 /* End of error codes from sxsymcrypt */
391 /* Error codes from silexpk */
393 /* The function or operation was given an invalid parameter */
394 return "SX_ERR_INVALID_PARAM";
396 /* Unknown error */
397 return "SX_ERR_UNKNOWN_ERROR";
398 case SX_ERR_BUSY:
399 /* The operation is still executing */
400 return "SX_ERR_BUSY";
402 /* The input operand is not a quadratic residue */
403 return "SX_ERR_NOT_QUADRATIC_RESIDUE";
405 /* The input value for Rabin-Miller test is a composite value */
406 return "SX_ERR_COMPOSITE_VALUE";
408 /* Inversion of non-invertible value */
409 return "SX_ERR_NOT_INVERTIBLE";
417 return "SX_ERR_INVALID_SIGNATURE";
419 /* The functionality or operation is not supported */
420 return "SX_ERR_NOT_IMPLEMENTED";
422 /* The output operand is a point at infinity */
423 return "SX_ERR_POINT_AT_INFINITY";
425 /* The input value is outside the expected range */
426 return "SX_ERR_OUT_OF_RANGE";
434 return "SX_ERR_INVALID_MODULUS";
436 /* The input point is not on the defined elliptic curve */
437 return "SX_ERR_POINT_NOT_ON_CURVE";
448 return "SX_ERR_OPERAND_TOO_LARGE";
450 /* A platform specific error */
451 return "SX_ERR_PLATFORM_ERROR";
452 case SX_ERR_EXPIRED:
453 /* The evaluation period for the product expired */
454 return "SX_ERR_EXPIRED";
455 case SX_ERR_IK_MODE:
464 return "SX_ERR_IK_MODE";
466 /* The parameters of the elliptic curve are not valid. */
467 return "SX_ERR_INVALID_CURVE_PARAM";
476 return "SX_ERR_IK_NOT_READY";
477 case SX_ERR_PK_RETRY:
478 /* Resources not available for a new operation. Retry later */
479 return "SX_ERR_PK_RETRY";
480 /* End of error codes from silexpk */
481 /* Error codes from sicrypto */
484 return "SX_ERR_INVALID_REQ_SZ";
487 return "SX_ERR_RESEED_NEEDED";
490 return "SX_ERR_INVALID_ARG";
491 case SX_ERR_READY:
494 return "SX_ERR_READY";
497 return "SX_ERR_UNSUPPORTED_HASH_ALG";
500 return "SX_ERR_INVALID_CIPHERTEXT";
505 return "SX_ERR_TOO_MANY_ATTEMPTS";
510 return "SX_ERR_RSA_PQ_RANGE_CHECK_FAIL";
514 return "SX_ERR_WORKMEM_BUFFER_TOO_SMALL";
515 /* End of error codes from sx */
516 default:
517 return "(UNKNOWN)";
518 }
519}
520
#define SX_ERR_TOO_BIG
Definition statuscodes.h:190
#define SX_ERR_INVALID_TAG_SIZE
Definition statuscodes.h:199
#define SX_ERR_INVALID_SIGNATURE
Definition statuscodes.h:46
#define SX_ERR_IK_NOT_READY
Definition statuscodes.h:108
#define SX_ERR_FEED_COUNT_EXCEEDED
Definition statuscodes.h:205
#define SX_ERR_INVALID_KEYREF
Definition statuscodes.h:184
#define SX_ERR_NOT_IMPLEMENTED
Definition statuscodes.h:49
#define SX_ERR_NOT_INVERTIBLE
Definition statuscodes.h:39
#define SX_ERR_INVALID_MODULUS
Definition statuscodes.h:69
#define SX_ERR_OPERAND_TOO_LARGE
Definition statuscodes.h:82
#define SX_ERR_PLATFORM_ERROR
Definition statuscodes.h:85
#define SX_ERR_DMA_FAILED
Definition statuscodes.h:167
#define SX_ERR_ALLOCATION_TOO_SMALL
Definition statuscodes.h:187
#define SX_ERR_INVALID_CURVE_PARAM
Definition statuscodes.h:100
#define SX_ERR_INVALID_PARAM
Definition statuscodes.h:24
#define SX_ERR_BUSY
Definition statuscodes.h:30
#define SX_ERR_COMPOSITE_VALUE
Definition statuscodes.h:36
#define SX_ERR_HW_PROCESSING
Definition statuscodes.h:146
#define SX_ERR_OUT_OF_RANGE
Definition statuscodes.h:62
#define SX_ERR_IK_MODE
Definition statuscodes.h:97
#define SX_ERR_READY
Definition statuscodes.h:128
#define SX_ERR_INVALID_KEY_SZ
Definition statuscodes.h:196
#define SX_ERR_INCOMPATIBLE_HW
Definition statuscodes.h:156
#define SX_ERR_INVALID_NONCE_SIZE
Definition statuscodes.h:202
#define SX_ERR_UNKNOWN_ERROR
Definition statuscodes.h:27
#define SX_ERR_FEED_AFTER_DATA
Definition statuscodes.h:217
#define SX_ERR_CONTEXT_SAVING_NOT_SUPPORTED
Definition statuscodes.h:214
#define SX_ERR_INVALID_ARG
Definition statuscodes.h:125
#define SX_ERR_RETRY
Definition statuscodes.h:149
#define SX_ERR_OUTPUT_BUFFER_TOO_SMALL
Definition statuscodes.h:193
#define SX_OK
Definition statuscodes.h:21
#define SX_ERR_PK_RETRY
Definition statuscodes.h:111
#define SX_ERR_RSA_PQ_RANGE_CHECK_FAIL
Definition statuscodes.h:140
#define SX_ERR_HW_KEY_NOT_SUPPORTED
Definition statuscodes.h:211
#define SX_ERR_INVALID_REQ_SZ
Definition statuscodes.h:119
#define SX_ERR_UNSUPPORTED_HASH_ALG
Definition statuscodes.h:131
#define SX_ERR_POINT_NOT_ON_CURVE
Definition statuscodes.h:72
#define SX_ERR_INVALID_TAG
Definition statuscodes.h:159
#define SX_ERR_RESET_NEEDED
Definition statuscodes.h:226
#define SX_ERR_INSUFFICIENT_ENTROPY
Definition statuscodes.h:239
#define SX_ERR_RESEED_NEEDED
Definition statuscodes.h:122
#define SX_ERR_NOT_QUADRATIC_RESIDUE
Definition statuscodes.h:33
#define SX_ERR_TOO_MANY_ATTEMPTS
Definition statuscodes.h:137
#define SX_ERR_WRONG_SIZE_GRANULARITY
Definition statuscodes.h:208
#define SX_ERR_POINT_AT_INFINITY
Definition statuscodes.h:59
#define SX_ERR_EXPIRED
Definition statuscodes.h:88
#define SX_ERR_INPUT_BUFFER_TOO_SMALL
Definition statuscodes.h:236
#define SX_ERR_INVALID_CIPHERTEXT
Definition statuscodes.h:134
#define SX_ERR_WORKMEM_BUFFER_TOO_SMALL
Definition statuscodes.h:143
#define SX_ERR_UNINITIALIZED_OBJ
Definition statuscodes.h:174
int sx_err2errno(int sx_err)
Function to convert CRACEN SW library error codes to errno.
Definition sx_error.h:28
const char * sx_err2str(int sx_err)
Function to convert CRACEN SW library error codes to strings for logging.
Definition sx_error.h:281