HAL HASH use cases

User application starting a HASH computation process in polling mode using MD5 algorithm

@startuml

hide footbox

' To add a number by line

'autonumber



' Fix order of each column

skinparam ParticipantPadding 40



participant "User Application" as part1 

participant "Driver HASH" as part2

participant "System" as part3



activate part1



group #9898fb Initializes the Flash interface and the Systick

part1->part3 : HAL_Init()

activate part3

part3 --> part1

deactivate part3

end



group #lightblue Configure the system clock

part1->part3 : SystemClock_Config()

activate part3

part3 --> part1

deactivate part3

group #lightblue Alternative 

part1->part3: HAL_RCC_HASH_EnableClock()

part3 --> part1

end

end



group #lightsalmon Initialize HASH

part1->part2 ++ : HAL_HASH_Init()

note right: Or HASH clock will be enabled when the user defines the \n USE_HAL_HASH_CLK_ENABLE_MODEL \n as HAL_CLK_ENABLE_PERIPH_ONLY

part2 --> part1

part1->part2 : HASH HW Initialisation and HASH NVIC configuration for HASH interrupts

part2 --> part1



end



group #9898fb Set HASH configuration

part1->part2 : HAL_HASH_SetConfig()

note right: The user need to select the algorithm which must be set to HAL_HASH_ALGO_MD5.

part2 --> part1

end



group #lightblue <size:15>HASH using MD5 algorithm in polling mode</size> : 

part1->part2 : HAL_HASH_Compute()

note right: Retrieve the message digest in the output buffer parameter.

part2 --> part1 : Return hal status



part1->part2 : HAL_HASH_DeInit()

end



@enduml

Functions called:

User application starting a HASH update process in polling mode using SHA1 algorithm

@startuml

hide footbox

participant "User Application" as part1

participant "HASH Driver" as part2



activate part1

activate part2



group #lightsalmon Initialize HASH

part1->part2 : HAL_HASH_Init()

part2 --> "part1"

part1->part2 : HASH HW Initialisation and HASH NVIC configuration for HASH interrupts

part2 --> part1



end



group #9898fb Set HASH configuration

"part1"->part2 : HAL_HASH_SetConfig()

note right: The user need to select the algorithm \n which must be set to HAL_HASH_ALGO_SHA1.

part2 --> "part1"

end



group #lightblue update process in polling mode

part1->part2 : HAL_HASH_Update()

part2 --> part1 : Return hal status



part1->part2 : HAL_HASH_Update()

part2 --> part1 : Return hal status

note right: The user continue feeding with N consecutive input \n buffers in polling mode using using HAL_HASH_Update API.



part1->part2 : HAL_HASH_Finish()

part2 --> part1 : Return hal status

note right: Retrieve the message digest in the output buffer.



part1->part2 : HAL_HASH_DeInit()

end

@enduml

Functions called:

User application starting a HASH Update process in IT mode using SHA256 algorithm

@startuml

hide footbox

participant "User Application" as part1

participant "HASH Driver" as part2

participant "NVIC" as part3



activate part1

activate part2



group #lightsalmon HASH initialization

part1->part2 : HAL_HASH_Init()

part2 --> part1

part1->part2 : HASH HW Initialisation and HASH NVIC configuration for HASH interrupts

part2 --> part1

end



group #9898fb HASH configuration 

part1->part2 : HAL_HASH_SetConfig()

note right: The user need to select the algorithm which \n must be set to HAL_HASH_ALGO_SHA256

part2 --> part1 : Return hal status

end

group #lightblue Update  process in IT mode

part1->part2 : HAL_HASH_Update_IT()

part2 --> part1 : Return hal status

part3 -> part2 : HAL_HASH_IRQ_HANDLER()

part2--> part1 : HAL_HASH_InputCpltCallback()



part1->part2 : HAL_HASH_Update_IT()

part2 --> part1 : Return hal status

part3 -> part2 : HAL_HASH_IRQ_HANDLER()

part2--> part1 : HAL_HASH_InputCpltCallback()

note right: The user can fed severals inputs data by calling the HAL_HASH_Update_IT.



part1->part2 : HAL_HASH_Finish()

part3 -> part2 : HAL_HASH_IRQ_HANDLER()

part2--> part1 : HAL_HASH_InputCpltCallback() \n HAL_HASH_DigestCpltCallback()

part2 --> part1 : Return hal status



part3 -> part2 : HAL_HASH_IRQ_HANDLER()

part2--> part1 : HAL_HASH_ErrorCallback()

note right: Or HASH error occured.

end 

@enduml

Functions called:

User application starting a HASH-HMAC computation process in DMA mode using SHA224 algorithm

@startuml

hide footbox

participant "User Application" as part1

participant "HASH Driver" as part2

participant "DMA Driver " as part3

participant "NVIC" as part4



activate part1

activate part2



group #lightsalmon HASH initialization

part1->part2 : HAL_HASH_Init()

part2 --> part1

part1->part2 : HASH HW Initialisation, DMA Initialization and HASH and DMA NVIC configuration.

part2 --> part1



part1->part2 : HAL_HASH_SetInDMA()

note right: Link In DMA handle to HASH handle 

end 



group #9898fb HASH configuration 

part1->part2 : HAL_HASH_HMAC_SetConfig

part2 --> part1 : Return hal status

end 



group #lightblue HMAC Computing process in DMA mode

part1->part2 : HAL_HASH_HMAC_Compute_DMA()

part2 --> part1 : Return hal status



part4 -> part3 : HAL_DMA_IRQ_HANDLER()

part3 -> part2 : DMA Transfer complete

note right: The HASH Peripheral state shall be \n in  HAL_HASH_STATE_IDLE.

part2--> part1 : HAL_HASH_InputCpltCallback() \n HAL_HASH_DigestCpltCallback()

part1->part2 : HAL_HASH_DeInit()

end

@enduml

Functions called:

User application suspending and Resuming a HASH process in IT mode

@startuml

hide footbox

participant "User Application" as part1

participant "HASH Driver" as part2

participant "DMA" as part3

participant "NVIC" as part4

activate part1

activate part2



group #lightsalmon HASH initialization

part1->part2 : HAL_HASH_Init()

part2 --> part1 : Return hal status

part1->part2 : HASH HW Initialisation and HASH NVIC configuration.

part2 --> part1

end



group #9898fb HASH configuration 

part1->part2 : HAL_HASH_SetConfig()

part2 --> part1 : Return hal status

end

group #lightblue Process 1 : Suspending IT process during an update process in IT mode

part1->part2 : HAL_HASH_Update_IT()

part1->part2 : HAL_HASH_RequestSuspendUpdate()

note right : The Update process shall be ongoing 

part4 -> part2 : HAL_HASH_IRQ_HANDLER()

part2--> part1 : HAL_HASH_SuspendCallback()

note right: HASH update suspended when an \n input buffer is entiry processed.



part1->part2 : HAL_HASH_SaveContext()

end 



group #lightblue Process 2 : HASH new process

part1->part2 : HAL_HASH_HMAC_SetConfig()

part2 --> part1 : Return hal status

note right: The configuration settings are optional. You can modify them \n if you need to change the default configuration to better suit your requirements.



part1->part2 : HAL_HASH_HMAC_Compute_DMA()

part2 --> part1 : Return hal status



part4 -> part3 : HAL_DMA_IRQ_HANDLER()

part3 -> part2 : DMA Transfer complete

note right: The HASH Peripheral state shall be \n in  HAL_HASH_STATE_IDLE.

part2--> part1 : HAL_HASH_InputCpltCallback() \n HAL_HASH_DigestCpltCallback()

part1->part2 : HAL_HASH_DeInit()



end



group #lightblue Process 1 : Resuming IT process

part1->part2 : HAL_HASH_RestoreContext()

part1->part2 : HAL_HASH_ResumeUpdate()

note right: The previous IT process is resumed.



part3--> part2 : HAL_HASH_IRQHandler()

note right: HASH Update process completed.

part2--> part1 : HAL_HASH_InputCpltCallback

part1->part2 : HAL_HASH_Update_IT()

part2 --> part1 : Return hal status

note right: The HASH peripheral feed the rest of the input buffer.

part3 -> part2 : HAL_HASH_IRQ_HANDLER()

part2--> part1 : HAL_HASH_InputCpltCallback



note right: The HASH peripheral state shall be in \n HAL_HASH_STATE_IDLE.





part1->part2 : HAL_HASH_Finish()

part3 -> part2 : HAL_HASH_IRQ_HANDLER()

note right: The HASH peripheral state shall be moved to \n HAL_HASH_STATE_IDLE.

part2--> part1 : HAL_HASH_DigestCpltCallback() \n HAL_HASH_InputCpltCallback

part2 --> part1 : Return hal status



part3 -> part2 : HAL_HASH_IRQ_HANDLER()

part2--> part1 : HAL_HASH_ErrorCallback()

note right: Or HASH error occured.



part1->part2 : HAL_HASH_DeInit()

end

@enduml

Functions called: