SWCU185G January 2018 – June 2024 CC1312PSIP , CC1312R , CC1352P , CC1352R , CC2642R , CC2642R-Q1 , CC2652P , CC2652PSIP , CC2652R , CC2652RB , CC2652RSIP , CC2662R-Q1
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 CTRL_ALG_SEL 0x00000000
// wait until the input buffer is available for writing by the host
wait HASH_IO_BUF_STAT[2]=='1'
write HASH_MODE = 0x0000_0021 // indicate the start of a new hash session and SHA-512
write HASH_LENGTH_L // the length may be written at any time during session;
write HASH_LENGTH_H // the length must be written when last data has been written
// first block: write and hand-off the block of data
write HASH_DATA_IN_0
...
write HASH_DATA_IN_31
write HASH_IO_BUF_CTRL[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 HASH_IO_BUF_STAT[2]=='1'
// write the intermediate block and hand off the data
write HASH_DATA_IN_0
...
write HASH_DATA_IN_31
write HASH_IO_BUF_CTRL[6:0]= 0x02 // indicate that a block of data is available
if more than one input block, go to loop
endloop
wait HASH_IO_BUF_STAT[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 HASH_DATA_IN_0
...
write HASH_DATA_IN_31
// if an intermediate digest is required (input data is hash block size aligned)
write HASH_IO_BUF_CTRL[6:0]= 0x42 // indicate that data is available and get the
// intermediate digest (no internal padding)
// else if final digest is required (input data padded by hash engine)
write HASH_IO_BUF_CTRL[6:0]= 0x22 // indicate that data is available and get the final
// digest of the padded data
// wait until output data ready
wait HASH_IO_BUF_STAT[0] == '1'
// read digest
read HASH_DIGEST_A
...
read HASH_DIGEST_P
write HASH_IO_BUF_CTRL = 0x01 // acknowledge that the digest is read
// eng of algorithm