Repository navigation
Make secret-key cleanup and replacement exception-safe - #29
Conversation
Secret keys were moved into wrapper objects before algorithm validation, so constructor exceptions could leave caller-provided key material uncleansed. Existing keys were also overwritten during assignment and key regeneration without cleansing the old bytes first.\n\nRetain constructor ownership until validation and metadata initialization complete, cleanse keys before copy/move assignment and regeneration, and add lifecycle coverage for both KEM and signature wrappers. Signed-off-by: AKG451 <217809809+AKG451@users.noreply.github.com>
Refactor secret key management for KeyEncapsulation and Signature classes. Introduce SecretKeyGuard for automatic cleansing of secret keys upon destruction. Signed-off-by: Aryan K. Gupta <akg451154@gmail.com>
Refactor KEM tests to use TestSecret for memory management and improve thread safety. Signed-off-by: Aryan K. Gupta <akg451154@gmail.com>
Signed-off-by: Aryan K. Gupta <akg451154@gmail.com>
Refactor KEM tests to improve clarity and correctness. Removed TestSecret class usage in favor of direct comparison of shared secrets. Added NotSupported test case for unsupported KEMs. Signed-off-by: Aryan K. Gupta <akg451154@gmail.com>
Refactor signature tests to improve readability and error handling. Update verification checks to log failures and ensure proper thread handling. Signed-off-by: Aryan K. Gupta <akg451154@gmail.com>
|
@dstebila @baentsch The Windows CI job is failing while compiling liboqs’s SQIsign code:
This appears unrelated to the files changed in this PR, although I haven’t confirmed the same failure on the base branch. Could you please take a look when convenient? Thank you. |
|
@bhess has been leading the SQIsign integration. |
|
It seems that ssize_t is POSIX, which MSVC doesn't support, and this wasn't caught in liboqs because our Windows CI only builds Release, where the asserts using it are compiled out. I'll propose a fix in liboqs; the use of ssize_t shouldn't actually be needed. |
|
I've opened a PR in liboqs which should resolve the Windows build error: open-quantum-safe/liboqs#2690 |
|
Thanks @bhess! I'll keep an eye on #2690 and re-trigger the CI here once it lands. |
The private member swap() in KeyEncapsulation and Signature hid std::swap from unqualified lookup in derived classes. Rename it to swap_state(). Add unit tests that observe the heap through a test-only replacement of the global operator new/delete (unit_tests/tests/alloc_hooks.*): - failed construction cleanses the secret key passed in - generate_keypair() and copy/move assignment cleanse the replaced key - moves do not copy the secret key - a failed copy assignment leaves the destination unchanged These replace NotSupportedWithSecretKey, which could not fail. All new tests fail against the header on main and pass with this change. Add a Pre-release entry to CHANGES.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Douglas Stebila <dstebila@uwaterloo.ca>
|
Thanks for the fixes. The approach looks right. I've pushed three changes on top:
The CI failures come from liboqs |
|
@dstebila, Thanks for the review and changes. The windows test will fail once again as, open-quantum-safe/liboqs#2690 hasn't been merged yet. |
Signed-off-by: AKG451 <akg451154@gmail.com>
1187f2c to
8b04911
Compare
Secret-key storage in
KeyEncapsulationandSignaturecould be released without cleansing during assignment, regeneration, or failed construction. The move operations also copied secret vectors insidenoexceptfunctions, potentially terminating the process on allocation failure.This PR updates both wrappers to:
The added lifecycle tests cover copying, moving, self-assignment, empty-key assignment, regeneration, and assignment across algorithms when the selected alternatives are enabled. They check that resulting keys remain usable for encapsulation/decapsulation or signing/verification.
Moves now transfer ownership of the existing allocation rather than copying and wiping the source allocation. The destination becomes responsible for cleansing that storage. Private member order also changes, so consumers should rebuild.
Validation completed: