1 /**
2   ******************************************************************************
3   * @file    se_psa.h
4   * @author  MCD Application Team
5   * @version V1.0.0
6   * @brief   SE_PSA interface include file.
7   *          Specifies device specific defines, macros, types.
8   ******************************************************************************
9   * @attention
10   *
11   * Copyright (c) 2021 STMicroelectronics.
12   * All rights reserved.
13   *
14   * This software is licensed under terms that can be found in the LICENSE file
15   * in the root directory of this software component.
16   * If no LICENSE file comes with this software, it is provided AS-IS.
17   *
18   ******************************************************************************
19   */
20 
21 /* Define to prevent recursive inclusion -------------------------------------*/
22 #ifndef __SE_PSA_H__
23 #define __SE_PSA_H__
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif /* __cplusplus */
28 
29 /* Includes ------------------------------------------------------------------*/
30 #include "psa/crypto_se_driver.h"
31 #include "psa/crypto.h"
32 #include "psa/crypto_extra.h"
33 #include "se_psa_id.h"
34 
35 
36 /** This macro checks if the result of an `expression` is equal to an
37   *  `expected` value and sets a `status` variable of type `psa_status_t` to
38   *  `PSA_SUCCESS`. If they are not equal, the `status` is set to
39   *  `psa_error instead`, the error details are printed, and the code jumps
40   *  to the `exit` label. */
41 #define ASSERT_STATUS(expression, expected, psa_error)              \
42   do                                                              \
43   {                                                               \
44     SE_API_Status_t ASSERT_result = (expression);                   \
45     SE_API_Status_t ASSERT_expected = (expected);                   \
46     if ((ASSERT_result) != (ASSERT_expected))                   \
47     {                                                           \
48       printf("assertion failed at %s:%d "                     \
49              "(actual=%d expected=%d)\n", __FILE__, __LINE__, \
50              ASSERT_result, ASSERT_expected);                 \
51       status = (psa_error);                                   \
52       goto exit;                                              \
53     }                                                           \
54     status = PSA_SUCCESS;                                       \
55   } while(0)
56 
57 /** Check if an ATCA operation is successful, translate the error otherwise. */
58 #define ASSERT_SUCCESS(expression) ASSERT_STATUS(expression, SE_OK, \
59                                                  se_st_to_psa_error(ASSERT_result))
60 
61 /** Does the same as the macro above, but without the error translation and for
62   *  the PSA return code - PSA_SUCCESS.*/
63 #define ASSERT_SUCCESS_PSA(expression) ASSERT_STATUS(expression, PSA_SUCCESS, \
64                                                      ASSERT_result)
65 
66 
67 extern const psa_drv_se_t psa_se_st;
68 
69 #ifdef __cplusplus
70 }
71 #endif /* __cplusplus */
72 
73 #endif /* __SE_PSA_H__ */
74 
75 
76