stm32h7xx_hal_driver icon indicating copy to clipboard operation
stm32h7xx_hal_driver copied to clipboard

CRYP api upgrade

Open fermentedfly opened this issue 2 years ago • 3 comments

As far as I can tell the current HAL_CRYP_Encrypt (decrypt as well) provides an all-in-one solution for encryption. This is fine but my use case requires an API that can be initialized and then fed with multiple blocks of data, i.e. something like Init -> Encrypt Block 1 -> Encrypt Block 2 -> ... -> Finalize

Some other HAL implementations, e.g. STM32L4, provide functionality to do this. I've had a look in stm32h7xx_hal_cryp.c and it seems all the required functions are already present but have internal linkage. Please consider making those functions public.

Regards, Manuel

fermentedfly avatar May 10 '23 14:05 fermentedfly

Hello @fermentedfly,

Thank you for this report. We will get back to you as soon as we analyze it further. This may take some time. Thank you for your comprehension.

With regards,

TOUNSTM avatar Jun 02 '23 13:06 TOUNSTM

Hello @fermentedfly,

Thank you for this contribution. Could you please give me more details about this issue, I need to know what internally linked functions you are talking about?

Best Regards,

HBOSTM avatar Aug 04 '23 08:08 HBOSTM

Hello @HBOSTM ,

I had a deeper look in stm32h7xx_hal_cryp.c and my initial estimate was a bit optimistic. I use AES CBC & GCM. For CBC, making static void CRYP_AES_ProcessData(CRYP_HandleTypeDef *hcryp, uint32_t Timeout) public is enough although a separate Init() would be very convenient.

For GCM, static HAL_StatusTypeDef CRYP_AESGCM_Process(CRYP_HandleTypeDef *hcryp, uint32_t Timeout) needs refactoring, i.e. the function needs to be split in it's three phases (header, data, finalize) in order to feed data multiple times.

For reference, please have a look in stm32l4xx_hal_cryp.c & stm32l4xx_hal_cryp_ex.c. It got my use case (both CBC & GCM) to work while using

  • HAL_StatusTypeDef HAL_CRYP_Init(CRYP_HandleTypeDef *hcryp)
  • HAL_StatusTypeDef HAL_CRYPEx_AES(CRYP_HandleTypeDef *hcryp, uint8_t *pInputData, uint16_t Size, uint8_t *pOutputData, uint32_t Timeout)
  • HAL_StatusTypeDef HAL_CRYPEx_AES_Auth(CRYP_HandleTypeDef *hcryp, uint8_t *pInputData, uint64_t Size, uint8_t *pOutputData, uint32_t Timeout) (GCM only)

It would be superb if you can provide a similar API for STM32H7.

Regards, Manuel

fermentedfly avatar Aug 07 '23 09:08 fermentedfly