2.3 Usage of SHA-256 APIs from Boot ROM

The cryptographic accelerator (CRYA) APIs are located in a dedicated Boot ROM area. This area is execute-only, meaning the CPU cannot do any loads but can call the APIs. The Boot ROM memory space is a secure area, only the secure application can directly call these APIs.

Table 2-1. CRYA APIs Addresses
CRYA APIAddress
AES Encryption0x02006804
AES Decryption0x02006808
SHA256 Init0x02006810
SHA256 Update0x02006814
SHA256 Final0x02006818
SHA256 Process (legacy API)0x02006800
GCM Process0x0200680C

The API is composed of the following functions which must be called in a specific order:

  1. SHA-256 Init to initiate a SHA256_CTX structure.
  2. SHA-256 Update to add a message to be computed in the digest.
  3. SHA-256 Final to compute the digest.
Note: SHA-256 Update can be called several times in the case several messages are to be included in the digest computation.

The SHA-256 structure to define is called SHA56_CTX:

typedef struct 
{
    /* Digest result of SHA256 */
    uint32_t digest[8];
    /* Length of the message */
    uint64_t length;
    /* Holds the size of the remaining part of data */
    uint32_t remain_size;
    /* Buffer of remaining part of data (512 bits data block) */
    uint8_t remain_ram[64];
    /* RAM buffer of 256 bytes used by crya_sha_process */
    uint32_t process_buf[64];
    
} SHA256_CTX;

The SHA-256 Init function entry point is located at the Boot ROM address 0x02006810:

typedef void (*crya_sha256_init_t) (SHA256_CTX *context);

#define crya_sha256_init ((crya_sha256_init_t) (0x02006810 | 0x1))

The SHA-256 Update function entry point is located at the Boot ROM address 0x02006814:

typedef void (*crya_sha256_update_t) (SHA256_CTX *context, const unsigned char *data, size_t length);

#define crya_sha256_update ((crya_sha256_update_t) (0x02006814 | 0x1))

The SHA-256 Final function entry point is located at the Boot ROM address 0x02006818:

typedef void (*crya_sha256_final_t) (SHA256_CTX *context, unsigned char output[32]);

#define crya_sha256_final ((crya_sha256_final_t) (0x02006818 | 0x1))