SWCU194 March 2023 CC1314R10 , CC1354P10 , CC1354R10 , CC2674P10 , CC2674R10
The following software example in pseudocode describes the actions that are typically executed by the host software. The example starts the Hash engine with a new hash session that receives the input data through the slave interface. In the end, the intermediate digest (nonfinal hash operation) or the finalized hash digest (final hash operation) is read as a result digest through the slave interface.
// disable the DMA path
write ALGSEL 0x00000000
// wait until the input buffer is available for writing by the Host
wait HASHIOBUFCTRL[2] == '1'
write HASHMODE = 0x00000020 // indicate the start of the resumed hash session and SHA256
// write initial digest
write HASHDIGESTA
...
write HASHDIGESTP
write HASHINLENL // the length may be written at any time during session
write HASHINLENH // the length must be written when last data has been written
// first block: write and hand-off the block of data
write HASHDATAIN0
...
write HASHDATAIN31
write HASHIOBUFCTRL[6:0] = 0x02 // indicate that a block of data is available
loop: // intermediate blocks // wait until the input buffer available for writing by Host
wait HASHIOBUFCTRL[2] == '1'
// write the intermediate block and hand off the data
write HASHDATAIN0
...
write HASHDATAIN31
write HASHIOBUFCTRL[6:0] = 0x02 // indicate that a block of data is available if more
// than one input block, go to loop
endloop
wait HASHIOBUFCTRL[2] == '1'
// write the last block and hand-off the data
// Note: if last block is misaligned, the last 32-bit word must be padded (any data is accepted)
write HASHDATAIN0
...
write HASHDATAIN31
// if an intermediate digest is required (input data is hash block size aligned)
write HASHIOBUFCTRL[6:0] = 0x42 // indicate that data is available and
// get the intermediate digest
// else if final digest is required (input data padded by hash engine)
write HASHIOBUFCTRL[6:0] = 0x22 // indicate that data is available and
// get the final digest of the padded data
// wait until output data ready
wait HASHIOBUFCTRL[2] == '1'
// read digest
read HASHDIGESTA
...
read HASHDIGESTP
write HASHIOBUFCTRL = 0x01 // acknowledge reading of the digest
// end of algorithm