PSoC64 Secure Boot Utilities Middleware Library 1.0
Functions

General Description

Functions

cy_p64_error_codes_t cy_p64_get_provisioning_details (uint32_t id, char **ptr, uint32_t *len)
 Reads the provisioning packet (JWT), policy templates or public keys strings in the JSON format. More...
 
cy_p64_error_codes_t cy_p64_access_port_control (cy_p64_ap_name_t ap, cy_p64_ap_control_t control)
 Allows the user to control DAP access during run-time. More...
 
cy_p64_error_codes_t cy_p64_acquire_response (void)
 Call this function only when TEST_MODE bit is set in the SRSS_TST_MODE register, use CY_P64_IS_TEST_MODE_SET() macro to check. More...
 
CY_RAMFUNC_BEGIN CY_NOINLINE void cy_p64_acquire_test_bit_loop (void)
 This function should be called after cy_p64_acquire_response(). More...
 
CY_RAMFUNC_END cy_p64_error_codes_t cy_p64_get_rollback_counter (uint32_t number, uint32_t *value)
 This function reads the rollback counter. More...
 
cy_p64_error_codes_t cy_p64_update_rollback_counter (uint32_t number, uint32_t value)
 Updates the rollback counter to a higher value only. More...
 
cy_p64_error_codes_t cy_p64_attestation (uint32_t sign_alg, uint32_t rnd, uint32_t mem_count, const uint32_t *mem_start_addr, const uint32_t *mem_sizes, const uint32_t *hash_addr, uint32_t hash_size, uint32_t *rnd_out, uint32_t *mem_hash_size, uint32_t *sign_size, uint32_t *sign_addr)
 Calculates hashes of memory regions provided in an input array. More...
 

Function Documentation

◆ cy_p64_get_provisioning_details()

cy_p64_error_codes_t cy_p64_get_provisioning_details ( uint32_t  id,
char **  ptr,
uint32_t *  len 
)

Reads the provisioning packet (JWT), policy templates or public keys strings in the JSON format.

Parameters
[in]idItem id (provisioning packet, templates or public keys):
  • 0 to 32 - Key slot in SFB Mbed Crypto Key Storage
  • 0x100 - CY_P64_POLICY_JWT
  • 0x101 - CY_P64_POLICY_TEMPL_BOOT
  • 0x102 - CY_P64_POLICY_TEMPL_DEBUG
  • 0x2xx - CY_P64_POLICY_CERTIFICATE, where xx is a certificate index in the "chain_of_trust" array of the provisioned packet. Note that when the function is called with this parameter it allocates buffer for the certificate. the buffer is free/reused on the following call for read certificate. To free the buffer explicitly call this function again with ptr=NULL and len=NULL.
  • 0x300 - CY_P64_POLICY_IMG_CERTIFICATE
[out]ptrThe pointer to the response string. Can be NULL to read 'len' only.
[out]lenThe length of the response string.
Returns
CY_P64_SUCCESS for success or error code

◆ cy_p64_access_port_control()

cy_p64_error_codes_t cy_p64_access_port_control ( cy_p64_ap_name_t  ap,
cy_p64_ap_control_t  control 
)

Allows the user to control DAP access during run-time.

It works only when particular Debug Access Port has permission set to "allowed" and control field is set to "open" in Debug policy.

Parameters
[in]apAccess port name
[in]controlControl value.
Returns
CY_P64_SUCCESS for success or error code

◆ cy_p64_acquire_response()

cy_p64_error_codes_t cy_p64_acquire_response ( void  )

Call this function only when TEST_MODE bit is set in the SRSS_TST_MODE register, use CY_P64_IS_TEST_MODE_SET() macro to check.

It sends acquire response, i.e. sets a magic number in the protected RAM by calling a syscall. The code after this function should wait until TEST_MODE is cleared by the debugger, call cy_p64_acquire_test_bit_loop(). Acquire procedure is described in PSoC 64 Programming Specification 002-31353 rev** section 5.3.

Returns
CY_P64_SUCCESS for success or error code

◆ cy_p64_acquire_test_bit_loop()

CY_RAMFUNC_BEGIN CY_NOINLINE void cy_p64_acquire_test_bit_loop ( void  )

This function should be called after cy_p64_acquire_response().

It is executed from SRAM and waits until TEST_MODE bit is cleared in the SRSS_TST_MODE register by the debugger. The acquire procedure is described in PSoC 64 Programming Specification 002-31353 rev** section 5.3.

◆ cy_p64_get_rollback_counter()

CY_RAMFUNC_END cy_p64_error_codes_t cy_p64_get_rollback_counter ( uint32_t  number,
uint32_t *  value 
)

This function reads the rollback counter.

Parameters
[in]numberRollback counter number (0-15).
[out]*valueThe pointer to the read value.
Returns
CY_P64_SUCCESS for success or error code

◆ cy_p64_update_rollback_counter()

cy_p64_error_codes_t cy_p64_update_rollback_counter ( uint32_t  number,
uint32_t  value 
)

Updates the rollback counter to a higher value only.

This syscall is used by Bootloader to prevent firmware reversion during firmware update.

Parameters
[in]numberRollback counter number (0-15).
[in]valueA new value.
Returns
CY_P64_SUCCESS for success or error code

◆ cy_p64_attestation()

cy_p64_error_codes_t cy_p64_attestation ( uint32_t  sign_alg,
uint32_t  rnd,
uint32_t  mem_count,
const uint32_t *  mem_start_addr,
const uint32_t *  mem_sizes,
const uint32_t *  hash_addr,
uint32_t  hash_size,
uint32_t *  rnd_out,
uint32_t *  mem_hash_size,
uint32_t *  sign_size,
uint32_t *  sign_addr 
)

Calculates hashes of memory regions provided in an input array.

Calculates the signature of a certificate that attests the device state at the moment of signing. Signature is calculated for the following data structure:

  • Server random number (uint32_t)
  • Syscall random number (uint32_t)
  • Device UID (SFLASH->DIE_LOT array, 11 bytes)
  • Device Identity (cy_flashDeviceKeyData array, 512 bytes)
  • OEM Public key and Product ID (cy_flashProvKeyData array, 512 bytes)
  • Chain of trust (cy_flashChainOfTrust array, 5 kbytes)
  • Image certificate (cy_flashImgCertJWT array, 1 kbytes)
  • Policy package (cy_flashProvisionJWT array, 10 kbytes)
  • Number of memory regions (uint32_t)
  • for (each memory region):
    • Memory region address (uint32_t)
    • Memory region size (uint32_t)
    • Memory region content (uint8_t array)
    • Memory region hash (calculated with the syscall random number at the beginning) (uint8_t array)

The signature is calculated without any additional padding / aligning between different certificate fields. Memory regions can be from SRAM, Flash, WFlash, SFlash. SMIF and peripheral address space is not supported. AttestationSysCall algorithm: Generate syscall random number. Init signature hash calculation. Update signature hash with Server/Syscall random numbers, DevUID, Dev public key, policy package. Update signature hash with Number of regions. Check whether the array with memory regions has at least read access allowed for the caller (to avoid side channel attacks) for (each specified memory region) { Start region hash calculation with the syscall random number. Update signature and region hash with a region content (in parallel using the same data). Update signature hash with the region hash. Verify writing rights of the caller and sufficient memory size. Output the region hash to corresponding memory. } Signs the signature hash with a device private key. Clears Crypto Block internal memories and used stack.

An example of real life usage: There is a server which knows information about all connected devices in the field, their IDs, Public keys, available versions of FW. The server wants to know exact state of one of the devices - whether it is hacked or not, which FW versions it has, which configuration. The server sends a request to the device and asks to send back a signed certificate with hashes and content of specific memory regions. The application (through SPM service) calls the SysCall which calculates hashes of the specified regions and create a signature of a data certificate with specific structure. SPM code creates a package with all needed data, includes their calculated hashes and signature, and returns it to Application. Application sends it back to server.

This syscall is not available for PSoC64_512K device

Parameters
[in]sign_algPSA signing algorithm (contains hash algorithm type used both for signature and memory region hashes). Only PSA_ALG_ECDSA(PSA_ALG_SHA_256) is allowed at the moment
[in]rndA random number from server
[in]mem_countThe number of memory regions in the array.
[in]mem_start_addrThe pointer to array of memory region start addresses
[in]mem_sizesThe pointer to array of memory region sizes
[in]hash_addrThe pointer to array for hashes of the memory regions
[in]hash_sizeThe size in bytes of the array for hashes
[out]rnd_outA random number from syscall.
[out]mem_hash_sizeThe size in bytes of each memory region Hash.
[out]sign_sizeThe size in bytes of the signature.
[out]sign_addrThe address where the signature is stored.
Returns
CY_P64_SUCCESS for success or error code