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.
CRYA API | Address |
---|---|
AES Encryption | 0x02006804 |
AES Decryption | 0x02006808 |
SHA256 Init | 0x02006810 |
SHA256 Update | 0x02006814 |
SHA256 Final | 0x02006818 |
SHA256 Process (legacy API) | 0x02006800 |
GCM Process | 0x0200680C |
The API is composed of the following functions which must be called in a specific order:
- SHA-256 Init to initiate a SHA256_CTX structure.
- SHA-256 Update to add a message to be computed in the digest.
- SHA-256 Final to compute the digest.
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))