-
Notifications
You must be signed in to change notification settings - Fork 2
[ Example ] Secure data storage counter access
The STSAFE-A120 is a secure element designed to provide robust data storage and counter management capabilities. In this example, you will learn how to:
- Retrieve the total number of data partitions configured on the STSAFE-A120 device.
- Access detailed information about each partition, including counter support, data segment size, and access control policies.
- Read the value and associated data from a specific counter zone (zone 5).
- Update (decrement) the counter in zone 5, demonstrating secure usage tracking.
These operations are essential for applications requiring secure monitoring of consumable usage, lifecycle management, or tamper-resistant counters.
Note: The zone IDs referenced in this example correspond to the STSAFE-A120 SPL05 personalization. If your device is personalized differently, you must adapt the access parameters accordingly.
The following flowchart illustrates the main steps of the example application, from initialization to secure counter access and update:
The following STSAFE-A120 APIs are used in this example:
-
stse_init: Initializes the STSAFE-A120 device and prepares it for data storage operations. -
stse_dat_storage_read_counter: Reads the current value and associated data from a specified counter zone. -
stse_data_storage_decrement_counter: Securely decrements the counter in a specified zone and updates the associated data.
When the example is executed, the host computer terminal displays detailed logs that reflect each step of the process, including partition configuration, counter reads, and updates. Below is a sample output:
----------------------------------------------------------------------------------------------------------------
- STSAFE-A120 secure data storage counter access example -
----------------------------------------------------------------------------------------------------------------
-
- Description:
- This example illustrates how to leverage the STSAFE-A120 data storage APIs to perform secure operations on
- the device, including querying partition information and managing counter zones.
- o Query STSAFE-A total partition count
- o Query STSAFE-A partitions information
- o Read STSAFE-A counter zone 5
- o Update STSAFE-A counter zone 5
-
- Note: Zone IDs used in this example are aligned with STSAFE-A120 SPL05 personalization.
- Access parameters must be adapted for other device personalization.
-
----------------------------------------------------------------------------------------------------------------
- Initialize peripheral STSAFE:
- stse_get_data_partitions_configuration
ID | COUNTER | DATA SEGMENT SIZE | READ AC CR | READ AC | UPDATE AC CR | UPDATE AC | COUNTER VAL
000 | x | 1000 | DENIED | ALWAYS | ALLOWED | NEVER | 000000
001 | x | 0700 | DENIED | ALWAYS | ALLOWED | ALWAYS | 000000
002 | x | 0600 | DENIED | ALWAYS | ALLOWED | ALWAYS | 000000
003 | x | 0600 | DENIED | ALWAYS | ALLOWED | ALWAYS | 000000
004 | x | 1696 | DENIED | ALWAYS | ALLOWED | ALWAYS | 000000
005 | - | 0064 | DENIED | ALWAYS | ALLOWED | ALWAYS | 499990
006 | - | 0064 | DENIED | ALWAYS | ALLOWED | ALWAYS | 500000
007 | x | 1578 | DENIED | ALWAYS | ALLOWED | ALWAYS | 000000
- stsafe_data_storage_read_zone (zone: 05; length: 16)
o Associated Data:
0x7D 0x32 0x09 0x10 0x6F 0x65 0x31 0x3A 0x34 0xDF 0xBF 0xF3 0x38 0x36 0xCE 0xE8
o Counter Value: 499990
- stsafe_data_storage_read_zone (zone: 05; length: 16)
o New Associated Data:
0x8B 0x6E 0xD2 0xB4 0x96 0xCC 0x5B 0xDB 0xE9 0x37 0xED 0x86 0x42 0xEB 0xD2 0x89
o New Counter Value: 499989
- stsafe_data_storage_read_zone (zone: 05; length: 16)
o Associated Data:
0x8B 0x6E 0xD2 0xB4 0x96 0xCC 0x5B 0xDB 0xE9 0x37 0xED 0x86 0x42 0xEB 0xD2 0x89
o Counter Value: 499989
The secure counter and data storage features demonstrated in this example are ideal for:
- Accessory/Consumable Usage Monitoring: Track the usage of replaceable components or consumables in a secure, tamper-resistant manner.
- Accessory/Consumable Life/Cycle Management: Monitor and enforce lifecycle policies for accessories, ensuring compliance and safety.
By following this example, developers can implement robust, secure usage tracking and data partition management in their own STSAFE-A120-based solutions.
- STSAFE-A120 Secure Element
- STSAFE-A110 Secure Element
- Feature Description
- Standard Use-cases
- Product Perso Profile
- STSAFE-A120 : X-NUCLEO-ESE01A1
- STSAFE-A110 : X-NUCLEO-SAFEA1
- Software Package Architecture
- Getting Started with Software Package
-
Project examples list
- Project template
- Echo loop
- Random number generation
- NIST P-256 key pair generation
- NIST P-512 key pair generation
- BRAINPOOL P-512 Key Pair Generation
- Edwards-25519 Key Pair Generation
- Secure Data Storage Zone Access
- Secure data storage counter access
- Hash
- Device authentication
- Multi-step device authentication
- Host key provisioning
- Host key provisioning (Wrapped)
- Command Access Condition provisioning
- Secret or key wrapping
- ECDH
- Symmetric key provisioning Control Fields
- Symmetric key establishment AES-128 CMAC
- Symmetric key establishment AES-256 CCM
- Symmetric Key Management AES-128 CMAC
- Symmetric Key Management AES-256 CCM
- Wrapped Symmetric Key Provisioning - AES-128 CMAC
- Wrapped Symmetric Key Provisioning - AES-256 CCM*