1. Short description
This wiki explains how the CCB mechanism securely wraps an ECDSA private key, stores it as a protected blob, and later reuses it for signing and verification on the STM32H5F5J.
2. Literature
- RM0517- STM32H5Ex/Fx Reference Manual: chapter dedicated to the Coupling and Chaining Bridge (CCB)
- UM2237 STM32CubeProgrammer software description
- AN5054 Secure programming using STM32CubeProgrammer
- AN2606 STM32 microcontroller system memory boot mode
- AN6205 Introduction to the use of PKA Key wrapping
- AN6278
- Start by reading the introduction article CCB KW ECDSA Signature How to Introduction and Security:CCB-ECDSA signature STM32H5F5J how to intro - stm32mcu
3. Introduction
This document explains how to get started with CCB on the STM32H5F5J using an example of key-wrapped ECDSA signatures. The workflow shows how a private key provided by the CPU is imported through PSA Crypto, converted into a protected blob, stored securely, and later reused for ECDSA signing and verification.
- CCB: Coupling and Chaining Bridge
- CCOP: Coupling and Chaining Operation
- OPSTEP: Operation Step
- PSA: Platform Security Architecture
- SAES: Secure AES Engine
- PKA: Public Key Accelerator
- RNG: Random Number Generator
4. Overview of the Hardware and Software Environment
4.1. Hardware
Board: STM32H5F5J-DK (MB2114)
The example requires a device supporting hardware cryptographic accelerators: CCB, PKA, SAES, and RNG
4.2. Software
- Firmware: STM32Cube_FW_H5_V1.6.0 or later
- IDE: IAR Embedded Workbench for Arm v9.20.1 or later, with the STM32H5Ex-Fx patch. The patch is available in
STM32Cube_FW_H5_Vx.x.x\Utilities\PC_Software\IDEs_Patches. This getting-started guide uses IAR, but other IDEs are also supported. - Debug probe/setup: As required by the board.
- Recommendation: Keep the STM32Cube firmware directory close to
C:\to avoid Windows path-length issues.
4.3. Environment setup
- Download and install the STM32CubeH5 package.
- Open the following project directory:
STM32Cube_FW_H5_V1.6.0\Projects\STM32H5F5J-DK\Applications\MbedTLS_HW_KWE - Select the
ECC_ECDSA_Sign_KWEexample.
5. Setup of the ECC_ECDSA_Sign_KWE application example
- Open the ECC_ECDSA_Sign_KWE example.
- Verify the device selection in the IDE (as shown in the figure2).
- Set the compilation switch for the target device.
- Set optimization to none to allow reliable single stepping
- Set the ST-LINK debug settings according to the following figures, if applicable.
- Compile the project.
- Connect the board and start the debug session.
6. Example overview
This example performs a digital signature using a wrapped (encrypted) private key. It demonstrates a secure signing workflow in which the private key is not exposed as plaintext after import. The CPU provides the key material to the PSA layer, which wraps it into a blob. The blob is then retrieved and used for ECDSA signing.
6.1. Main objectives
- Import a private key provided by the CPU.
- Wrap the key in a protected blob.
- Store the blob securely in non-volatile memory.
- Use the blob to generate an ECDSA signature.
- Verify the signature.
6.2. High-level architecture
The example relies on the following functional blocks:
- CPU: Provides the plaintext key material.
- PSA Crypto: Manages key objects and cryptographic operations.
- CCB: Controls the secure execution flow.
- SAES: Supports secure chaining and GCM-based protection.
- PKA: Performs the ECDSA computation.
- RNG: Generates the random nonce required for ECDSA.
- Non-volatile memory: Stores the wrapped blob for later reuse.
6.3. Simplified data flow
- The CPU provides the key material.
psa_import_key()creates a wrapped blob.- The blob is stored securely.
- The message is hashed.
- The blob is used to generate an ECDSA signature
6.4. Expected result
The example is successful if:
- The blob is created correctly.
- The message is signed successfully.
- The generated signature is verified successfully.
- The protected execution sequence completes without error.
7. Execution of ECDSA application example
The following section describes the complete workflow and the steps required to create, securely store, and later reuse the wrapped ECDSA key blob. It then presents the main.c file and explains its contents in detail.
7.1. Private and public keys declaration
Private key
The private key is defined in main.c for demonstration purposes only. In a real product, the private key should not be stored in plaintext in flash or duplicated in RAM.
This example demonstrates how to import the key once, wrap it into a protected blob, and then erase the plaintext key material.
Public key declaration
The public key is also defined as a constant in main.c. It contains the X and Y coordinates of the elliptic-curve public point.
The first byte, 0x04, indicates that the public key is an uncompressed point containing the X and Y coordinates on a Weierstrass elliptic curve.
The public key is later used to verify the generated ECDSA signature.
7.2. Blob creation and persistence
This step creates a protected ECDSA key blob from the plaintext private key provided by the CPU. The blob can be stored persistently and reused for future signing operations while keeping the secret key material protected.
In this example, the plaintext private key is used only to demonstrate the wrapping process. The recommended end state is to retain the wrapped blob as the long-term protected asset and erase the plaintext key material after wrapping.
The following sections explain how this process is performed in the example.
7.3. CPU key provisioning
The process begins when the CPU provides the private key material to the PSA API. In this example, the private key is provided in plaintext for demonstration purposes only. This approach is not recommended for production use.
7.3.1. Key handle and attributes
After HAL initialization, clock configuration, and BSP setup, the ECDSA configuration is defined in main.c using the key_attributes structure. This structure specifies the key’s cryptographic policy, usage constraints, lifetime, and location.
In this example, the attributes authorize hash signing, select ECDSA with SHA-224, assign the key to the STM32 Key Wrap Engine, and set a persistent key identifier for later reuse.
7.3.2. Key policy
PSA_KEY_USAGE_SIGN_HASHauthorizes the key to sign hashes.PSA_ALG_ECDSA(PSA_ALG_SHA_224)selects ECDSA with SHA-224 as the hash algorithm.PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1)defines an elliptic-curve key pair using thesecp_r1curve family.- The 256-bit private key corresponds to the
secp256r1curve. PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(PSA_KEY_PERSISTENCE_DEFAULT, PSA_CRYPTO_KWE_DRIVER_LOCATION)configures the key as persistent and assigns it to the STM32 Key Wrap Engine location.PSA_ECC_KEY_ID_USERspecifies the persistent key identifier.
This configuration prepares the private key for secure import, wrapping, storage, and subsequent ECDSA signing.
When the private key is imported, key_handle_private stores the handle returned by PSA Crypto. The variable is stored in SRAM.
In the debugger, key_handle_private is located at 0x2000A438 in this example. This address may vary between runs. To find the address in your run, add key_handle_private to the watch list and inspect its address in the debugger.
7.4. Blob generation with psa_import_key().
psa_import_key() imports the plaintext private key and creates a protected blob. The wrapping process protects the key when it is stored outside the application domain. The original plaintext key remains in the input buffer until the application securely erases it.
During key import, psa_import_key() initiates the secure blob creation sequence. In this example, CCOP = 0xC0 corresponds to creating an ECDSA signing-key blob from the private key provided by the CPU.
7.4.1. Recommended breakpoint strategy
- Open
\STM32Cube_FW_H5_V1.6.0\Drivers\STM32H5xx_HAL_Driver\Src\stm32h5xx_hal_ccb.c. - Find the
CCB_ECDSA_SignBlobCreation()function to observe the progress of the internal secure sequence. - For a clean debugging session, set breakpoints at the locations listed in Table 1. These breakpoints correspond to the following stages:
- Start of secure initialization
- After IV generation
- After loading the ECDSA parameters
- After writing the private key, d
- Start of the PKA-to-SAES transfer
- GCM finalization and tag generation
- Cleanup and reset
7.4.2. Debug Procedure
- Use
OPSTEPto identify the current execution stage.- Monitor the RNG during IV generation.
- Monitor the PKA during ECDSA parameter loading and private-key handling.
- Monitor the SAES during GCM setup, encrypted data transfer, and tag generation. Open the Registers 1, Registers 2, Registers 3, and Registers 4 windows. In these windows, display the CCB, SAES, PKA, and RNG register groups. Monitor the CCB registers to observe the
CCOPbits and theOPSTEPfield. Pay particular attention to the PKA and SAES registers, which reflect the progress of the secure processing sequence. Run the program until it reaches the first breakpoint. Then continue execution from breakpoint to breakpoint, following the steps in Table 1. Table 1 summarizes the secure sequence in execution order, linking each breakpoint to the corresponding hardware action. The sequence can be tracked through theOPSTEPbits in theCCB_SRregister. The table also indicates the execution path and whether the operation uses coupling or chaining. For this secure operation,CCOPis set to0xC0<.
.
| OPSTEP | Breakpoint in CCB_ECDSA_SignBlobCreation() function | Main action | PATH | Coupling / chaining |
|---|---|---|---|---|
| 0x1 | CCB_WaitOperStep(hccb, 0x01, HAL_CCB_TIMEOUT_DEFAULT_VALUE) | Initialize the secure hardware context | Setup | None |
| 0x2 | CCB_WaitOperStep(hccb, 0x02, HAL_CCB_TIMEOUT_DEFAULT_VALUE) | Generate IV through RNG and prepare GCM in SAES | RNG → SAES | Chaining |
| 0x3 | CCB_WaitOperStep(hccb, 0x03, HAL_CCB_TIMEOUT_DEFAULT_VALUE) | Load ECDSA parameters into PKA and SAES | CPU → PKA + SAES | Coupling |
| 0x4 | CCB_WaitOperStep(hccb, 0x04, HAL_CCB_TIMEOUT_DEFAULT_VALUE) | Write private key `d` into protected PKA RAM | CPU → PKA | Coupling |
| 0x8 | CCB_WaitOperStep(hccb, 0x08, HAL_CCB_TIMEOUT_DEFAULT_VALUE) | Transfer and encrypt private key through SAES | PKA → SAES | Chaining |
| 0xA | CCB_WaitOperStep(hccb, 0x0A, HAL_CCB_TIMEOUT_DEFAULT_VALUE) | Finalize GCM and generate the reference tag | SAES → CCB | Chaining |
| 0x0 | CLEAR_BIT(hccb->Instance->CR, CCB_CR_IPRST); hccb->State = HAL_CCB_STATE_READY; | Reset and end the sequence | Cleanup | None |
During ECDSA blob creation, Figures 6a and 6b illustrate the protected sequence executed by the CCB and the corresponding PKA, SAES, and RNG register states.
Figure 6a shows the CCB register group. CCB_CR should indicate CCOP = 0xC0, and CCB_SR should be monitored to track the current OPSTEP value. This is the main register to follow during the secure sequence: each OPSTEP corresponds to a specific hardware action, and progress through the protected flow is reflected in OPSTEP[4:0].
For example, when OPSTEP = 0x2, the RNG is expected to generate the IV material for AES-GCM initialization. At this stage, the RNG registers should indicate that the random number generator is enabled and ready: RNG_CR.RNGEN = 1, and RNG_SR.DRDY = 1 when random data are available.
At the same time, the SAES registers should indicate that GCM initialization is in progress. SAES_CR should be configured for AES-GCM encryption with a 256-bit key, and GCMPH = 0x1 after the initial setup. The IV registers SAES_IVR1 to SAES_IVR3 are then loaded with random values provided through the CCB/RNG path, while SAES_IVR0 remains fixed as required by the sequence. CCB_SR should show CCB_BUSY = 1 and OPSTEP = 0x2, confirming that the protected operation is still running.
Figure 6b shows the PKA, SAES, and RNG register groups to monitor during blob creation. The PKA registers confirm that the protected operation is configured in the expected mode, with PKA_CR.MODE = 0x24 for ECDSA signature blob creation. PKA_SR indicates that the accelerator is ready and progressing normally.
Check the SAES registers to verify the chaining configuration and track the GCM phase. Monitor the RNG registers to confirm that the random values required by the blob creation sequence are being generated.
7.5. Blob protection and persistence
Once created, the blob can be stored in non-volatile memory. In this form, the key remains protected and can later be retrieved for secure use.
What to observe
At each step, verify:
- The key_attributes content,
- The key_handle_private value
- The ecdsa_blob layout,
- The temporary key copy in RAM,
- The stored wrapped key in the Flash.
Rerun the code to observe in detail the needed expressions:
- Open main.c file :
- Put a breakpoint @ retval = psa_import_key(&key_attributes, Private_Key, sizeof(Private_Key), &key_handle_private);
- Add to watch the following expression to observe their location
- Key_attributes
- Private_Key and
- Key_handle_private
The figure below shows the observed addresses in the executed example.
Debug procedure for private key wrapping
Files to open and breakpoints to set for debugging
- Open the kwe_core.c and set the breakpoints
- Middlewares/ST/mbedtls_key_wrap_engine/kwe_core.c
- Search: /* Configure Wrapping Key : DHUK */
- Set two breakpoints as indicated in the figure 8 (the code line number can differ depending on the CubeFw release)
- Middlewares/ST/mbedtls_key_wrap_engine/kwe_core.c
- Open the psa_crypoto.c: Middlewares/mbedtls/psa_crypto.c
- Search: /* Key material is saved in export representation in the slot
- Set a breakpoint as indicated in the figure below (the code line number can differ depending on the Cube Firware release)
Execute the code till the first breakpoint.
The 32-byte private key is temporarily stored in embedded RAM while the blob is being created.
To inspect the copy in RAM:
- Open the Memory view.
- Right-click in the view and select Find (or press Ctrl+F).
- Enter the first word of the known private key, then select Find Next.
- Record the address of the copy. In this example, it is
0x20012B2C.
In this example, the private key is also stored in flash. To inspect it, search the flash address space. The example address is 0x080130CC
.
ECDSA_Blob is a structure containing three pointer fields, located at 0x2000A348. Each field stores the address of the corresponding data item in memory (see Figure 9).
The fields point to the initialization vector (IV), the authentication tag, and the wrapped private key. Their values are shown in Figure 10:
- IV: The initialization vector used by the AES-GCM key-wrapping mechanism. In this example, it is located at
0x2000AAC0. The first four bytes of the IV are fixed to0x2, and the remaining bytes are generated by the RNG (see Figure 11). - Tag: Used to verify the key’s authenticity during unwrapping. During key wrapping, the hardware generates a tag associated with the key and IV. During unwrapping, the hardware generates a tag for comparison with the stored tag. A match confirms the key’s authenticity. The tag is located at
0x2000AAD0. pWrappedKey: Points to the encrypted 256-bit private key, which is the same size as the original private key. It is located at0x2000AAE0.
Key point:
The DHUK is associated with the
- HDPLx security level,
- the secure or non-secure execution domain,
- and the variable context settings.
- Execute the code till the third breakpoint set previously.Step over the current line.
The wrapped key is stored in embedded flash because it is configured as persistent (see the /* Setup the key policy for the private key */ section in main.c).
To locate the wrapped key, search the memory view starting at 0x08000000. In this example, the wrapped key is located at 0x080FC034.
key point:
Once the key has been wrapped, the wrapped key can be stored in the designated memory area. The key material used during wrapping, including the private and public keys, can then be removed from RAM and, where applicable, from flash. This cleanup helps minimize the exposure of sensitive material and reduce the risk of unauthorized access or reuse.
If the wrapped key must be retained, an additional copy step may be needed to move it from the memory area managed by the mbedTLS library to another memory area. This copy can then be used for the signing operation.
If the data is no longer needed, call mbed_crypto_free() to release the associated library-managed resources. Warning: This function frees only the instance managed by the library. It does not erase other copies of the wrapped key; delete those separately.
In this example, you can inspect the wrapped key’s erasure by opening main.c, setting a breakpoint, and stepping over the relevant code. The Memory view then shows the result, as illustrated in the figure below.
8. Blob usage for signing
Before signing, the input message is hashed to produce the digest used by the ECDSA algorithm.
During signing, the wrapped blob is used instead of the plaintext private key. The blob is retrieved from protected storage and processed through the CCB-orchestrated execution flow. The SAES restores the protected context, the RNG provides the ephemeral nonce, and the PKA computes the ECDSA signature.
The following sections describe the CCB operation steps and how the CCB interacts with the SAES and PKA. They show that signing is not a standalone operation, but part of a blob-use flow orchestrated by the CCB, protected by the SAES, and executed by the PKA. CCOP = 0x0C3 identifies the protected ECDSA signing workflow.
8.1. Debug procedure for signing
- Open
stm32h5xx_hal_ccb.cand locate theHAL_CCB_ECDSA_Sign()function. - Set breakpoints at the locations indicated in the corresponding table.
- Rerun the example and continue execution until the signing phase begins.
- Step through the protected signing sequence, monitoring the
OPSTEPprogression in the CCB registers. - Continue until the signature is generated.
8.2. OPSTEP sequence for blob retrieving
The signing workflow is organized into a sequence of OPSTEP values. It begins with configuration at 0x01, where the secure context is initialized. The flow then proceeds to input preparation at 0x12 and parameter setup at 0x13, involving coupling between the CPU and the secure hardware blocks. At 0x14, the encrypted private key is transferred from the SAES to the PKA. Next, the RNG provides a random nonce to the PKA at 0x16, followed by signature computation by the PKA at 0x17. Finally, 0x1A marks the finalization stage, when the operation completes and the signature is obtained.
The table summarizes the successive OPSTEP breakpoints used by the CCB during the protected ECDSA signing flow. Each step corresponds to an operation, from secure-context setup and blob handling to private-key restoration, nonce loading, signature authorization, PKA execution, and retrieval of the final signature.
| OPSTEP | Breakpoint in CCB_ECDSA_SignBlobCreation() function | Main action | PATH | Coupling / chaining |
|---|---|---|---|---|
| 0x01 | CCB_WaitOperStep(hccb, 0x01, ...) | Initialize the secure hardware context | Setup | None |
| 0x12 | CCB_WaitOperStep(hccb, 0x12, ...) | Configure wrapping key and signing context | CPU → CCB | Coupling |
| 0x13 | CCB_WaitOperStep(hccb, 0x13, ...) | Load hash, IV, and tag | SAES → CCB | Chaining |
| 0x14 | CCB_WaitOperStep(hccb, 0x14, ...) | Restore encrypted private key | CPU → PKA + SAES / SAES → PKA | Coupling + Chaining |
| 0x16 | CCB_WaitOperStep(hccb, 0x16, ...) | Load RNG nonce `k` | RNG → PKA | Chaining |
| 0x17 | CCB_WaitOperStep(hccb, 0x17, ...) | Authorize protected signature execution | SAES → CCB | Chaining |
| 0x18 | CCB_WaitOperStep(hccb, 0x18, ...) | Finalize blob usage | CCB → PKA | Chaining |
| 0x19 | SET_BIT(PKA->CR, PKA_CR_START) then CCB_WaitOperStep(hccb, 0x19, ...) | Start PKA ECDSA computation | CCB → PKA | Chaining |
| 0x1A | CCB_WaitOperStep(hccb, 0x1A, ...) | Read signature `(r, s)` and complete operation | PKA execution | None |
| 0x0 | CLEAR_BIT(hccb->Instance->CR, CCB_CR_IPRST); | Reset CCB and restore state to READY | Cleanup | None |
8.3. Blob usage monitoring
During the ECDSA blob-usage phase, the CCB controls the execution flow, the SAES restores the protected context, the PKA performs the cryptographic operation, and the RNG provides the random nonce. According to RM0517, the ECDSA signature blob-usage sequence starts when CCOP = 0xC3 is set in CCB_CR. The OPSTEP field in CCB_SR identifies the current state-machine step and indicates the operation’s progress. Monitor the CCB_BUSY and OPERR bits to check that the operation is running and that no security or configuration errors have occurred.
In the debugger, first monitor the CCB register group, particularly:
CCB_CR, to verify thatCCOP = 0xC3is selected.CCB_SR, to track theOPSTEPprogression and monitor theCCB_BUSYandOPERR[5:0]fields.CCB_REFTAGRx, when the reference tag is loaded and checked during GCM authentication.
The second figure highlights the PKA, SAES, and RNG registers to monitor during blob usage:
- Check
PKA_CRandPKA_SRto verify that the PKA is enabled in the expected mode (MODE = 0x24) and to track theSTART,INITOK, andPROCENDFstatus bits. - Monitor
SAES_CRandSAES_ISRto check the selected GCM mode, theGCMPHprogression, and the completion of the AES-GCM phases. - Monitor
RNG_CRandRNG_SRto verify that the random number generator is initialized correctly and that random data are available when required.
These registers provide a complete view of the protected ECDSA blob usage flow and allow the user to validate each step of the chaining and coupling sequence (more details can be found in RM0517[1])
9. Signature verification
The objective is to confirm that a signature was generated for a given hash using the corresponding private key, and that the matching public key can successfully verify it.
The process follows the standard public-key cryptography model:
- Hash the message to produce a fixed-size digest.
- Use the private key to generate a digital signature for the digest.
- Import the corresponding public key.
- Verify the signature against the hash and public key.
In this example, psa_verify_hash() verifies the generated signature using the hash and the public key provided in the code. It does not hash or verify the original message directly. Successful verification confirms that the signature is valid for the given hash and was generated using the private key corresponding to the public key.
The receiver first computes the message hash, which serves as a compact representation of the message. The verification function then checks the signature against that hash and the public key. If verification succeeds, the signature is valid for the supplied hash and key. This supports message-integrity and signer-authenticity checks, provided the public key is trusted. Otherwise, verification fails and the signature is rejected.
If verification succeeds:
- Sensitive data is cleaned up.
- The green LED turns on.
- The example reports successful completion.
10. Security considerations
- After import, the private key is represented by a protected blob. Ensure that any plaintext copies are securely erased; they may otherwise remain in RAM or flash.
- The blob is stored in protected form.
- The signing flow is controlled by
CCOPandOPSTEP. - The SAES supports secure context restoration and integrity checks.
- The PKA performs the cryptographic operation without exposing the secret key material.
11. Conclusion
This example demonstrates a secure ECDSA signing workflow in which a CPU-provided key is wrapped into a protected blob. The document describes the blob’s lifecycle, from creation with psa_import_key() to protected signing and signature verification. It also explains the internal CCOP and OPSTEP execution model and the roles of coupling and chaining in coordinating the CCB, SAES, PKA, and RNG.
12. References