AES CMAC with Keystore Key Loading (Polling Mode)

This example demonstrates AES CMAC (Cipher-based Message Authentication Code) generation using the AES engine in polling mode, with the AES key securely loaded via the KEYSTORECTL keystore peripheral. The KEYSTORECTL supports both 128-bit and 256-bit AES keys. This example uses an AES-256 key stored in keystore slot 0.

Enabling Non-Main Flash Programming in CCS

Important — Prerequisite: This step must be completed before programming the device.

To program the non-main flash (which stores the BCR with cscExists = true), follow these steps in Code Composer Studio:

Step 1 — Open Project Properties

Right-click the project in the CCS Project Explorer and select Properties.

Open Project Properties

Step 2 — Navigate to Debug Settings

In the Properties dialog, navigate to Debug.

Navigate to Debug

Step 3 — Open Flash Settings

Under Debug, select Flash Settings.

Flash Settings

Step 4 — Enable Non-Main Flash Programming

Check the option to enable non-main flash programming, then click Apply and Close. Rebuild and flash the application.

Enable Non-Main Flash

Step 5 — Enable cscExists in SysConfig

Open the SysConfig file for the project and set nonmain.cscExists = true

Enable cscExists in SysConfig

Background: The AM13E2X Multi Stage Boot Flow

The AM13E2X uses a two-stage boot sequence controlled by the Boot Configuration Record (BCR) stored in non-main flash.

Phase 1 — ROM Boot Phase

The ROM boots the device based on the CSC configuration stored in non-main flash (BCR). When cscExists = true is set in the BCR, the ROM jumps to the CSC application instead of the main application. The CSC phase then runs before launching the main application. During this phase:

  • The device is in a secure operating state — keystore writes are permitted.

  • The SECSTATUS.INITDONE bit is not yet set.

Note : This bit denotes that the elevated priviledges of the application is not available. When the CSC Boot is disabled, the bit is set by ROM during the reset

  • The application code running in this phase is the CSC (this example acts as its own CSC).

  • The CSC must:

    1. Configure the keystore (set number of 256-bit key slots).

    2. Write the AES key into the keystore.

    3. Issue INITDONE to signal that secure initialization is complete.

Enabling CSC Mode

In SysConfig, set nonmain.cscExists = true. This writes the CSC-exists flag into the BCR in non-main flash. Without this, the device issues INITDONE automatically before main() runs, closing the keystore write window.

Important: Modifying non-main flash carries risks related to changing certain device configurations. Set the nonmain.nonmainWarning = true flag in SysConfig to acknowledge this before programming non-main flash.

Boot Flow Diagram

The complete boot flow — including the one-time non-main flash programming step, the CSC phase (first boot), and the main application phase (second boot) — is shown below:

AM13E2X Keystore Boot Flow

Key Loading via Keystore

Instead of writing the AES key directly into the AES engine registers, this example uses the KEYSTORECTL peripheral to manage the key securely:

1. Write Key to Keystore (DL_KEYSTORECTL_writeKey)

  • Called once during the CSC phase (first boot only).

  • Supports both 128-bit and 256-bit AES keys:

    • 128-bit key: occupies one 128-bit slot (e.g. slot 2)

    • 256-bit key: occupies two consecutive 128-bit slots (e.g. slots 0+1)

  • Keys are not readable in AES Regs as well as KeyStore Regs.

  • This example writes an AES-256 key into keystore slot 0 (occupies hardware slots 0 and 1).

  • The keystore is write-once per boot — a full BOOTRST is required to re-initialize.

  • After INITDONE is issued, the keystore write window is permanently closed for this boot.

2. Transfer Key to AES Engine (DL_KEYSTORECTL_transferKey)

  • Called before each AES operation (subkey generation, CMAC tag generation).

  • Transfers the key from keystore slot 0 into the AES engine hardware registers.

  • DL_AES_setKeySize() must be called before the transfer so the AES engine knows the key width.

  • The raw key material is never exposed in software after the initial write — it moves directly from keystore hardware to AES engine hardware.


External Connections

None