ZHDU116G January 2018 – June 2024 CC1312PSIP , CC1312R , CC1352P , CC1352R , CC2642R , CC2642R-Q1 , CC2652P , CC2652PSIP , CC2652R , CC2652RB , CC2652RSIP , CC2662R-Q1
以下伪代码形式的软件示例描述了主机软件通常执行的操作。该示例启动哈希引擎,新建一个哈希会话以通过从机接口接收输入数据。最后,中间摘要(非最终哈希操作)或最终确定的哈希摘要(最终哈希操作)作为结果摘要通过从机接口读取。
// 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_0020 // indicate the start of the resumed hash session and SHA256
//write initial digest
write HASH_DIGEST_A
...
write HASH_DIGEST_P
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
//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 reading of the digest
// eng of algorithm