Skip to content

refactor(core): move session keys to platform secure storage#67

Open
Grolleau-Benjamin wants to merge 2 commits intoSTMicroelectronics:mainfrom
Grolleau-Benjamin:refactor-key-management
Open

refactor(core): move session keys to platform secure storage#67
Grolleau-Benjamin wants to merge 2 commits intoSTMicroelectronics:mainfrom
Grolleau-Benjamin:refactor-key-management

Conversation

@Grolleau-Benjamin
Copy link
Copy Markdown
Contributor

Summary

Session keys are no longer kept in RAM. It is now up to the user to decide where they are stored, referencing them via a uint32_t key index.

This improves security, enables backend-agnostic key management, and allows integration with PSA and TrustZone Secure Storage.

Changes

  • Add secure session key storage via stse_platform_store_session_key
  • Session now tracks Host_MAC_key_idx and Host_cipher_key_idx
  • Wipe plaintext session keys from RAM after storage
  • Use key indices for AES ECB / CBC / CMAC operations

Security

  • Session keys no longer persist in RAM
  • Enables hardware-backed key protection

Note

STSELib remains backend-agnostic (no PSA assumption). The platform decides how keys are stored and used.

@TofMassilia13320
Copy link
Copy Markdown
Contributor

Branch is out-of-date with the base branch.
Please rebase!
Tx for your contribution.

@Grolleau-Benjamin
Copy link
Copy Markdown
Contributor Author

@TofMassilia13320
This should be fine, I’ve just rebased.

Maybe we should add a Discussions section to this repository, or create a Discord server to discuss this kind of change. It could also be useful to maintain a changelog. Your last change introduced a regression that could have been flagged through a proper changelog process (and I also introduced a huge regression in this PR).

Signed-off-by: Benjamin Grolleau <benjamin.grolleau@outlook.com>
Signed-off-by: Benjamin Grolleau <benjamin.grolleau@outlook.com>
@Grolleau-Benjamin Grolleau-Benjamin force-pushed the refactor-key-management branch from 4de1a70 to 99f3889 Compare March 5, 2026 09:16
@Grolleau-Benjamin
Copy link
Copy Markdown
Contributor Author

Hi @TofMassilia13320,

I've just rebased my branch on prepare v1.1.7.

I also discovered the release notes (doc/resources/Markdown/02_RELEASE_NOTE/release_note.md) by reviewing the commit you just added. Since it currently lists the raw commit history, I was wondering if we could switch to a more user-centric format? Grouping updates by "Added", "Changed", "Fixed", and "Breaking Changes" is usually much easier for users to digest than reading through Git commit messages.

Additionally, it might make more sense to maintain a classic CHANGELOG.md directly at the root of the repository. It's the standard location most developers and users instinctively look for, making it much easier to track the project's evolution at a glance. Furthermore, this location permit to easily add the content to the release note using GitHub CI/CD.

Let me know what your thoughts are on this!

@Grolleau-Benjamin
Copy link
Copy Markdown
Contributor Author

Looking at the commits, I also believe that @Grom- would be interested in this discussion.

@Grom-perso
Copy link
Copy Markdown

Hello @Grolleau-Benjamin , Indeed , I am interested to discuss/review with you the different needs/requirements highlighted in this PR . I will contact you via mail in the coming days.

@Grom- Grom- self-requested a review March 26, 2026 10:39
@Grom- Grom- added the enhancement New feature or request label Mar 26, 2026
Copy link
Copy Markdown
Contributor

@Grom- Grom- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Grolleau-Benjamin , I have reviewed your PR . Please do not hesitate to contact me if you want to discuss my comments .

In addition to the in-line code review . the PR commit messages are not in line with our contribution guideline . But I think being able to identify bug-fix for feature and refactor is an important point for change traceability and for release note content clarification . Please do not change them now , I will discuss this with the team and come back to you .

* \param[in] key_length Length of the keys in bytes
* \return \ref STSE_OK on success; \ref stse_ReturnCode_t error code otherwise
*/
stse_ReturnCode_t stse_platform_store_session_key(PLAT_UI8 *pCypherKey, PLAT_UI32 *pCypherKeyIdx,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to be more generic here . Something like store AES key . This would help to decorrelate this from STSAFE-A sessions context

* \param[in] MACKeyIdx Index of the MAC key to delete
* \return \ref STSE_OK on success; \ref stse_ReturnCode_t error code otherwise
*/
stse_ReturnCode_t stse_platform_delete_key(PLAT_UI32 CypherKeyIdx, PLAT_UI32 MACKeyIdx);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, I suggest to manage only one AES key (single index) . APIs will call the functions multiple times if needed

pSession->context.host.MAC_counter = ARRAY_3B_SWAP_TO_UI32(host_key_slot.cmac_sequence_counter);
}

PLAT_UI32 HostMacKeyIdx;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this would fit with the STSAFE-A host key approach.

When the host key is provisioned in the STSAFE-A, it is immutable (except in a specific A120 evaluation configuration, which is not applicable to the full STSAFE-A portfolio and is not recommended for production).

Therefore, I would recommend replacing the current stsafea_open_host_session with your stsafea_open_host_session_from_idx approach.

The new stse_platform_store_session_key, which allows the user to set the key, can optionally be used prior to the stsafea_open_host_session call (depending on the host key storage option at the host level).

}

if (pSession->context.host.Host_MAC_key_idx && pSession->context.host.Host_cypher_key_idx) {
stse_platform_delete_key(pSession->context.host.Host_cypher_key_idx, pSession->context.host.Host_MAC_key_idx);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not delete the key here . Deleting the index is enough. The Host platform usually keep the Host key in its secure storage or in static memory (this key immutable in STSAFE-A) . Only the ID and counters could change from session to session as it can target a different STSAFE

@Grolleau-Benjamin
Copy link
Copy Markdown
Contributor Author

Hi @Grom- , @TofMassilia13320, I think that I should move those changes to dev/v1.2 and introduce a changelog as we discussed with @Grom- in this PR?

@TofMassilia13320
Copy link
Copy Markdown
Contributor

Yes exactly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants