1 /**
2   ******************************************************************************
3   * @filestm32wb0x_hal_pka.h
4   * @author  MCD Application Team
5   * @brief   Header file of PKA HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2024 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32WB0x_HAL_PKA_H
21 #define STM32WB0x_HAL_PKA_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32wb0x_hal_def.h"
29 
30 /** @addtogroup STM32WB0x_HAL_Driver
31   * @{
32   */
33 
34 #if defined(PKA) && defined(HAL_PKA_MODULE_ENABLED)
35 
36 /** @addtogroup PKA
37   * @{
38   */
39 
40 /* Exported types ------------------------------------------------------------*/
41 /** @defgroup PKA_Exported_Types PKA Exported Types
42   * @{
43   */
44 
45 /** @defgroup HAL_state_structure_definition HAL state structure definition
46   * @brief  HAL State structures definition
47   * @{
48   */
49 typedef enum
50 {
51   HAL_PKA_STATE_RESET   = 0x00U,  /*!< PKA not yet initialized or disabled  */
52   HAL_PKA_STATE_READY   = 0x01U,  /*!< PKA initialized and ready for use    */
53   HAL_PKA_STATE_BUSY    = 0x02U,  /*!< PKA internal processing is ongoing   */
54   HAL_PKA_STATE_ERROR   = 0x03U,  /*!< PKA error state                      */
55 }
56 HAL_PKA_StateTypeDef;
57 
58 /**
59   * @}
60   */
61 
62 #if (USE_HAL_PKA_REGISTER_CALLBACKS == 1)
63 /** @defgroup HAL_callback_id HAL callback ID enumeration
64   * @{
65   */
66 typedef enum
67 {
68   HAL_PKA_OPERATION_COMPLETE_CB_ID      = 0x00U,    /*!< PKA End of operation callback ID  */
69   HAL_PKA_ERROR_CB_ID                   = 0x01U,    /*!< PKA Error callback ID             */
70   HAL_PKA_MSPINIT_CB_ID                 = 0x02U,    /*!< PKA Msp Init callback ID          */
71   HAL_PKA_MSPDEINIT_CB_ID               = 0x03U     /*!< PKA Msp DeInit callback ID        */
72 } HAL_PKA_CallbackIDTypeDef;
73 
74 /**
75   * @}
76   */
77 
78 #endif /* USE_HAL_PKA_REGISTER_CALLBACKS */
79 
80 /** @defgroup PKA_Error_Code_definition PKA Error Code definition
81   * @brief  PKA Error Code definition
82   * @{
83   */
84 #define HAL_PKA_ERROR_NONE      (0x00000000U)
85 #define HAL_PKA_ERROR_ADDRERR   (0x00000001U)
86 #define HAL_PKA_ERROR_RAMERR    (0x00000002U)
87 #define HAL_PKA_ERROR_TIMEOUT   (0x00000004U)
88 #define HAL_PKA_ERROR_OPERATION (0x00000008U)
89 #if (USE_HAL_PKA_REGISTER_CALLBACKS == 1)
90 #define HAL_PKA_ERROR_INVALID_CALLBACK  (0x00000010U)    /*!< Invalid Callback error */
91 #endif /* USE_HAL_PKA_REGISTER_CALLBACKS */
92 
93 /**
94   * @}
95   */
96 
97 /** @defgroup PKA_handle_Structure_definition PKA handle Structure definition
98   * @brief  PKA handle Structure definition
99   * @{
100   */
101 #if (USE_HAL_PKA_REGISTER_CALLBACKS == 1)
102 typedef struct __PKA_HandleTypeDef
103 #else
104 typedef struct
105 #endif  /* USE_HAL_PKA_REGISTER_CALLBACKS */
106 {
107   PKA_TypeDef                   *Instance;              /*!< Register base address */
108   __IO HAL_PKA_StateTypeDef     State;                  /*!< PKA state */
109   __IO uint32_t                 ErrorCode;              /*!< PKA Error code */
110 #if (USE_HAL_PKA_REGISTER_CALLBACKS == 1)
111   void (* OperationCpltCallback)(struct __PKA_HandleTypeDef *hpka); /*!< PKA End of operation callback */
112   void (* ErrorCallback)(struct __PKA_HandleTypeDef *hpka);         /*!< PKA Error callback            */
113   void (* MspInitCallback)(struct __PKA_HandleTypeDef *hpka);       /*!< PKA Msp Init callback         */
114   void (* MspDeInitCallback)(struct __PKA_HandleTypeDef *hpka);     /*!< PKA Msp DeInit callback       */
115 #endif  /* USE_HAL_PKA_REGISTER_CALLBACKS */
116 } PKA_HandleTypeDef;
117 /**
118   * @}
119   */
120 
121 #if (USE_HAL_PKA_REGISTER_CALLBACKS == 1)
122 /** @defgroup PKA_Callback_definition PKA Callback pointer definition
123   * @brief  PKA Callback pointer definition
124   * @{
125   */
126 typedef  void (*pPKA_CallbackTypeDef)(PKA_HandleTypeDef *hpka); /*!< Pointer to a PKA callback function */
127 /**
128   * @}
129   */
130 #endif /* USE_HAL_PKA_REGISTER_CALLBACKS */
131 /** @defgroup PKA_Operation PKA operation structure definition
132   * @brief  Input and output data definition
133   * @{
134   */
135 typedef struct
136 {
137 
138   uint32_t scalarMulSize;              /*!< Number of element in scalarMul array */
139   uint32_t modulusSize;                /*!< Number of element in modulus, coefA, pointX and pointY arrays */
140 #if defined (STM32WB05)|| defined(STM32WB09)
141   uint32_t coefSign;                   /*!< Curve coefficient a sign */
142   const uint8_t *coefA;                /*!< Pointer to curve coefficient |a| (Array of modulusSize elements) */
143   const uint8_t *modulus;              /*!< Pointer to curve modulus value p (Array of modulusSize elements) */
144 #endif /* STM32WB05 || STM32WB09 */
145   const uint8_t *pointX;               /*!< Pointer to point P coordinate xP (Array of modulusSize elements) */
146   const uint8_t *pointY;               /*!< Pointer to point P coordinate yP (Array of modulusSize elements) */
147   const uint8_t *scalarMul;            /*!< Pointer to scalar multiplier k   (Array of scalarMulSize elements) */
148 } PKA_ECCMulInTypeDef;
149 
150 typedef struct
151 {
152   uint8_t *ptX;                        /*!< Pointer to point P coordinate xP     (Array of modulusSize elements) */
153   uint8_t *ptY;                        /*!< Pointer to point P coordinate yP     (Array of modulusSize elements) */
154 } PKA_ECCMulOutTypeDef;
155 
156 #if defined (STM32WB05)|| defined(STM32WB09)
157 typedef struct
158 {
159   uint32_t scalarMulSize;              /*!< Number of element in scalarMul array */
160   uint32_t modulusSize;                /*!< Number of element in modulus, coefA, pointX and pointY arrays */
161   uint32_t coefSign;                   /*!< Curve coefficient a sign */
162   const uint8_t *coefA;                /*!< Pointer to curve coefficient |a| (Array of modulusSize elements) */
163   const uint8_t *modulus;              /*!< Pointer to curve modulus value p (Array of modulusSize elements) */
164   const uint8_t *pointX;               /*!< Pointer to point P coordinate xP (Array of modulusSize elements) */
165   const uint8_t *pointY;               /*!< Pointer to point P coordinate yP (Array of modulusSize elements) */
166   const uint8_t *scalarMul;            /*!< Pointer to scalar multiplier k   (Array of scalarMulSize elements) */
167   const uint32_t *pMontgomeryParam;    /*!< Pointer to Montgomery parameter  (Array of modulusSize/4 elements) */
168 } PKA_ECCMulFastModeInTypeDef;
169 
170 typedef struct
171 {
172   uint32_t modulusSize;                /*!< Number of element in coefA, coefB, modulus, pointX and pointY arrays */
173   uint32_t coefSign;                   /*!< Curve coefficient a sign */
174   const uint8_t *coefA;                /*!< Pointer to curve coefficient |a| (Array of modulusSize elements) */
175   const uint8_t *coefB;                /*!< Pointer to curve coefficient b   (Array of modulusSize elements) */
176   const uint8_t *modulus;              /*!< Pointer to curve modulus value p (Array of modulusSize elements) */
177   const uint8_t *pointX;               /*!< Pointer to point P coordinate xP (Array of modulusSize elements) */
178   const uint8_t *pointY;               /*!< Pointer to point P coordinate yP (Array of modulusSize elements) */
179   const uint32_t *pMontgomeryParam;    /*!< Pointer to Montgomery parameter  (Array of modulusSize/4 elements) */
180 } PKA_PointCheckInTypeDef;
181 
182 typedef struct
183 {
184   uint32_t size;                       /*!< Number of element in popA array */
185   const uint8_t *pOpDp;                /*!< Pointer to operand dP   (Array of size/2 elements) */
186   const uint8_t *pOpDq;                /*!< Pointer to operand dQ   (Array of size/2 elements) */
187   const uint8_t *pOpQinv;              /*!< Pointer to operand qinv (Array of size/2 elements) */
188   const uint8_t *pPrimeP;              /*!< Pointer to prime p      (Array of size/2 elements) */
189   const uint8_t *pPrimeQ;              /*!< Pointer to prime Q      (Array of size/2 elements) */
190   const uint8_t *popA;                 /*!< Pointer to operand A    (Array of size elements) */
191 } PKA_RSACRTExpInTypeDef;
192 
193 typedef struct
194 {
195   uint32_t primeOrderSize;             /*!< Number of element in primeOrder array */
196   uint32_t modulusSize;                /*!< Number of element in modulus array */
197   uint32_t coefSign;                   /*!< Curve coefficient a sign */
198   const uint8_t *coef;                 /*!< Pointer to curve coefficient |a|     (Array of modulusSize elements) */
199   const uint8_t *modulus;              /*!< Pointer to curve modulus value p     (Array of modulusSize elements) */
200   const uint8_t *basePointX;           /*!< Pointer to curve base point xG       (Array of modulusSize elements) */
201   const uint8_t *basePointY;           /*!< Pointer to curve base point yG       (Array of modulusSize elements) */
202   const uint8_t *pPubKeyCurvePtX;      /*!< Pointer to public-key curve point xQ (Array of modulusSize elements) */
203   const uint8_t *pPubKeyCurvePtY;      /*!< Pointer to public-key curve point yQ (Array of modulusSize elements) */
204   const uint8_t *RSign;                /*!< Pointer to signature part r          (Array of primeOrderSize elements) */
205   const uint8_t *SSign;                /*!< Pointer to signature part s          (Array of primeOrderSize elements) */
206   const uint8_t *hash;                 /*!< Pointer to hash of the message e     (Array of primeOrderSize elements) */
207   const uint8_t *primeOrder;           /*!< Pointer to order of the curve n      (Array of primeOrderSize elements) */
208 } PKA_ECDSAVerifInTypeDef;
209 
210 typedef struct
211 {
212   uint32_t primeOrderSize;             /*!< Number of element in primeOrder array */
213   uint32_t modulusSize;                /*!< Number of element in modulus array */
214   uint32_t coefSign;                   /*!< Curve coefficient a sign */
215   const uint8_t *coef;                 /*!< Pointer to curve coefficient |a|     (Array of modulusSize elements) */
216   const uint8_t *modulus;              /*!< Pointer to curve modulus value p     (Array of modulusSize elements) */
217   const uint8_t *integer;              /*!< Pointer to random integer k          (Array of primeOrderSize elements) */
218   const uint8_t *basePointX;           /*!< Pointer to curve base point xG       (Array of modulusSize elements) */
219   const uint8_t *basePointY;           /*!< Pointer to curve base point yG       (Array of modulusSize elements) */
220   const uint8_t *hash;                 /*!< Pointer to hash of the message       (Array of primeOrderSize elements) */
221   const uint8_t *privateKey;           /*!< Pointer to private key d             (Array of primeOrderSize elements) */
222   const uint8_t *primeOrder;           /*!< Pointer to order of the curve n      (Array of primeOrderSize elements) */
223 } PKA_ECDSASignInTypeDef;
224 
225 typedef struct
226 {
227   uint8_t *RSign;                      /*!< Pointer to signature part r          (Array of modulusSize elements) */
228   uint8_t *SSign;                      /*!< Pointer to signature part s          (Array of modulusSize elements) */
229 } PKA_ECDSASignOutTypeDef;
230 
231 typedef struct
232 {
233   uint8_t *ptX;                        /*!< Pointer to point P coordinate xP     (Array of modulusSize elements) */
234   uint8_t *ptY;                        /*!< Pointer to point P coordinate yP     (Array of modulusSize elements) */
235 } PKA_ECDSASignOutExtParamTypeDef;
236 
237 typedef struct
238 {
239   uint32_t expSize;                    /*!< Number of element in pExp array */
240   uint32_t OpSize;                     /*!< Number of element in pOp1 and pMod arrays */
241   const uint8_t *pExp;                 /*!< Pointer to Exponent             (Array of expSize elements) */
242   const uint8_t *pOp1;                 /*!< Pointer to Operand              (Array of OpSize elements) */
243   const uint8_t *pMod;                 /*!< Pointer to modulus              (Array of OpSize elements) */
244 } PKA_ModExpInTypeDef;
245 
246 typedef struct
247 {
248   uint32_t expSize;                    /*!< Number of element in pExp and pMontgomeryParam arrays */
249   uint32_t OpSize;                     /*!< Number of element in pOp1 and pMod arrays */
250   const uint8_t *pExp;                 /*!< Pointer to Exponent             (Array of expSize elements) */
251   const uint8_t *pOp1;                 /*!< Pointer to Operand              (Array of OpSize elements) */
252   const uint8_t *pMod;                 /*!< Pointer to modulus              (Array of OpSize elements) */
253   const uint32_t *pMontgomeryParam;    /*!< Pointer to Montgomery parameter (Array of expSize/4 elements) */
254 } PKA_ModExpFastModeInTypeDef;
255 
256 typedef struct
257 {
258   uint32_t size;                       /*!< Number of element in pOp1 array */
259   const uint8_t *pOp1;                 /*!< Pointer to Operand (Array of size elements) */
260 } PKA_MontgomeryParamInTypeDef;
261 
262 typedef struct
263 {
264   uint32_t size;                       /*!< Number of element in pOp1 and pOp2 arrays */
265   const uint32_t *pOp1;                /*!< Pointer to Operand 1 (Array of size elements) */
266   const uint32_t *pOp2;                /*!< Pointer to Operand 2 (Array of size elements) */
267 } PKA_AddInTypeDef, PKA_SubInTypeDef, PKA_MulInTypeDef, PKA_CmpInTypeDef;
268 
269 typedef struct
270 {
271   uint32_t size;                       /*!< Number of element in pOp1 array */
272   const uint32_t *pOp1;                /*!< Pointer to Operand 1       (Array of size elements) */
273   const uint8_t *pMod;                 /*!< Pointer to modulus value n (Array of size*4 elements) */
274 } PKA_ModInvInTypeDef;
275 
276 typedef struct
277 {
278   uint32_t OpSize;                     /*!< Number of element in pOp1 array */
279   uint32_t modSize;                    /*!< Number of element in pMod array */
280   const uint32_t *pOp1;                /*!< Pointer to Operand 1       (Array of OpSize elements) */
281   const uint8_t *pMod;                 /*!< Pointer to modulus value n (Array of modSize elements) */
282 } PKA_ModRedInTypeDef;
283 
284 typedef struct
285 {
286   uint32_t size;                       /*!< Number of element in pOp1 and pOp2 arrays */
287   const uint32_t *pOp1;                /*!< Pointer to Operand 1 (Array of size elements) */
288   const uint32_t *pOp2;                /*!< Pointer to Operand 2 (Array of size elements) */
289   const uint8_t  *pOp3;                /*!< Pointer to Operand 3 (Array of size*4 elements) */
290 } PKA_ModAddInTypeDef, PKA_ModSubInTypeDef, PKA_MontgomeryMulInTypeDef;
291 #endif /* STM32WB05 || STM32WB09 */
292 
293 #if defined (STM32WB09)
294 typedef struct
295 {
296   uint32_t primeOrderSize;             /*!< curve prime order n length */
297   uint32_t modulusSize;                /*!< curve modulus p length */
298   uint32_t coefSign;                   /*!< curve coefficient a sign */
299   const uint8_t *coefA;                /*!< pointer to curve coefficient |a| */
300   const uint8_t *modulus;              /*!< pointer to curve modulus value p */
301   const uint8_t *integerK;             /*!< pointer to cryptographically secure random integer k */
302   const uint8_t *integerM;             /*!< pointer to cryptographically secure random integer m */
303   const uint8_t *basePointX1;          /*!< pointer to curve base first point coordinate x */
304   const uint8_t *basePointY1;          /*!< pointer to curve base first point coordinate y */
305   const uint8_t *basePointZ1;          /*!< pointer to curve base first point coordinate z */
306   const uint8_t *basePointX2;          /*!< pointer to curve base second point coordinate x */
307   const uint8_t *basePointY2;          /*!< pointer to curve base second point coordinate y */
308   const uint8_t *basePointZ2;          /*!< pointer to curve base second point coordinate z */
309 } PKA_ECCDoubleBaseLadderInTypeDef;
310 
311 typedef struct
312 {
313   uint32_t modulusSize;                /*!< curve modulus p length */
314   uint32_t coefSign;                   /*!< curve coefficient a sign */
315   const uint8_t *modulus;              /*!< pointer to curve modulus value p */
316   const uint8_t *coefA;                /*!< pointer to curve coefficient |a| */
317   const uint8_t *basePointX1;          /*!< pointer to curve base first point coordinate x */
318   const uint8_t *basePointY1;          /*!< pointer to curve base first point coordinate y */
319   const uint8_t *basePointZ1;          /*!< pointer to curve base first point coordinate z */
320   const uint8_t *basePointX2;          /*!< pointer to curve base second point coordinate x */
321   const uint8_t *basePointY2;          /*!< pointer to curve base second point coordinate y */
322   const uint8_t *basePointZ2;          /*!< pointer to curve base second point coordinate z */
323 } PKA_ECCCompleteAdditionInTypeDef;
324 
325 typedef struct
326 {
327   uint8_t *ptX;                        /*!< Pointer to point P coordinate xP     (Array of modulusSize elements) */
328   uint8_t *ptY;                        /*!< Pointer to point P coordinate yP     (Array of modulusSize elements) */
329 } PKA_ECCDoubleBaseLadderOutTypeDef;
330 
331 typedef struct
332 {
333   uint8_t *ptX;                        /*!< pointer to point P coordinate xP */
334   uint8_t *ptY;                        /*!< pointer to point P coordinate yP */
335   uint8_t *ptZ;                        /*!< pointer to point P coordinate zP */
336 } PKA_ECCCompleteAdditionOutTypeDef;
337 #endif /* STM32WB05 || STM32WB09 */
338 /**
339   * @}
340   */
341 
342 /**
343   * @}
344   */
345 
346 /* Exported constants --------------------------------------------------------*/
347 /** @defgroup PKA_Exported_Constants PKA Exported Constants
348   * @{
349   */
350 
351 /** @defgroup PKA_Mode PKA mode
352   * @{
353   */
354 #if defined (STM32WB06) || defined(STM32WB07)
355 #define PKA_MODE_ECC_MUL                          (0x00000020U)
356 #endif /* STM32WB06 || STM32WB07 */
357 #if defined (STM32WB05)|| defined(STM32WB09)
358 #define PKA_MODE_MONTGOMERY_PARAM                 (0x00000001U)
359 #define PKA_MODE_MODULAR_EXP                      (0x00000000U)
360 #define PKA_MODE_MODULAR_EXP_FAST_MODE            (0x00000002U)
361 #define PKA_MODE_ECC_MUL                          (0x00000020U)
362 #define PKA_MODE_ECC_MUL_FAST_MODE                (0x00000022U)
363 #define PKA_MODE_ECDSA_SIGNATURE                  (0x00000024U)
364 #define PKA_MODE_POINT_CHECK                      (0x00000028U)
365 #define PKA_MODE_RSA_CRT_EXP                      (0x00000007U)
366 #define PKA_MODE_MODULAR_INV                      (0x00000008U)
367 #define PKA_MODE_ARITHMETIC_ADD                   (0x00000009U)
368 #define PKA_MODE_ARITHMETIC_SUB                   (0x0000000AU)
369 #define PKA_MODE_ARITHMETIC_MUL                   (0x0000000BU)
370 #define PKA_MODE_COMPARISON                       (0x0000000CU)
371 #define PKA_MODE_MODULAR_RED                      (0x0000000DU)
372 #define PKA_MODE_MODULAR_ADD                      (0x0000000EU)
373 #define PKA_MODE_MODULAR_SUB                      (0x0000000FU)
374 #define PKA_MODE_MONTGOMERY_MUL                   (0x00000010U)
375 #endif /* STM32WB05 || STM32WB09 */
376 #if defined (STM32WB09)
377 #define PKA_MODE_ECDSA_VERIFICATION               (0x00000025U)
378 #define PKA_MODE_DOUBLE_BASE_LADDER               (0x00000027U)
379 #define PKA_MODE_ECC_COMPLETE_ADD                 (0x00000023U)
380 #endif /* STM32WB09 */
381 #if defined (STM32WB05)
382 #define PKA_MODE_ECDSA_VERIFICATION               (0x00000026U)
383 #endif /* STM32WB05 */
384 /**
385   * @}
386   */
387 
388 /** @defgroup PKA_Interrupt_configuration_definition PKA Interrupt configuration definition
389   * @brief PKA Interrupt definition
390   * @{
391   */
392 #if defined (STM32WB05)|| defined(STM32WB09)
393 #define PKA_IT_PROCEND                            PKA_CR_PROCENDIE
394 #define PKA_IT_ADDRERR                            PKA_CR_ADDRERRIE
395 #define PKA_IT_RAMERR                             PKA_CR_RAMERRIE
396 #endif /* STM32WB05 || STM32WB09 */
397 
398 #if defined (STM32WB06) || defined(STM32WB07)
399 #define PKA_IT_PROCEND                            PKA_IEN_READY_EN
400 #define PKA_IT_ADDRERR                            PKA_IEN_ADDERR_EN
401 #define PKA_IT_RAMERR                             PKA_IEN_RAMERR_EN
402 #endif /* STM32WB06 || STM32WB07 */
403 
404 /**
405   * @}
406   */
407 
408 /** @defgroup PKA_Flag_definition PKA Flag definition
409   * @{
410   */
411 #if defined (STM32WB05)|| defined(STM32WB09)
412 #define PKA_FLAG_PROCEND                          PKA_SR_PROCENDF
413 #define PKA_FLAG_ADDRERR                          PKA_SR_ADDRERRF
414 #define PKA_FLAG_RAMERR                           PKA_SR_RAMERRF
415 #endif /* STM32WB05 || STM32WB09 */
416 
417 #if defined (STM32WB06) || defined(STM32WB07)
418 #define PKA_FLAG_PROCEND                          PKA_ISR_PROC_END
419 #define PKA_FLAG_ADDRERR                          PKA_ISR_ADD_ERR
420 #define PKA_FLAG_RAMERR                           PKA_ISR_RAM_ERR
421 #endif /* STM32WB06 || STM32WB07 */
422 /**
423   * @}
424   */
425 
426 
427 /**
428   * @}
429   */
430 
431 /* Exported macros -----------------------------------------------------------*/
432 
433 /** @defgroup PKA_Exported_Macros PKA Exported Macros
434   * @{
435   */
436 
437 /** @brief  Reset PKA handle state.
438   * @param  __HANDLE__ specifies the PKA Handle
439   * @retval None
440   */
441 #if (USE_HAL_PKA_REGISTER_CALLBACKS == 1)
442 #define __HAL_PKA_RESET_HANDLE_STATE(__HANDLE__)                do{                                                   \
443                                                                     (__HANDLE__)->State = HAL_PKA_STATE_RESET;       \
444                                                                     (__HANDLE__)->MspInitCallback = NULL;            \
445                                                                     (__HANDLE__)->MspDeInitCallback = NULL;          \
446                                                                   } while(0)
447 #else
448 #define __HAL_PKA_RESET_HANDLE_STATE(__HANDLE__)                ((__HANDLE__)->State = HAL_PKA_STATE_RESET)
449 #endif /* USE_HAL_PKA_REGISTER_CALLBACKS */
450 
451 /** @brief  Enable the specified PKA interrupt.
452   * @param  __HANDLE__ specifies the PKA Handle
453   * @param  __INTERRUPT__ specifies the interrupt source to enable.
454   *        This parameter can be one of the following values:
455   *            @arg @ref PKA_IT_PROCEND End Of Operation interrupt enable
456   *            @arg @ref PKA_IT_ADDRERR Address error interrupt enable
457   *            @arg @ref PKA_IT_RAMERR RAM error interrupt enable
458   * @retval None
459   */
460 #if defined (STM32WB06) || defined(STM32WB07)
461 #define __HAL_PKA_ENABLE_IT(__HANDLE__, __INTERRUPT__)          ((__HANDLE__)->Instance->IEN |= (__INTERRUPT__))
462 #endif /* STM32WB06 || STM32WB07 */
463 #if defined (STM32WB05)|| defined(STM32WB09)
464 #define __HAL_PKA_ENABLE_IT(__HANDLE__, __INTERRUPT__)          ((__HANDLE__)->Instance->CR |= (__INTERRUPT__))
465 #endif /* STM32WB05 || STM32WB09 */
466 /** @brief  Disable the specified PKA interrupt.
467   * @param  __HANDLE__ specifies the PKA Handle
468   * @param  __INTERRUPT__ specifies the interrupt source to disable.
469   *        This parameter can be one of the following values:
470   *            @arg @ref PKA_IT_PROCEND End Of Operation interrupt enable
471   *            @arg @ref PKA_IT_ADDRERR Address error interrupt enable
472   *            @arg @ref PKA_IT_RAMERR RAM error interrupt enable
473   * @retval None
474   */
475 #if defined (STM32WB06) || defined(STM32WB07)
476 #define __HAL_PKA_DISABLE_IT(__HANDLE__, __INTERRUPT__)         ((__HANDLE__)->Instance->IEN &= (~(__INTERRUPT__)))
477 #endif /* STM32WB06 || STM32WB07 */
478 #if defined (STM32WB05)|| defined(STM32WB09)
479 #define __HAL_PKA_DISABLE_IT(__HANDLE__, __INTERRUPT__)         ((__HANDLE__)->Instance->CR &= (~(__INTERRUPT__)))
480 #endif /* STM32WB05 || STM32WB09 */
481 /** @brief  Check whether the specified PKA interrupt source is enabled or not.
482   * @param  __HANDLE__ specifies the PKA Handle
483   * @param  __INTERRUPT__ specifies the PKA interrupt source to check.
484   *        This parameter can be one of the following values:
485   *            @arg @ref PKA_IT_PROCEND End Of Operation interrupt enable
486   *            @arg @ref PKA_IT_ADDRERR Address error interrupt enable
487   *            @arg @ref PKA_IT_RAMERR RAM error interrupt enable
488   * @retval The new state of __INTERRUPT__ (SET or RESET)
489   */
490 #if defined (STM32WB06) || defined(STM32WB07)
491 #define __HAL_PKA_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)      ((((__HANDLE__)->Instance->IEN\
492                                                                    & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
493 #endif /* STM32WB06 || STM32WB07 */
494 #if defined (STM32WB05)|| defined(STM32WB09)
495 #define __HAL_PKA_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)      ((((__HANDLE__)->Instance->CR\
496                                                                    & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
497 #endif /* STM32WB05 || STM32WB09 */
498 /** @brief  Check whether the specified PKA flag is set or not.
499   * @param  __HANDLE__ specifies the PKA Handle
500   * @param  __FLAG__ specifies the flag to check.
501   *        This parameter can be one of the following values:
502   *            @arg @ref PKA_FLAG_PROCEND End Of Operation
503   *            @arg @ref PKA_FLAG_ADDRERR Address error
504   *            @arg @ref PKA_FLAG_RAMERR RAM error
505   * @retval The new state of __FLAG__ (SET or RESET)
506   */
507 #if defined (STM32WB06) || defined(STM32WB07)
508 #define __HAL_PKA_GET_FLAG(__HANDLE__, __FLAG__)                (((((__HANDLE__)->Instance->ISR)\
509                                                                    & (__FLAG__)) == (__FLAG__)) ? SET : RESET)
510 #endif /* STM32WB06 || STM32WB07 */
511 #if defined (STM32WB05)|| defined(STM32WB09)
512 #define __HAL_PKA_GET_FLAG(__HANDLE__, __FLAG__)                (((((__HANDLE__)->Instance->SR)\
513                                                                    & (__FLAG__)) == (__FLAG__)) ? SET : RESET)
514 #endif /* STM32WB05 || STM32WB09 */
515 
516 /** @brief  Clear the PKA pending flags which are cleared by writing 1 in a specific bit.
517   * @param  __HANDLE__ specifies the PKA Handle
518   * @param  __FLAG__ specifies the flag to clear.
519   *          This parameter can be any combination of the following values:
520   *            @arg @ref PKA_FLAG_PROCEND End Of Operation
521   *            @arg @ref PKA_FLAG_ADDRERR Address error
522   *            @arg @ref PKA_FLAG_RAMERR RAM error
523   * @retval None
524   */
525 #if defined (STM32WB06) || defined(STM32WB07)
526 #define __HAL_PKA_CLEAR_FLAG(__HANDLE__, __FLAG__)    do {                                                    \
527                                                            SET_BIT((__HANDLE__)->Instance->ISR,(__FLAG__));   \
528                                                            CLEAR_BIT((__HANDLE__)->Instance->ISR,(__FLAG__)); \
529                                                          } while(0)
530 #endif /* STM32WB06 || STM32WB07 */
531 #if defined (STM32WB05)|| defined(STM32WB09)
532 #define __HAL_PKA_CLEAR_FLAG(__HANDLE__, __FLAG__)              ((__HANDLE__)->Instance->CLRFR = (__FLAG__))
533 #endif /* STM32WB05 || STM32WB09 */
534 #if defined (STM32WB05)|| defined(STM32WB09)
535 /** @brief  Enable the specified PKA peripheral.
536   * @param  __HANDLE__ specifies the PKA Handle
537   * @retval None
538   */
539 #define __HAL_PKA_ENABLE(__HANDLE__)                            (SET_BIT((__HANDLE__)->Instance->CR,  PKA_CR_EN))
540 
541 /** @brief  Disable the specified PKA peripheral.
542   * @param  __HANDLE__ specifies the PKA Handle
543   * @retval None
544   */
545 #define __HAL_PKA_DISABLE(__HANDLE__)                           (CLEAR_BIT((__HANDLE__)->Instance->CR, PKA_CR_EN))
546 #endif /* STM32WB05 || STM32WB09 */
547 /** @brief  Start a PKA operation.
548   * @param  __HANDLE__ specifies the PKA Handle
549   * @retval None
550   */
551 #if defined (STM32WB06) || defined(STM32WB07)
552 #define __HAL_PKA_START(__HANDLE__)                             (SET_BIT((__HANDLE__)->Instance->CSR,  PKA_CSR_GO))
553 #endif /* STM32WB06 || STM32WB07 */
554 #if defined (STM32WB05)|| defined(STM32WB09)
555 #define __HAL_PKA_START(__HANDLE__)                             (SET_BIT((__HANDLE__)->Instance->CR,  PKA_CR_START))
556 #endif /* STM32WB05 || STM32WB09 */
557 /**
558   * @}
559   */
560 
561 /* Private macros --------------------------------------------------------*/
562 /* Exported functions --------------------------------------------------------*/
563 /** @addtogroup PKA_Exported_Functions
564   * @{
565   */
566 
567 /** @addtogroup PKA_Exported_Functions_Group1
568   * @{
569   */
570 /* Initialization and de-initialization functions *****************************/
571 HAL_StatusTypeDef HAL_PKA_Init(PKA_HandleTypeDef *hpka);
572 HAL_StatusTypeDef HAL_PKA_DeInit(PKA_HandleTypeDef *hpka);
573 void              HAL_PKA_MspInit(PKA_HandleTypeDef *hpka);
574 void              HAL_PKA_MspDeInit(PKA_HandleTypeDef *hpka);
575 
576 #if (USE_HAL_PKA_REGISTER_CALLBACKS == 1)
577 /* Callbacks Register/UnRegister functions  ***********************************/
578 HAL_StatusTypeDef HAL_PKA_RegisterCallback(PKA_HandleTypeDef *hpka, HAL_PKA_CallbackIDTypeDef CallbackID,
579                                            pPKA_CallbackTypeDef pCallback);
580 HAL_StatusTypeDef HAL_PKA_UnRegisterCallback(PKA_HandleTypeDef *hpka, HAL_PKA_CallbackIDTypeDef CallbackID);
581 #endif /* USE_HAL_PKA_REGISTER_CALLBACKS */
582 
583 /**
584   * @}
585   */
586 
587 /** @addtogroup PKA_Exported_Functions_Group2
588   * @{
589   */
590 /* IO operation functions *****************************************************/
591 /* High Level Functions *******************************************************/
592 HAL_StatusTypeDef HAL_PKA_ECCMul(PKA_HandleTypeDef *hpka, PKA_ECCMulInTypeDef *in, uint32_t Timeout);
593 HAL_StatusTypeDef HAL_PKA_ECCMul_IT(PKA_HandleTypeDef *hpka, PKA_ECCMulInTypeDef *in);
594 void HAL_PKA_ECCMul_GetResult(PKA_HandleTypeDef *hpka, PKA_ECCMulOutTypeDef *out);
595 #if defined (STM32WB05)|| defined(STM32WB09)
596 HAL_StatusTypeDef HAL_PKA_ModExp(PKA_HandleTypeDef *hpka, PKA_ModExpInTypeDef *in, uint32_t Timeout);
597 HAL_StatusTypeDef HAL_PKA_ModExp_IT(PKA_HandleTypeDef *hpka, PKA_ModExpInTypeDef *in);
598 HAL_StatusTypeDef HAL_PKA_ModExpFastMode(PKA_HandleTypeDef *hpka, PKA_ModExpFastModeInTypeDef *in, uint32_t Timeout);
599 HAL_StatusTypeDef HAL_PKA_ModExpFastMode_IT(PKA_HandleTypeDef *hpka, PKA_ModExpFastModeInTypeDef *in);
600 void HAL_PKA_ModExp_GetResult(PKA_HandleTypeDef *hpka, uint8_t *pRes);
601 
602 HAL_StatusTypeDef HAL_PKA_ECDSASign(PKA_HandleTypeDef *hpka, PKA_ECDSASignInTypeDef *in, uint32_t Timeout);
603 HAL_StatusTypeDef HAL_PKA_ECDSASign_IT(PKA_HandleTypeDef *hpka, PKA_ECDSASignInTypeDef *in);
604 void HAL_PKA_ECDSASign_GetResult(PKA_HandleTypeDef *hpka, PKA_ECDSASignOutTypeDef *out,
605                                  PKA_ECDSASignOutExtParamTypeDef *outExt);
606 
607 HAL_StatusTypeDef HAL_PKA_ECDSAVerif(PKA_HandleTypeDef *hpka, PKA_ECDSAVerifInTypeDef *in, uint32_t Timeout);
608 HAL_StatusTypeDef HAL_PKA_ECDSAVerif_IT(PKA_HandleTypeDef *hpka, PKA_ECDSAVerifInTypeDef *in);
609 uint32_t HAL_PKA_ECDSAVerif_IsValidSignature(PKA_HandleTypeDef const *const hpka);
610 
611 HAL_StatusTypeDef HAL_PKA_RSACRTExp(PKA_HandleTypeDef *hpka, PKA_RSACRTExpInTypeDef *in, uint32_t Timeout);
612 HAL_StatusTypeDef HAL_PKA_RSACRTExp_IT(PKA_HandleTypeDef *hpka, PKA_RSACRTExpInTypeDef *in);
613 void HAL_PKA_RSACRTExp_GetResult(PKA_HandleTypeDef *hpka, uint8_t *pRes);
614 
615 HAL_StatusTypeDef HAL_PKA_PointCheck(PKA_HandleTypeDef *hpka, PKA_PointCheckInTypeDef *in, uint32_t Timeout);
616 HAL_StatusTypeDef HAL_PKA_PointCheck_IT(PKA_HandleTypeDef *hpka, PKA_PointCheckInTypeDef *in);
617 uint32_t HAL_PKA_PointCheck_IsOnCurve(PKA_HandleTypeDef const *const hpka);
618 
619 
620 HAL_StatusTypeDef HAL_PKA_ECCMulFastMode(PKA_HandleTypeDef *hpka, PKA_ECCMulFastModeInTypeDef *in, uint32_t Timeout);
621 HAL_StatusTypeDef HAL_PKA_ECCMulFastMode_IT(PKA_HandleTypeDef *hpka, PKA_ECCMulFastModeInTypeDef *in);
622 
623 HAL_StatusTypeDef HAL_PKA_Add(PKA_HandleTypeDef *hpka, PKA_AddInTypeDef *in, uint32_t Timeout);
624 HAL_StatusTypeDef HAL_PKA_Add_IT(PKA_HandleTypeDef *hpka, PKA_AddInTypeDef *in);
625 HAL_StatusTypeDef HAL_PKA_Sub(PKA_HandleTypeDef *hpka, PKA_SubInTypeDef *in, uint32_t Timeout);
626 HAL_StatusTypeDef HAL_PKA_Sub_IT(PKA_HandleTypeDef *hpka, PKA_SubInTypeDef *in);
627 HAL_StatusTypeDef HAL_PKA_Cmp(PKA_HandleTypeDef *hpka, PKA_CmpInTypeDef *in, uint32_t Timeout);
628 HAL_StatusTypeDef HAL_PKA_Cmp_IT(PKA_HandleTypeDef *hpka, PKA_CmpInTypeDef *in);
629 HAL_StatusTypeDef HAL_PKA_Mul(PKA_HandleTypeDef *hpka, PKA_MulInTypeDef *in, uint32_t Timeout);
630 HAL_StatusTypeDef HAL_PKA_Mul_IT(PKA_HandleTypeDef *hpka, PKA_MulInTypeDef *in);
631 HAL_StatusTypeDef HAL_PKA_ModAdd(PKA_HandleTypeDef *hpka, PKA_ModAddInTypeDef *in, uint32_t Timeout);
632 HAL_StatusTypeDef HAL_PKA_ModAdd_IT(PKA_HandleTypeDef *hpka, PKA_ModAddInTypeDef *in);
633 HAL_StatusTypeDef HAL_PKA_ModSub(PKA_HandleTypeDef *hpka, PKA_ModSubInTypeDef *in, uint32_t Timeout);
634 HAL_StatusTypeDef HAL_PKA_ModSub_IT(PKA_HandleTypeDef *hpka, PKA_ModSubInTypeDef *in);
635 HAL_StatusTypeDef HAL_PKA_ModInv(PKA_HandleTypeDef *hpka, PKA_ModInvInTypeDef *in, uint32_t Timeout);
636 HAL_StatusTypeDef HAL_PKA_ModInv_IT(PKA_HandleTypeDef *hpka, PKA_ModInvInTypeDef *in);
637 HAL_StatusTypeDef HAL_PKA_ModRed(PKA_HandleTypeDef *hpka, PKA_ModRedInTypeDef *in, uint32_t Timeout);
638 HAL_StatusTypeDef HAL_PKA_ModRed_IT(PKA_HandleTypeDef *hpka, PKA_ModRedInTypeDef *in);
639 HAL_StatusTypeDef HAL_PKA_MontgomeryMul(PKA_HandleTypeDef *hpka, PKA_MontgomeryMulInTypeDef *in, uint32_t Timeout);
640 HAL_StatusTypeDef HAL_PKA_MontgomeryMul_IT(PKA_HandleTypeDef *hpka, PKA_MontgomeryMulInTypeDef *in);
641 void HAL_PKA_Arithmetic_GetResult(PKA_HandleTypeDef *hpka, uint32_t *pRes);
642 
643 HAL_StatusTypeDef HAL_PKA_MontgomeryParam(PKA_HandleTypeDef *hpka, PKA_MontgomeryParamInTypeDef *in, uint32_t Timeout);
644 HAL_StatusTypeDef HAL_PKA_MontgomeryParam_IT(PKA_HandleTypeDef *hpka, PKA_MontgomeryParamInTypeDef *in);
645 void HAL_PKA_MontgomeryParam_GetResult(PKA_HandleTypeDef *hpka, uint32_t *pRes);
646 #endif /* STM32WB05 || STM32WB09 */
647 
648 #if defined (STM32WB09)
649 HAL_StatusTypeDef HAL_PKA_ECCDoubleBaseLadder(PKA_HandleTypeDef *hpka, PKA_ECCDoubleBaseLadderInTypeDef *in,
650                                               uint32_t Timeout);
651 HAL_StatusTypeDef HAL_PKA_ECCDoubleBaseLadder_IT(PKA_HandleTypeDef *hpka, PKA_ECCDoubleBaseLadderInTypeDef *in);
652 void HAL_PKA_ECCDoubleBaseLadder_GetResult(PKA_HandleTypeDef *hpka, PKA_ECCDoubleBaseLadderOutTypeDef *out);
653 
654 HAL_StatusTypeDef HAL_PKA_ECCCompleteAddition(PKA_HandleTypeDef *hpka, PKA_ECCCompleteAdditionInTypeDef *in,
655                                               uint32_t Timeout);
656 HAL_StatusTypeDef HAL_PKA_ECCCompleteAddition_IT(PKA_HandleTypeDef *hpka, PKA_ECCCompleteAdditionInTypeDef *in);
657 void HAL_PKA_ECCCompleteAddition_GetResult(PKA_HandleTypeDef *hpka, PKA_ECCCompleteAdditionOutTypeDef *out);
658 #endif /* STM32WB09 */
659 
660 HAL_StatusTypeDef HAL_PKA_Abort(PKA_HandleTypeDef *hpka);
661 void HAL_PKA_RAMReset(PKA_HandleTypeDef *hpka);
662 void HAL_PKA_OperationCpltCallback(PKA_HandleTypeDef *hpka);
663 void HAL_PKA_ErrorCallback(PKA_HandleTypeDef *hpka);
664 void HAL_PKA_IRQHandler(PKA_HandleTypeDef *hpka);
665 /**
666   * @}
667   */
668 
669 /** @addtogroup PKA_Exported_Functions_Group3
670   * @{
671   */
672 /* Peripheral State and Error functions ***************************************/
673 HAL_PKA_StateTypeDef HAL_PKA_GetState(const PKA_HandleTypeDef *hpka);
674 uint32_t             HAL_PKA_GetError(const PKA_HandleTypeDef *hpka);
675 /**
676   * @}
677   */
678 
679 /**
680   * @}
681   */
682 
683 /**
684   * @}
685   */
686 
687 #endif /* defined(PKA) && defined(HAL_PKA_MODULE_ENABLED) */
688 
689 /**
690   * @}
691   */
692 
693 #ifdef __cplusplus
694 }
695 #endif
696 
697 #endif /* STM32WB0x_HAL_PKA_H */
698