Skip to content

Conversation

@simo5
Copy link
Member

@simo5 simo5 commented Dec 19, 2025

Description

  • Implements the infrastructure needed to save and restore state in encrypted form
  • Uses an ephemeral key that ensures state is tied to a specific process and can't be recovered later
  • Actually implement save/restore operations for Digests

Currently the only way to use this is with a pre-release version of OpenSSL 4.0 which implement the required EVP_MD_CTX_serialize/deserialize functions. Only SHA2/SHA3 algorithms are supported.

Fixes #349

Checklist

  • Test suite updated with functionality tests
  • Test suite updated with negative tests
  • Rustdoc string were added or updated
  • CHANGELOG and/or other documentation added or updated
  • This is not a code change

Reviewer's checklist:

  • Any issues marked for closing are fully addressed
  • There is a test suite reasonably covering new functionality or modifications
  • This feature/change has adequate documentation added
  • A changelog entry is added if the change is significant
  • Code conform to coding style that today cannot yet be enforced via the check style test
  • Commits have short titles and sensible text
  • Doc string are properly updated

simo5 and others added 5 commits December 18, 2025 18:19
Move the `aes_gcm_encrypt` and `aes_gcm_decrypt` functions from the
`storage::aci` module to a new, dedicated `encryption` module.

This change makes these general-purpose cryptographic helpers available
for reuse in other parts of the codebase and improves modularity.

Signed-off-by: Simo Sorce <simo@redhat.com>
Add a `new()` constructor for `AesMechanism` to handle the common
initialization of the `CK_MECHANISM_INFO` struct.

This change centralizes the setting of `ulMinKeySize` and `ulMaxKeySize`,
removing significant code duplication from the `AES_MECHS` static array
definition and improving readability.

Signed-off-by: Simo Sorce <simo@redhat.com>
Implement the C_GetOperationState and C_SetOperationState functions. This
allows clients to save the state of an active cryptographic operation and
restore it later, potentially in a different session.

The state of all active operations in a session is collected, serialized using
ASN.1, and then encrypted with an ephemeral AES-GCM key. This key is generated
once per process lifetime, ensuring the confidentiality and integrity of the
saved state.

While the framework supports saving the state for all operation types, only
the restoration of Digest operations is currently implemented.

Signed-off-by: Simo Sorce <simo@redhat.com>
This commit introduces support for OpenSSL 4.0 by adding the `ossl400` feature
flag and corresponding build-time version checks.

The primary change is the implementation of digest context serialization and
deserialization, a feature available in OpenSSL 4.0. New methods `get_state`,
`set_state`, and `get_state_size` are added to `OsslDigest` to expose this
functionality, wrapping the underlying `EVP_MD_CTX_serialize` and
`EVP_MD_CTX_deserialize` functions. These methods are conditionally compiled
and only available when using OpenSSL 4.0 or newer.

Signed-off-by: Simo Sorce <simo@redhat.com>
This change implements the `C_GetOperationState` and `C_SetOperationState`
functions for multi-part digest (hashing) operations.

This allows an application to save the state of a digest operation and resume
it later. The OpenSSL backend is updated to use its internal state-saving
capabilities. A comprehensive test is added to verify that a restored
operation produces the same result as a continuous one.

The `state_save` method in the `MechOperation` trait was also changed to take
`&self` instead of `&mut self`, as saving the state should not mutate the
operation itself.

Co-authored-by: Gemini <gemini@google.com>
Signed-off-by: Simo Sorce <simo@redhat.com>
Modify the GitHub Actions build workflow to check out different OpenSSL
sources depending on the linking type.

FIPS builds now use a specific fork and branch
(`simo5/openssl@kryoptic_ossl35`) required for the FIPS provider. Static
builds are updated to use the official OpenSSL repository's master branch.
Previously, both build types used the same FIPS-specific branch.

Signed-off-by: Simo Sorce <simo@redhat.com>
This allows to test options that are not available in older OpenSSL
versions like digest (de)serialization.

Signed-off-by: Simo Sorce <simo@redhat.com>
Signed-off-by: Simo Sorce <simo@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for (re)storing state for Digest operations

2 participants