cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U5 HASH

aes2
Associate II

Post edited by a ST moderator to be inline with the community rules especially on the code sharing. In next time please use </> button to paste your code.

Hi

I am struggling getting context save restore working correctly, when operating the HASH hardware block using polling mode.

Basicly the flow is like this:

/* --- STEP 1: Start hashing first chunk --- */
HAL_HASHEx_SHA256_Start(&hhash, input1,strlen((char*)input1), digest,HAL_MAX_DELAY);

/* --- STEP 2: Save context --- */
HAL_HASH_ContextSaving(&hhash, context);

/* --- STEP 3: Restore context --- */
HAL_HASH_ContextRestoring(&hhash, context);

/* --- STEP 4: Continue hashing --- */
HAL_HASHEx_SHA256_Accumulate(&hhash, input2, strlen((char*)input2)); 

/* --- STEP 5: Finalize hash --- */
status = HAL_HASHEx_SHA256_Finish(&hhash, digest, HAL_MAX_DELAY);


However when calling HAL_HASH_ContextSaving the DINIS is not equal to 1 and CSRx registers return zeros as stated in the reference manual

How do it get the HW block in a state where i can do context swap when using polling mode.

Does any working example code for this use case exist ?

Best regards
Anders

1 REPLY 1
Jocelyn RICARD
ST Employee

Hello @aes2 ,

On STM32H5 HASH, there is a 17-word long FIFO that needs to be filled-up before the hashing process actually starts. 17 words, that means one block plus one additional 32-bit word
(please refer to RM0456, HASH chapter section 4.4 Message data feeding).

Only when the 17 words are written, then the flag DINIS goes to 1 and only then it is possible to save the HASH_CSR registers.

Here is a code extract I could find internally that may help

   if (HAL_HASH_Init(&hhash2)!= HAL_OK)
   {
	   Error_Handler();
   }

   /* The line below will trigger an automatic suspension as soon the first block is processed
          and suspension conditions satisfied */
   HAL_HASH_SwFeed_ProcessSuspend(&hhash2);
   HAL_HASHEx_SHA256_Accmlt(&hhash2, (uint8_t *)sha256_tv_2, sizeof(sha256_tv_2));
   if (HAL_HASH_GetState(&hhash2) != HAL_HASH_STATE_SUSPENDED)
   {
	   Error_Handler();
   }
   HAL_HASH_ContextSaving(&hhash2, periph_status2);

   /* Process sha256_tv_1 */
   if (HAL_HASH_Init(&hhash1)!= HAL_OK)
   {
	   Error_Handler();
   }
   HAL_HASHEx_SHA256_Accmlt(&hhash1, (uint8_t *)sha256_tv_1, 12);
   HAL_HASHEx_SHA256_Accmlt_End(&hhash1, (uint8_t *)&sha256_tv_1[12], sizeof(sha256_tv_1) - 12, comp_digest_1, 0xffffffff);


   /* Resume sha256_tv_2 processing */
   HAL_HASH_ContextRestoring(&hhash2, periph_status2);
   HAL_HASHEx_SHA256_Accmlt_End(&hhash2, (uint8_t *)&sha256_tv_2[64], sizeof(sha256_tv_2) - 64, comp_digest_2, 0xffffffff);

 

Best regards

Jocelyn