SLAA547C July 2013 – July 2021 MSP430FR5739
The following code example shows an example of a data hash using SHA-256.
#include "msp430xxxx.h"
#include "TI_SHA2.h"
uint32_t M[32]; //Message array to be hashed
uint64_t L = 0x0000000000000000; //Bit Length of message to be hashed
uint32_t Ha[8]; // Hash Array to be used during calculation and to store result
int main( void )
{
M[0] =0x41424344; //Data
M[1] =0x45464748; //Data
M[2] =0x494A4B4C; //Data
L = 0x0000000000000060 //Length == 96 bits or 0x60 bits
SHA_256(M, L, Ha, 1); // "1" indicates SHA-256 mode
return 0;
}
Although this example does not show full initialization of the array M[ ], all relevant values have been populated with meaningful data. M[ ] must be initialized to sizes equal to a 512-bit block of data or hashing block. If the message to be hashed exceeds 448 bits within a hashing block, then an additional hashing block must be reserved. Table 2-1 explains minimum sizes of M[ ] according to message size.
Message Size x (bits) | Minimum Size of Array M[ ] |
---|---|
× < 448 | M[16] |
448 ≤ × ≤ 512 | M[32] |
512 < × < 960 | M[32] |
960 ≤ × < 1024 | M[48] |