13.3.3.2 SHA API

The SHA software function can update the digest value based on the 512-bit data.

It is assumed that the message is already preprocessed properly for the SHA algorithm, so that the SHA software can work directly on 512-bit portions.

The SHA function entry point is located at the Boot ROM address 0x02001900 and has three parameters:

  • [In/out]: A pointer to a digest location (digest input and output)
  • [In]: A pointer to a 512-bit data block
  • [In]: A pointer to a RAM buffer (256B needed for internal algorithm)

The updated digest value is put at first parameter after the function exit.

The API is:

/* Type definition for CRYA SHA function. */
typedef void (*crya_sha_process_t) (uint32_t digest_in_out[8], const uint8_t data[64], uint32_t ram_buf[64]);
/* CRYA SHA function 
* \param digest_in_out[In/out]: A pointer to a digest location (digest input and output)
* \param data[In]: A pointer to a 512 bit data block
* \param ram_buf[In]: A pointer to a RAM buffer (256B needed for internal algorithm)
*/
#define crya_sha_process ((crya_sha_process_t ) (0x02001900 | 0x1))

Code example of using CRYA SHA software:

void sha256_process(uint32_t digest[8], const uint8_t data[64])
{
   uint32_t ram_buf[64]; /* 256 bytes needed for message schedule table */

   /* Pointer to CRYA SHA function in ROM */
   static void (*crya_sha_process)(uint32_t digest_in_out[8], const uint8_t data[64], 
                uint32_t ram_buf[64]);

   crya_sha_process = (void (*)(uint32_t *, const uint8_t *, uint32_t *)) 
                       *((uint32_t*)0x02001900);

   crya_sha_process (digest, data, ram_buf);
}