Skip to content

Added support for ML-DSA in softhsm2-util#870

Open
antoinelochet wants to merge 1 commit into
softhsm:mainfrom
antoinelochet:feature/ml-dsa-softhsmutil
Open

Added support for ML-DSA in softhsm2-util#870
antoinelochet wants to merge 1 commit into
softhsm:mainfrom
antoinelochet:feature/ml-dsa-softhsmutil

Conversation

@antoinelochet
Copy link
Copy Markdown
Contributor

@antoinelochet antoinelochet commented Apr 30, 2026

Added missing ML-DSA cmake compiler option
Fixes #853

Summary by CodeRabbit

  • New Features

    • ML‑DSA key import and persistent storage with improved OpenSSL provider support.
  • Bug Fixes / UX

    • Import/save success messages now include the key or certificate label for clearer feedback.
  • Tests

    • Added automated ML‑DSA import test and integrated it into local/CI test runs.
  • CI / Build

    • Expanded Windows CI matrix and added ML‑DSA detection during configuration.
  • Chores

    • Broadened ignored test token paths and increased logging buffer sizing.

Review Change Stack

@antoinelochet antoinelochet requested a review from a team as a code owner April 30, 2026 15:36
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds ML‑DSA import and persistence to the softhsm2-util OpenSSL backend: detects provider-backed ML‑DSA EVP_PKEYs, extracts seed/private/public components, maps parameter sets to PKCS#11 attributes, and persists key pairs via new save/alloc/free helpers (guarded by WITH_ML_DSA).

Changes

ML-DSA Import and Save Logic

Layer / File(s) Summary
Build-time OpenSSL ML‑DSA detection
cmake/modules/CompilerOptions.cmake, cmake/modules/tests/test_openssl_mldsa.c
Adds ML‑DSA detection test and configures WITH_ML_DSA when OpenSSL provider supports ML‑DSA.
Utility entry & EVP_PKEY dispatch
src/bin/util/softhsm2-util-ossl.cpp
Refactors OpenSSL 3+ EVP_PKEY dispatch to use keymgmt/EVP_PKEY_get_id, detects ML‑DSA provider keys (ML-DSA-44/65/87), up-refs provider EVP_PKEY, and routes to a new ML‑DSA persistence branch; updates user-facing success messages to include label.
ML‑DSA Types & Public API Declarations
src/bin/util/softhsm2-util-ossl.h
Adds mldsa_key_material_t and declares crypto_save_mldsa, crypto_malloc_mldsa, and crypto_free_mldsa under #ifdef WITH_ML_DSA.
Persistence Helpers (new)
src/bin/util/softhsm2-util-ossl.cpp
Implements crypto_save_mldsa, crypto_malloc_mldsa, and crypto_free_mldsa to extract seed/priv/pub, validate sizes, map parameter set to PKCS#11 attributes (CKA_PARAMETER_SET, CKA_SEED, CKA_VALUE), and create PKCS#11 public/private objects.
Tests & Test Wiring
src/bin/util/test/*, src/bin/util/test/mldsa44-import-key-test.sh, src/bin/util/CMakeLists.txt, src/bin/util/Makefile.am
Adds a shell test to generate/import an ML‑DSA‑44 key, CMake/Automake test wiring, and a CTest entry to exercise the import in CI.
CI Jobs (Windows)
.github/workflows/ci.yml
Parameterizes Windows CI matrix and adds an OpenSSL 3.5.4 entry that can enable -DENABLE_MLDSA=ON; generates vcpkg.json dynamically and exposes MLDSA_TEST to the test step.
Token ignores & logging buffer
.gitignore, src/lib/common/log.h, src/lib/common/log.cpp, src/lib/win32/syslog.cpp
Expands ignored test token dirs and replaces fixed-size/unbounded formatting with MAX_LOG_MESSAGE_SIZE and bounded formatting.
Crypto includes & small ML changes
src/lib/crypto/CMakeLists.txt, src/lib/crypto/OSSLMLDSA.cpp, src/lib/crypto/OSSLMLDSAPrivateKey.cpp
Adds include paths for crypto build; renames parameter variable and tightens seed extraction/zeroing in ML‑DSA private key handling.

Sequence Diagram(s)

sequenceDiagram
  participant Tool as softhsm2-util
  participant OpenSSL as OpenSSL EVP (provider)
  participant PKCS11 as PKCS#11 Token

  Tool->>OpenSSL: Import request -> provider-backed EVP_PKEY
  OpenSSL-->>Tool: EVP_PKEY (ML-DSA)
  Tool->>OpenSSL: Query EVP_PKEY_is_a / KEYMGMT for ML-DSA
  OpenSSL-->>Tool: seed, privValue, pubValue, parameterSet
  Tool->>PKCS11: crypto_save_mldsa -> C_CreateObject(private, attrs: CKA_SEED, CKA_VALUE, CKA_PARAMETER_SET)
  PKCS11-->>Tool: private object stored
  Tool->>PKCS11: crypto_save_mldsa -> C_CreateObject(public, attrs: CKA_VALUE, CKA_PARAMETER_SET)
  PKCS11-->>Tool: public object stored
  Tool-->>Tool: print success message (includes label)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • softhsm/SoftHSMv2#816: Modifies crypto_import_key_pair dispatch in src/bin/util/softhsm2-util-ossl.cpp (related EVP_PKEY/type handling and new algorithm branches).
  • softhsm/SoftHSMv2#809: Also implements ML‑DSA support in the OpenSSL backend with parameter/structure additions and build/test updates.
  • softhsm/SoftHSMv2#867: Related ML‑DSA work touching ML‑DSA internals and mechanism parameter handling.

Suggested labels

enhancement

Suggested reviewers

  • bukka
  • jschlyter
  • bjosv

Poem

🐰 I found a seed beneath the code,
ML‑DSA tucked on the import road.
I hopped to token, stored each byte,
Now keys can wake and sign by night.
🥕 Small paws, big crypto delight.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 52.38% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Out of Scope Changes check ❓ Inconclusive Most changes are directly related to ML-DSA support. However, several ancillary modifications extend beyond the core ML-DSA implementation: log buffer sizing refactoring and CMake include directory adjustments appear tangential to the stated objective of adding ML-DSA key import support. Clarify whether log.h/log.cpp buffer sizing changes and crypto/CMakeLists.txt include path additions are necessary for ML-DSA support or represent separate improvements that should be in different PRs.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding ML-DSA support to softhsm2-util. It is clear, specific, and directly related to the changeset.
Linked Issues check ✅ Passed The PR addresses issue #853's requirement to add ML-DSA key support to softhsm2-util for the --import functionality. All necessary code changes are implemented including ML-DSA key detection, PKCS#11 persistence, extraction helpers, CMake configuration, and test coverage.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmake/modules/CompilerOptions.cmake`:
- Around line 373-379: The CMake logic for ML-DSA currently toggles WITH_ML_DSA
based only on ENABLE_MLDSA; add a functional probe like the existing EDDSA/GOST
probes by using try_compile/try_run to compile and run a small test that calls
EVP_PKEY_CTX_new_from_name(NULL, "ML-DSA-44", NULL) (or the same test snippet
used for autoconf) and set WITH_ML_DSA only if the probe succeeds; if
ENABLE_MLDSA is ON but the probe fails, emit a fatal error (message(FATAL_ERROR
...)) so the build fails fast, mirroring the behavior of the autoconf macro and
the EDDSA/GOST checks.

In `@src/bin/util/softhsm2-util-ossl.cpp`:
- Around line 440-442: The fprintf call that prints the PKCS#8 read failure is
malformed ("Error code: %")—fix it by formatting and passing the actual error
value or message: change the call to include a proper format specifier (e.g.,
"Error code: %d\n" or "Error: %s\n") and pass the appropriate error variable
(for example rc, err, or use ERR_error_string(ERR_get_error(), NULL) if using
OpenSSL). Update the fprintf invocation in the same block (the fprintf(...) that
reports "Could not read the PKCS#8 file") to use the corrected format and
argument so the error code/text is shown.
- Around line 1276-1350: The function crypto_malloc_mldsa leaks keyMat on early
returns and risks deref if mallocs fail before memcpy; ensure every early error
path calls crypto_free_mldsa(keyMat) (not plain return) after zeroing sensitive
buffers (seed, priv, pub) and only perform memcpy(keyMat->seed,...),
memcpy(keyMat->privValue,...) and memcpy(keyMat->pubValue,...) after successful
malloc checks of keyMat->seed, keyMat->privValue and keyMat->pubValue;
specifically update the error branches following EVP_PKEY_get_octet_string_param
(for seed, priv, pub) to free keyMat on failure and add immediate null-checks of
allocations right after the three malloc(...) calls and before the memcpy calls,
using crypto_free_mldsa to clean up on allocation failure.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 53d311e7-ea48-4feb-9f8b-598f85e8bb0e

📥 Commits

Reviewing files that changed from the base of the PR and between 6319797 and 422b004.

📒 Files selected for processing (3)
  • cmake/modules/CompilerOptions.cmake
  • src/bin/util/softhsm2-util-ossl.cpp
  • src/bin/util/softhsm2-util-ossl.h

Comment thread cmake/modules/CompilerOptions.cmake
Comment thread src/bin/util/softhsm2-util-ossl.cpp
Comment thread src/bin/util/softhsm2-util-ossl.cpp Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/bin/util/softhsm2-util-ossl.cpp`:
- Around line 198-201: In crypto_import_key_pair(), the error path currently
returns NULL (a pointer) inside an int function, causing a false success; change
the return from NULL to 0 to indicate failure, keeping the existing
EVP_PKEY_free(pkey) and stderr log intact so the function properly signals
failure on the OSSL_PKEY_PARAM_ML_DSA_SEED size retrieval error.
- Around line 193-202: The code currently treats any failure to get
OSSL_PKEY_PARAM_ML_DSA_SEED via EVP_PKEY_get_octet_string_param as a hard error;
instead, make the seed optional: call EVP_PKEY_get_octet_string_param(pkey,
OSSL_PKEY_PARAM_ML_DSA_SEED, NULL, 0, &seed_len) and if it returns 1 proceed to
allocate and retrieve the seed and add CKA_SEED to the object template, if it
returns 0 treat the seed as absent and continue without adding CKA_SEED, and
only treat negative return values as real errors; mirror the behavior used in
OSSLMLDSAPrivateKey::setFromOSSL so missing seed is handled gracefully rather
than failing the import.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6c788348-9406-4df2-8231-03046d9e1330

📥 Commits

Reviewing files that changed from the base of the PR and between 422b004 and 21beaf3.

📒 Files selected for processing (3)
  • cmake/modules/CompilerOptions.cmake
  • src/bin/util/softhsm2-util-ossl.cpp
  • src/bin/util/softhsm2-util-ossl.h
🚧 Files skipped from review as they are similar to previous changes (2)
  • cmake/modules/CompilerOptions.cmake
  • src/bin/util/softhsm2-util-ossl.h

Comment thread src/bin/util/softhsm2-util-ossl.cpp
Comment thread src/bin/util/softhsm2-util-ossl.cpp Outdated
@antoinelochet antoinelochet force-pushed the feature/ml-dsa-softhsmutil branch from 21beaf3 to 090bbd1 Compare April 30, 2026 15:49
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/bin/util/softhsm2-util-ossl.cpp (1)

1262-1263: 💤 Low value

Remove unused macro redefinitions.

PUBPREFIXLEN and PRIVPREFIXLEN are already defined in the EdDSA section (lines 1083-1084) and are not used in the ML-DSA implementation. These lines appear to be copy-paste artifacts.

🧹 Suggested removal
-// Convert the OpenSSL key to binary
-#define PUBPREFIXLEN	12
-#define PRIVPREFIXLEN	16
-
+// Convert the OpenSSL key to binary
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/bin/util/softhsm2-util-ossl.cpp` around lines 1262 - 1263, Remove the
duplicate macro redefinitions PUBPREFIXLEN and PRIVPREFIXLEN from the ML-DSA
section (the lines that define "#define PUBPREFIXLEN 12" and "#define
PRIVPREFIXLEN 16"); these are already defined earlier in the EdDSA section and
are unused in the ML-DSA implementation, so delete those two defines and run a
build to confirm no remaining references to PUBPREFIXLEN/PRIVPREFIXLEN are
broken.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/bin/util/softhsm2-util-ossl.cpp`:
- Around line 1262-1263: Remove the duplicate macro redefinitions PUBPREFIXLEN
and PRIVPREFIXLEN from the ML-DSA section (the lines that define "#define
PUBPREFIXLEN 12" and "#define PRIVPREFIXLEN 16"); these are already defined
earlier in the EdDSA section and are unused in the ML-DSA implementation, so
delete those two defines and run a build to confirm no remaining references to
PUBPREFIXLEN/PRIVPREFIXLEN are broken.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 40925612-15b6-4b92-b560-4cf425323e28

📥 Commits

Reviewing files that changed from the base of the PR and between 21beaf3 and 090bbd1.

📒 Files selected for processing (3)
  • cmake/modules/CompilerOptions.cmake
  • src/bin/util/softhsm2-util-ossl.cpp
  • src/bin/util/softhsm2-util-ossl.h
✅ Files skipped from review due to trivial changes (1)
  • cmake/modules/CompilerOptions.cmake

@antoinelochet antoinelochet force-pushed the feature/ml-dsa-softhsmutil branch from 090bbd1 to 79c039e Compare April 30, 2026 16:02
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/bin/util/softhsm2-util-ossl.cpp (2)

1350-1366: 💤 Low value

Consider adding defensive assertion for unreachable default case.

The default case in the parameter set switch (line 1364) is unreachable due to the length validation at lines 1310-1319, but silently leaving parameterSet as 0 could mask bugs if the validation logic changes. Adding an assertion or explicit error return would improve defensive coding.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/bin/util/softhsm2-util-ossl.cpp` around lines 1350 - 1366, The switch
over keyMat->sizePrivValue leaves keyMat->parameterSet as 0 in the default
branch which can hide future bugs; modify the default branch in this switch (the
block that assigns MLDSAParameters::ML_DSA_*_PARAMETER_SET) to be defensive:
either add an assertion (e.g., assert(false) or equivalent debug assertion)
referencing keyMat->sizePrivValue, or return/throw an explicit error indicating
an unexpected private length, so parameterSet is never silently left unset;
ensure you update the containing function's control flow to propagate the error
if you choose return/throw.

159-218: 💤 Low value

Provider-managed key detection relies on ML-DSA-specific parameters.

The detection for provider-managed keys (OpenSSL 3+) probes for OSSL_PKEY_PARAM_ML_DSA_SEED or OSSL_PKEY_PARAM_PRIV_KEY. This works for now since ML-DSA is the only provider-managed key type supported, but if future algorithms are added (e.g., ML-KEM, SLH-DSA), this detection logic would need refinement to avoid misidentifying them.

Consider using EVP_PKEY_is_a(pkey, "ML-DSA") for more robust algorithm identification when expanding provider key support.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/bin/util/softhsm2-util-ossl.cpp` around lines 159 - 218, The current
provider-managed key detection in the EVP_PKEY_KEYMGMT branch relies on probing
ML-DSA-specific params via EVP_PKEY_get_octet_string_param
(OSSL_PKEY_PARAM_ML_DSA_SEED / OSSL_PKEY_PARAM_PRIV_KEY), which may misidentify
future provider algorithms; change the detection to explicitly check the key
type with EVP_PKEY_is_a(pkey, "ML-DSA") (or analogous algorithm name) before
attempting ML-DSA-specific param calls, and only call
EVP_PKEY_get_octet_string_param / EVP_PKEY_up_ref and assign to mldsa when
EVP_PKEY_is_a returns true; update the logic in the branch guarded by keyType ==
EVP_PKEY_KEYMGMT to use EVP_PKEY_is_a(pkey, "ML-DSA") instead of the current
param-probing heuristic so other provider algorithms won't be misdetected.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/bin/util/softhsm2-util-ossl.cpp`:
- Around line 1266-1267: Remove the redundant macro redefinitions PUBPREFIXLEN
and PRIVPREFIXLEN from the ML-DSA section: delete the two `#define` lines so the
code uses the existing definitions from the EDDSA section and avoids macro
redefinition warnings; if you prefer safety instead of deletion, wrap the
defines with `#ifndef` PUBPREFIXLEN / `#ifndef` PRIVPREFIXLEN guards to only define
them when not already defined.

---

Nitpick comments:
In `@src/bin/util/softhsm2-util-ossl.cpp`:
- Around line 1350-1366: The switch over keyMat->sizePrivValue leaves
keyMat->parameterSet as 0 in the default branch which can hide future bugs;
modify the default branch in this switch (the block that assigns
MLDSAParameters::ML_DSA_*_PARAMETER_SET) to be defensive: either add an
assertion (e.g., assert(false) or equivalent debug assertion) referencing
keyMat->sizePrivValue, or return/throw an explicit error indicating an
unexpected private length, so parameterSet is never silently left unset; ensure
you update the containing function's control flow to propagate the error if you
choose return/throw.
- Around line 159-218: The current provider-managed key detection in the
EVP_PKEY_KEYMGMT branch relies on probing ML-DSA-specific params via
EVP_PKEY_get_octet_string_param (OSSL_PKEY_PARAM_ML_DSA_SEED /
OSSL_PKEY_PARAM_PRIV_KEY), which may misidentify future provider algorithms;
change the detection to explicitly check the key type with EVP_PKEY_is_a(pkey,
"ML-DSA") (or analogous algorithm name) before attempting ML-DSA-specific param
calls, and only call EVP_PKEY_get_octet_string_param / EVP_PKEY_up_ref and
assign to mldsa when EVP_PKEY_is_a returns true; update the logic in the branch
guarded by keyType == EVP_PKEY_KEYMGMT to use EVP_PKEY_is_a(pkey, "ML-DSA")
instead of the current param-probing heuristic so other provider algorithms
won't be misdetected.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5a792174-e8f1-462c-bc1e-e0622326af75

📥 Commits

Reviewing files that changed from the base of the PR and between 090bbd1 and 79c039e.

📒 Files selected for processing (2)
  • src/bin/util/softhsm2-util-ossl.cpp
  • src/bin/util/softhsm2-util-ossl.h

Comment thread src/bin/util/softhsm2-util-ossl.cpp Outdated
@antoinelochet antoinelochet force-pushed the feature/ml-dsa-softhsmutil branch 3 times, most recently from 8686705 to 845cda9 Compare April 30, 2026 16:25
@antoinelochet
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/bin/util/softhsm2-util-ossl.cpp`:
- Line 1282: The fprintf calls printing error messages to stderr are missing
trailing newlines (e.g., the call "fprintf(stderr, \"ERROR: Could not get ML-DSA
seed, rv: %d\", rv)" and the similar calls at the other sites), which can garble
console output; update each fprintf that writes errors to stderr (the ML-DSA
seed error and the two other error fprintfs around the same block) to include a
terminating "\n" in the format string so they become e.g. "fprintf(stderr,
\"ERROR: Could not get ML-DSA seed, rv: %d\\n\", rv)". Ensure all three affected
fprintf invocations are changed consistently.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fe4e7a23-21aa-4b18-b83a-b6de4989ee54

📥 Commits

Reviewing files that changed from the base of the PR and between 79c039e and 845cda9.

📒 Files selected for processing (2)
  • src/bin/util/softhsm2-util-ossl.cpp
  • src/bin/util/softhsm2-util-ossl.h

Comment thread src/bin/util/softhsm2-util-ossl.cpp Outdated
@antoinelochet antoinelochet force-pushed the feature/ml-dsa-softhsmutil branch from 845cda9 to 046a174 Compare April 30, 2026 19:05
@bukka
Copy link
Copy Markdown
Member

bukka commented May 3, 2026

Nice work. It would be even nicer if we could add some tests. The #864 might be something that we can build on - even if we have some shell scripts that will run, it will be a big improvement. And I suppose you have some script that you run to test it, right?

@antoinelochet
Copy link
Copy Markdown
Contributor Author

Nice work. It would be even nicer if we could add some tests. The #864 might be something that we can build on - even if we have some shell scripts that will run, it will be a big improvement. And I suppose you have some script that you run to test it, right?

Well... To be honest, I have tested it manually...
I will take a look at #864 and add some tests as much as I can.

@antoinelochet antoinelochet force-pushed the feature/ml-dsa-softhsmutil branch 2 times, most recently from 0ded500 to 33fc9a6 Compare May 4, 2026 09:22
@antoinelochet
Copy link
Copy Markdown
Contributor Author

Nice work. It would be even nicer if we could add some tests. The #864 might be something that we can build on - even if we have some shell scripts that will run, it will be a big improvement. And I suppose you have some script that you run to test it, right?

Added a shell basic test taking inspiration from #864

@antoinelochet antoinelochet force-pushed the feature/ml-dsa-softhsmutil branch 8 times, most recently from c160ae6 to b4f069e Compare May 4, 2026 19:30
@antoinelochet antoinelochet force-pushed the feature/ml-dsa-softhsmutil branch 17 times, most recently from fd467dc to 29965b7 Compare May 11, 2026 12:58
@antoinelochet
Copy link
Copy Markdown
Contributor Author

antoinelochet commented May 11, 2026

@bukka It is ready for review with the test script now.
I could not make it work as a Windows 32bits executable since the whole runner is based on Windows 2022 with an 64bits OpenSSL.
Windows syslog was broken for messages > 1023 chars because log input buffer was 4096 and syslog buffer was only 1024. I applied a suggestion by coderabbit to improve this part of the code.

@antoinelochet
Copy link
Copy Markdown
Contributor Author

antoinelochet commented May 11, 2026

@codrerabbitai resume
@coderabbitai resume

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

@antoinelochet Sure! Resuming the reviews now. I'll take a look at the latest changes including the new test script.

✅ Actions performed

Reviews resumed.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (3)
src/lib/win32/syslog.cpp (1)

37-37: 💤 Low value

Consider the stack allocation size for buf.

The buffer buf is stack-allocated with size MAX_LOG_MESSAGE_SIZE. If MAX_LOG_MESSAGE_SIZE is large (e.g., several KB), this could risk stack overflow on threads with limited stack space. The comparable code in log.cpp uses std::vector<char> for heap allocation, which is safer for large buffers.

If MAX_LOG_MESSAGE_SIZE is reasonably small (≤ 1-2 KB), stack allocation is fine. Otherwise, consider heap allocation or document the size constraint.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/win32/syslog.cpp` at line 37, The stack allocation `char
buf[MAX_LOG_MESSAGE_SIZE];` in syslog.cpp can overflow if MAX_LOG_MESSAGE_SIZE
is large; replace it with a heap-backed buffer (e.g., construct a
std::vector<char> buffer(MAX_LOG_MESSAGE_SIZE) and use buffer.data() in place of
`buf`) or validate/limit MAX_LOG_MESSAGE_SIZE with a runtime check/static_assert
to ensure it's small (<= 1-2 KB) before keeping stack allocation; update all
uses of `buf` to the new buffer variable and include a brief comment explaining
the choice.
src/bin/util/test/mldsa44-import-key-test.sh (1)

12-118: 💤 Low value

Address shellcheck findings (backticks, unquoted expansions, unused vars).

Several style/robustness issues flagged by shellcheck are easy to fix in one pass:

  • Legacy backticks → use $(...): lines 12, 17, 27, 48, 50, 72, 95, 96, 118.
  • Unquoted glob in for F in "$D"/*softhsm2.$S (line 60): the $S portion should be safe but the file expansion is inside quotes; OK, but consider failing more cleanly if no match (current test -f "$F" || continue already handles "no match" loop iteration when nullglob is off — the loop body will fire once with the literal pattern).
  • Unused PASS_URI / KEY_URI (lines 125-126) — drop them or actually use them in the import invocation.
  • Unquoted $SOFTHSM2_CONF / $TOKEN_DIR in cat invocations (lines 116, 133, 138, 146, 151, 156) — quote to be safe against paths with spaces (relevant on Windows runners with C:\Program Files\…-style temp dirs).
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/bin/util/test/mldsa44-import-key-test.sh` around lines 12 - 118, Replace
legacy backticks with $(...) (occurrences where variables are assigned: CWD,
OPENSSL lookup, openssl_version, D, P11MODULE realpath, WINDOWS_TOKEN_DIR
realpath and cygpath), quote all variable expansions passed to commands like
cat, realpath, mkdir, rm, and softhsm2_tool (use "$SOFTHSM2_CONF", "$TOKEN_DIR",
"$P11MODULE", "$CWD", "$WINDOWS_TOKEN_DIR"), and either remove the unused
PASS_URI/KEY_URI variables or actually pass them into the import invocation;
also ensure the glob loop for F in "$D"/*softhsm2.$S is left as-is but guarded
(keep test -f "$F" || continue) so it behaves predictably when no match is
found.
.github/workflows/ci.yml (1)

191-265: ⚖️ Poor tradeoff

Consider consolidating the three Windows jobs.

The new windows_ossl30 and windows_ossl35 jobs duplicate most of windows_botan_ossl11 (steps, vcpkg setup, build, and test). The differences (vcpkg overrides, arch matrix, build-options) could be expressed in a single matrix-driven job to reduce drift risk over time (e.g., if someone updates the vcpkg-action version on only one job).

This is optional and non-blocking for the PR’s goal of enabling ML‑DSA.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/ci.yml around lines 191 - 265, The CI duplicates three
Windows jobs (windows_ossl30, windows_ossl35 and windows_botan_ossl11); replace
them with one matrix-driven job (e.g., windows) that exposes per-matrix keys for
arch, target-platform, openssl_version (used in the vcpkg.json override), and
build-options, then reuse the same steps (actions/checkout, ilammy/msvc-dev-cmd,
generate vcpkg.json using matrix.openssl_version, seanmiddleditch/vcpkg-action,
cmake configure/build and RUN_TESTS) so differences are driven by matrix values
and not duplicated across separate job blocks.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/bin/util/test/Makefile.am`:
- Around line 9-10: The EXTRA_DIST assignment is missing a trailing
line-continuation backslash so the second file entry is not included; update the
EXTRA_DIST multi-line variable (EXTRA_DIST) to use a backslash after the
CMakeLists.txt entry so that $(srcdir)/mldsa44-import-key-test.sh is part of the
same assignment and will be packaged by make dist.

In `@src/bin/util/test/mldsa44-import-key-test.sh`:
- Around line 47-81: The Windows-specific paths in the test script (the
RUNNER_OS branch that sets D to ../../../lib/Debug/ and the softhsm2_tool
invocation using ../Debug/softhsm2-util.exe) hardcode the Debug config and will
break Release builds; update the script to detect or accept a build
configuration and/or search both Debug and Release (or use an env var like
CONFIG or CMAKE_BUILD_TYPE) when setting D and when calling softhsm2-util inside
the softhsm2_tool function, e.g., try Debug then Release (or use a provided
CONFIG) to locate the library directory and executable and set P11MODULE/command
accordingly so the script works for both Debug and Release builds.
- Around line 4-5: Remove the dangerous combination of "set -x" and the bare
"export" in the test script to avoid dumping all exported environment variables
(including secrets) to logs; either delete the standalone "export" and disable
or limit shell trace, or replace the bare export with explicit, named debug
echoes (e.g., echo "RUNNER_OS=$RUNNER_OS") for only the variables you need to
inspect so secrets are not leaked.
- Around line 7-10: The test script uses an undocumented
ACTIONS_ORCHESTRATION_ID check; update the early-skip condition to use the
documented GITHUB_JOB variable instead: replace occurrences of
ACTIONS_ORCHESTRATION_ID with GITHUB_JOB in the conditional, ensure the pattern
match still looks for "ossl35" (e.g., [[ "${GITHUB_JOB:-}" != *"ossl35"* ]]),
and keep the surrounding CI check and exit behavior intact so the later OpenSSL
version guard still handles unsupported versions.

---

Nitpick comments:
In @.github/workflows/ci.yml:
- Around line 191-265: The CI duplicates three Windows jobs (windows_ossl30,
windows_ossl35 and windows_botan_ossl11); replace them with one matrix-driven
job (e.g., windows) that exposes per-matrix keys for arch, target-platform,
openssl_version (used in the vcpkg.json override), and build-options, then reuse
the same steps (actions/checkout, ilammy/msvc-dev-cmd, generate vcpkg.json using
matrix.openssl_version, seanmiddleditch/vcpkg-action, cmake configure/build and
RUN_TESTS) so differences are driven by matrix values and not duplicated across
separate job blocks.

In `@src/bin/util/test/mldsa44-import-key-test.sh`:
- Around line 12-118: Replace legacy backticks with $(...) (occurrences where
variables are assigned: CWD, OPENSSL lookup, openssl_version, D, P11MODULE
realpath, WINDOWS_TOKEN_DIR realpath and cygpath), quote all variable expansions
passed to commands like cat, realpath, mkdir, rm, and softhsm2_tool (use
"$SOFTHSM2_CONF", "$TOKEN_DIR", "$P11MODULE", "$CWD", "$WINDOWS_TOKEN_DIR"), and
either remove the unused PASS_URI/KEY_URI variables or actually pass them into
the import invocation; also ensure the glob loop for F in "$D"/*softhsm2.$S is
left as-is but guarded (keep test -f "$F" || continue) so it behaves predictably
when no match is found.

In `@src/lib/win32/syslog.cpp`:
- Line 37: The stack allocation `char buf[MAX_LOG_MESSAGE_SIZE];` in syslog.cpp
can overflow if MAX_LOG_MESSAGE_SIZE is large; replace it with a heap-backed
buffer (e.g., construct a std::vector<char> buffer(MAX_LOG_MESSAGE_SIZE) and use
buffer.data() in place of `buf`) or validate/limit MAX_LOG_MESSAGE_SIZE with a
runtime check/static_assert to ensure it's small (<= 1-2 KB) before keeping
stack allocation; update all uses of `buf` to the new buffer variable and
include a brief comment explaining the choice.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a96b093f-7f9f-42a7-b226-806030aa0e12

📥 Commits

Reviewing files that changed from the base of the PR and between 845cda9 and 29965b7.

📒 Files selected for processing (18)
  • .github/workflows/ci.yml
  • .gitignore
  • cmake/modules/CompilerOptions.cmake
  • cmake/modules/tests/test_openssl_mldsa.c
  • configure.ac
  • src/bin/util/CMakeLists.txt
  • src/bin/util/Makefile.am
  • src/bin/util/softhsm2-util-ossl.cpp
  • src/bin/util/softhsm2-util-ossl.h
  • src/bin/util/test/CMakeLists.txt
  • src/bin/util/test/Makefile.am
  • src/bin/util/test/mldsa44-import-key-test.sh
  • src/lib/common/log.cpp
  • src/lib/common/log.h
  • src/lib/crypto/CMakeLists.txt
  • src/lib/crypto/OSSLMLDSA.cpp
  • src/lib/crypto/OSSLMLDSAPrivateKey.cpp
  • src/lib/win32/syslog.cpp
✅ Files skipped from review due to trivial changes (6)
  • src/bin/util/test/CMakeLists.txt
  • src/bin/util/Makefile.am
  • src/lib/common/log.h
  • configure.ac
  • src/lib/crypto/OSSLMLDSA.cpp
  • src/lib/crypto/OSSLMLDSAPrivateKey.cpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/bin/util/softhsm2-util-ossl.h
  • src/bin/util/softhsm2-util-ossl.cpp

Comment thread src/bin/util/test/Makefile.am Outdated
Comment thread src/bin/util/test/mldsa44-import-key-test.sh Outdated
Comment thread src/bin/util/test/mldsa44-import-key-test.sh Outdated
Comment thread src/bin/util/test/mldsa44-import-key-test.sh
@antoinelochet
Copy link
Copy Markdown
Contributor Author

Actionable comments posted: 4
🧹 Nitpick comments (3)

🤖 Prompt for all review comments with AI agents

🪄 Autofix (Beta)

ℹ️ Review info

@coderabbitai Consolidate the three Windows jobs

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
cat .github/workflows/ci.yml

Length of output: 9725


@antoinelochet Sure! Here's a consolidated single windows job that replaces all three, using a richer matrix and a dynamic PowerShell step to generate vcpkg.json:

  windows:
    name: Windows (${{ matrix.arch }}, ${{ matrix.backend }}, OpenSSL ${{ matrix.ossl-version }})
    runs-on: windows-2022
    strategy:
      fail-fast: false
      matrix:
        include:
          # OpenSSL 1.1.1n variants (+ Botan 2.19.3)
          - arch: x64
            backend: openssl
            target-platform: x64
            ossl-version: "1.1.1n"
            botan-version: ""
            build-options: ""
          - arch: x64
            backend: botan
            target-platform: x64
            ossl-version: "1.1.1n"
            botan-version: "2.19.3"
            build-options: "-DENABLE_ECC=OFF -DENABLE_EDDSA=OFF"
          - arch: x86
            backend: openssl
            target-platform: Win32
            ossl-version: "1.1.1n"
            botan-version: ""
            build-options: "-DENABLE_ECC=OFF -DENABLE_EDDSA=OFF"
          # OpenSSL 3.4.1
          - arch: x64
            backend: openssl
            target-platform: x64
            ossl-version: "3.4.1"
            botan-version: ""
            build-options: ""
          - arch: x86
            backend: openssl
            target-platform: Win32
            ossl-version: "3.4.1"
            botan-version: ""
            build-options: "-DENABLE_ECC=OFF -DENABLE_EDDSA=OFF"
          # OpenSSL 3.5.4 + ML-DSA (x64 only — 32-bit runner limitation)
          - arch: x64
            backend: openssl
            target-platform: x64
            ossl-version: "3.5.4"
            botan-version: ""
            build-options: "-DENABLE_MLDSA=ON"
    steps:
      - uses: actions/checkout@v4
      - uses: ilammy/msvc-dev-cmd@v1
        with:
          arch: ${{ matrix.arch }}
      - name: Create vcpkg.json
        shell: pwsh
        run: |
          $deps = @("openssl", "cppunit")
          $overrides = @(@{ name = "openssl"; "version-string" = "${{ matrix.ossl-version }}" })
          if ("${{ matrix.backend }}" -eq "botan") {
            $deps += "botan"
            $overrides += @{ name = "botan"; "version-string" = "${{ matrix.botan-version }}" }
          }
          [ordered]@{
            dependencies     = $deps
            overrides        = $overrides
            "builtin-baseline" = "38d1652f152d36481f2f4e8a85c0f1e14f3769f7"
          } | ConvertTo-Json -Depth 5 | Out-File vcpkg.json -Encoding utf8
      - uses: seanmiddleditch/vcpkg-action@master
        id: vcpkg
        with:
          manifest-dir: ${{ github.workspace }}
          triplet: ${{ matrix.arch }}-windows
          token: ${{ github.token }}
      - name: Build
        run: |
          mkdir build
          cmake -B build ${{ steps.vcpkg.outputs.vcpkg-cmake-config }} -A ${{ matrix.target-platform }} -DWITH_CRYPTO_BACKEND=${{ matrix.backend }} ${{ matrix.build-options }} -DDISABLE_NON_PAGED_MEMORY=ON -DBUILD_TESTS=ON
          cmake --build build
      - name: Test
        env:
          CTEST_OUTPUT_ON_FAILURE: 1
        run: |
          cmake --build build --target RUN_TESTS

What changed vs. the three separate jobs:

Aspect Before After
Job count 3 (windows_botan_ossl11, windows_ossl30, windows_ossl35) 1 (windows)
Matrix entries 3 + 2 + 1 = 6 total Same 6 entries, same coverage
vcpkg.json step Hardcoded JSON per job Generated dynamically via PowerShell from ossl-version / botan-version matrix vars
Build/Test steps Duplicated across 3 jobs Single shared definition

The only behavioural difference is the job display name now includes the OpenSSL version (e.g. Windows (x64, openssl, OpenSSL 3.5.4)), which makes the matrix more readable in the GitHub Actions UI.

@antoinelochet antoinelochet force-pushed the feature/ml-dsa-softhsmutil branch 2 times, most recently from d60a1e4 to f0323ea Compare May 11, 2026 19:28
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
src/bin/util/test/mldsa44-import-key-test.sh (1)

4-7: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Early CI gate is skipping the ML-DSA test in intended jobs

Line 4 ties execution to GITHUB_JOB containing ossl35, but current job ids don’t reliably match that token (e.g., windows, linux_ossl_35). This causes the test to be skipped even when OpenSSL is 3.5+. The version check later in the script already handles eligibility, so this gate should be removed (or replaced with an explicit CI flag).

Suggested minimal fix
-if [[ "$CI" == "true" ]] && [[ "$GITHUB_JOB" != *"ossl35"* ]] ; then
-  echo "This test is intended to be run with OpenSSL >= 3.5, skipping." >&2
-  exit 0
-fi
+# Let the OpenSSL version check below decide whether to skip.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/bin/util/test/mldsa44-import-key-test.sh` around lines 4 - 7, Remove the
early CI gate that checks CI and GITHUB_JOB (the if block testing [[ "$CI" ==
"true" ]] && [[ "$GITHUB_JOB" != *"ossl35"* ]] ... fi) from the
mldsa44-import-key-test.sh script so the test isn't prematurely skipped; rely on
the existing OpenSSL version check later in the script (or, if desired, replace
the gate with an explicit CI-only flag check) so jobs with non-matching
GITHUB_JOB names like "linux_ossl_35" no longer get incorrectly excluded.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@src/bin/util/test/mldsa44-import-key-test.sh`:
- Around line 4-7: Remove the early CI gate that checks CI and GITHUB_JOB (the
if block testing [[ "$CI" == "true" ]] && [[ "$GITHUB_JOB" != *"ossl35"* ]] ...
fi) from the mldsa44-import-key-test.sh script so the test isn't prematurely
skipped; rely on the existing OpenSSL version check later in the script (or, if
desired, replace the gate with an explicit CI-only flag check) so jobs with
non-matching GITHUB_JOB names like "linux_ossl_35" no longer get incorrectly
excluded.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4a1a8c2d-4c11-48ec-8a3a-d61fbf6ae81c

📥 Commits

Reviewing files that changed from the base of the PR and between 29965b7 and d60a1e4.

📒 Files selected for processing (18)
  • .github/workflows/ci.yml
  • .gitignore
  • cmake/modules/CompilerOptions.cmake
  • cmake/modules/tests/test_openssl_mldsa.c
  • configure.ac
  • src/bin/util/CMakeLists.txt
  • src/bin/util/Makefile.am
  • src/bin/util/softhsm2-util-ossl.cpp
  • src/bin/util/softhsm2-util-ossl.h
  • src/bin/util/test/CMakeLists.txt
  • src/bin/util/test/Makefile.am
  • src/bin/util/test/mldsa44-import-key-test.sh
  • src/lib/common/log.cpp
  • src/lib/common/log.h
  • src/lib/crypto/CMakeLists.txt
  • src/lib/crypto/OSSLMLDSA.cpp
  • src/lib/crypto/OSSLMLDSAPrivateKey.cpp
  • src/lib/win32/syslog.cpp
✅ Files skipped from review due to trivial changes (6)
  • src/bin/util/test/Makefile.am
  • .gitignore
  • src/lib/common/log.h
  • src/lib/crypto/OSSLMLDSA.cpp
  • src/lib/common/log.cpp
  • src/lib/crypto/CMakeLists.txt
🚧 Files skipped from review as they are similar to previous changes (9)
  • src/bin/util/Makefile.am
  • configure.ac
  • cmake/modules/CompilerOptions.cmake
  • src/bin/util/CMakeLists.txt
  • src/bin/util/test/CMakeLists.txt
  • src/bin/util/softhsm2-util-ossl.h
  • src/lib/win32/syslog.cpp
  • src/lib/crypto/OSSLMLDSAPrivateKey.cpp
  • src/bin/util/softhsm2-util-ossl.cpp

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
src/bin/util/test/mldsa44-import-key-test.sh (3)

127-127: ⚡ Quick win

Quote variable expansions to prevent word splitting.

Multiple cat commands use unquoted variable expansions (e.g., cat $SOFTHSM2_CONF, cat $TOKEN_DIR/token.log). While unlikely to cause issues in practice since the paths are constructed within the script, quoting is best practice and prevents potential issues if paths contain spaces.

♻️ Proposed fix
-cat $SOFTHSM2_CONF
+cat "$SOFTHSM2_CONF"
-  cat $TOKEN_DIR/token.log
+  cat "$TOKEN_DIR"/token.log

Apply the same pattern to lines 149, 157, 162, and 167.

Also applies to: 144-144, 149-149, 157-157, 162-162, 167-167

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/bin/util/test/mldsa44-import-key-test.sh` at line 127, Replace unquoted
variable expansions in the cat commands with quoted expansions to prevent
word-splitting: e.g., change cat $SOFTHSM2_CONF to cat "$SOFTHSM2_CONF" and cat
$TOKEN_DIR/token.log to cat "$TOKEN_DIR/token.log"; apply the same quoting
pattern for the other occurrences mentioned (the other cat invocations using
SOFTHSM2_CONF and TOKEN_DIR) so all variable usages are wrapped in double
quotes.

9-9: 💤 Low value

Consider modernizing command substitution syntax.

The script uses legacy backtick syntax `...` in multiple places (lines 9, 14, 24, 106, 107, 129). The modern $(...) syntax is preferred as it's more readable, nests better, and is recommended by ShellCheck.

♻️ Example conversions
-CWD=`pwd`
+CWD=$(pwd)
-OPENSSL=`command -v "$OPENSSL"`
+OPENSSL=$(command -v "$OPENSSL")
-openssl_version=`openssl version` || exit $?
+openssl_version=$(openssl version) || exit $?

Apply similar changes to lines 106, 107, and 129.

Also applies to: 14-14, 24-24, 106-107, 129-129

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/bin/util/test/mldsa44-import-key-test.sh` at line 9, Replace legacy
backtick command substitutions with modern $(...) form: change occurrences like
the CWD assignment (CWD=`pwd`) and other backtick usages around lines where
variables are set or commands are captured (the instances at lines 14, 24, 106,
107, 129) to use $(pwd) and equivalent $(...) forms; update each variable
assignment and any nested substitutions in the script so they use the $(...)
syntax to improve readability and nesting safety while preserving the exact
command semantics.

136-137: ⚡ Quick win

Remove unused variables.

PASS_URI and KEY_URI are defined but never used in the test. Remove dead code to improve clarity.

♻️ Proposed fix
-PASS_URI=pass:$TOKEN_PIN
-KEY_URI=pkcs11:id=%$TOKEN_ID
 KEY_FILE="$TOKEN_DIR"/openssl_test_key
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/bin/util/test/mldsa44-import-key-test.sh` around lines 136 - 137, The
script defines unused variables PASS_URI and KEY_URI which should be removed;
delete the lines that set PASS_URI=pass:$TOKEN_PIN and
KEY_URI=pkcs11:id=%$TOKEN_ID in the test script (and run a quick search for
PASS_URI / KEY_URI to ensure no remaining references), leaving TOKEN_PIN and
TOKEN_ID intact only if they're used elsewhere. Ensure the script still passes
shellcheck and test runs after removing these dead-variable definitions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmake/modules/tests/test_openssl_mldsa.c`:
- Around line 5-10: The EVP_PKEY_CTX returned by EVP_PKEY_CTX_new_from_name is
not freed; call EVP_PKEY_CTX_free(ctx) after successful allocation (before
returning 0) so the allocated EVP_PKEY_CTX is released; keep the existing NULL
check (return 1 if ctx == NULL) and only free when ctx is non-NULL (i.e., free
the ctx returned by EVP_PKEY_CTX_new_from_name before the successful return).

---

Nitpick comments:
In `@src/bin/util/test/mldsa44-import-key-test.sh`:
- Line 127: Replace unquoted variable expansions in the cat commands with quoted
expansions to prevent word-splitting: e.g., change cat $SOFTHSM2_CONF to cat
"$SOFTHSM2_CONF" and cat $TOKEN_DIR/token.log to cat "$TOKEN_DIR/token.log";
apply the same quoting pattern for the other occurrences mentioned (the other
cat invocations using SOFTHSM2_CONF and TOKEN_DIR) so all variable usages are
wrapped in double quotes.
- Line 9: Replace legacy backtick command substitutions with modern $(...) form:
change occurrences like the CWD assignment (CWD=`pwd`) and other backtick usages
around lines where variables are set or commands are captured (the instances at
lines 14, 24, 106, 107, 129) to use $(pwd) and equivalent $(...) forms; update
each variable assignment and any nested substitutions in the script so they use
the $(...) syntax to improve readability and nesting safety while preserving the
exact command semantics.
- Around line 136-137: The script defines unused variables PASS_URI and KEY_URI
which should be removed; delete the lines that set PASS_URI=pass:$TOKEN_PIN and
KEY_URI=pkcs11:id=%$TOKEN_ID in the test script (and run a quick search for
PASS_URI / KEY_URI to ensure no remaining references), leaving TOKEN_PIN and
TOKEN_ID intact only if they're used elsewhere. Ensure the script still passes
shellcheck and test runs after removing these dead-variable definitions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c822863a-09e3-4799-a6b7-487a38d4fe59

📥 Commits

Reviewing files that changed from the base of the PR and between d60a1e4 and f0323ea.

📒 Files selected for processing (18)
  • .github/workflows/ci.yml
  • .gitignore
  • cmake/modules/CompilerOptions.cmake
  • cmake/modules/tests/test_openssl_mldsa.c
  • configure.ac
  • src/bin/util/CMakeLists.txt
  • src/bin/util/Makefile.am
  • src/bin/util/softhsm2-util-ossl.cpp
  • src/bin/util/softhsm2-util-ossl.h
  • src/bin/util/test/CMakeLists.txt
  • src/bin/util/test/Makefile.am
  • src/bin/util/test/mldsa44-import-key-test.sh
  • src/lib/common/log.cpp
  • src/lib/common/log.h
  • src/lib/crypto/CMakeLists.txt
  • src/lib/crypto/OSSLMLDSA.cpp
  • src/lib/crypto/OSSLMLDSAPrivateKey.cpp
  • src/lib/win32/syslog.cpp
✅ Files skipped from review due to trivial changes (5)
  • .gitignore
  • src/lib/common/log.h
  • src/bin/util/test/Makefile.am
  • src/lib/crypto/CMakeLists.txt
  • src/lib/common/log.cpp
🚧 Files skipped from review as they are similar to previous changes (11)
  • src/bin/util/Makefile.am
  • configure.ac
  • src/bin/util/CMakeLists.txt
  • src/lib/win32/syslog.cpp
  • src/lib/crypto/OSSLMLDSA.cpp
  • src/bin/util/test/CMakeLists.txt
  • cmake/modules/CompilerOptions.cmake
  • src/bin/util/softhsm2-util-ossl.h
  • src/lib/crypto/OSSLMLDSAPrivateKey.cpp
  • .github/workflows/ci.yml
  • src/bin/util/softhsm2-util-ossl.cpp

Comment thread cmake/modules/tests/test_openssl_mldsa.c
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
cmake/modules/tests/test_openssl_mldsa.c (1)

5-10: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Free EVP_PKEY_CTX on the success path.

Line 6 allocates ctx, but Line 10 returns without releasing it. This is still a leak (even in a smoke test).

🛠️ Proposed fix
     if (ctx == NULL)
         return 1;
+    EVP_PKEY_CTX_free(ctx);
     return 0;
#!/bin/bash
rg -n 'EVP_PKEY_CTX_new_from_name|EVP_PKEY_CTX_free' cmake/modules/tests/test_openssl_mldsa.c
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmake/modules/tests/test_openssl_mldsa.c` around lines 5 - 10, The test
allocates an EVP_PKEY_CTX via EVP_PKEY_CTX_new_from_name into the variable ctx
but returns 0 on success without freeing it; modify the success path to call
EVP_PKEY_CTX_free(ctx) before returning (i.e., after confirming ctx != NULL and
before the final return 0) so the EVP_PKEY_CTX is released; ensure you only call
EVP_PKEY_CTX_free when ctx is non-NULL to avoid NULL-free issues.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/bin/util/test/mldsa44-import-key-test.sh`:
- Line 127: Unquoted variable expansions in the script cause word-splitting for
paths with spaces; update every cat invocation that uses the SOFTHSM2_CONF and
TOKEN_DIR variables so they are quoted (e.g., change usages of cat
$SOFTHSM2_CONF to cat "$SOFTHSM2_CONF" and cat $TOKEN_DIR/token.log to cat
"$TOKEN_DIR/token.log"). Locate the occurrences referencing the SOFTHSM2_CONF
variable and the TOKEN_DIR/token.log string in the test script and wrap the
variable expansions in double quotes to prevent splitting and globbing.

---

Duplicate comments:
In `@cmake/modules/tests/test_openssl_mldsa.c`:
- Around line 5-10: The test allocates an EVP_PKEY_CTX via
EVP_PKEY_CTX_new_from_name into the variable ctx but returns 0 on success
without freeing it; modify the success path to call EVP_PKEY_CTX_free(ctx)
before returning (i.e., after confirming ctx != NULL and before the final return
0) so the EVP_PKEY_CTX is released; ensure you only call EVP_PKEY_CTX_free when
ctx is non-NULL to avoid NULL-free issues.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dfe6c029-65c1-40d8-ac55-e58f52815d7a

📥 Commits

Reviewing files that changed from the base of the PR and between f0323ea and 60d2ec0.

📒 Files selected for processing (18)
  • .github/workflows/ci.yml
  • .gitignore
  • cmake/modules/CompilerOptions.cmake
  • cmake/modules/tests/test_openssl_mldsa.c
  • configure.ac
  • src/bin/util/CMakeLists.txt
  • src/bin/util/Makefile.am
  • src/bin/util/softhsm2-util-ossl.cpp
  • src/bin/util/softhsm2-util-ossl.h
  • src/bin/util/test/CMakeLists.txt
  • src/bin/util/test/Makefile.am
  • src/bin/util/test/mldsa44-import-key-test.sh
  • src/lib/common/log.cpp
  • src/lib/common/log.h
  • src/lib/crypto/CMakeLists.txt
  • src/lib/crypto/OSSLMLDSA.cpp
  • src/lib/crypto/OSSLMLDSAPrivateKey.cpp
  • src/lib/win32/syslog.cpp
✅ Files skipped from review due to trivial changes (8)
  • src/bin/util/CMakeLists.txt
  • .gitignore
  • src/lib/crypto/OSSLMLDSA.cpp
  • src/bin/util/test/CMakeLists.txt
  • src/bin/util/test/Makefile.am
  • configure.ac
  • src/bin/util/Makefile.am
  • src/lib/crypto/CMakeLists.txt
🚧 Files skipped from review as they are similar to previous changes (8)
  • src/lib/common/log.h
  • cmake/modules/CompilerOptions.cmake
  • src/lib/crypto/OSSLMLDSAPrivateKey.cpp
  • src/lib/win32/syslog.cpp
  • src/bin/util/softhsm2-util-ossl.h
  • src/lib/common/log.cpp
  • .github/workflows/ci.yml
  • src/bin/util/softhsm2-util-ossl.cpp

Comment thread src/bin/util/test/mldsa44-import-key-test.sh Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/bin/util/test/mldsa44-import-key-test.sh (1)

106-107: ⚡ Quick win

Modernize legacy backticks to $(...) syntax.

Lines 106, 107, and 127 still use backticks for command substitution. Modern shell style prefers $(...) for better readability and nesting support. ShellCheck SC2006 flags these as style issues.

♻️ Proposed fix
-  WINDOWS_TOKEN_DIR=`realpath "$TOKEN_DIR"`
-  WINDOWS_TOKEN_DIR=`cygpath -w "$WINDOWS_TOKEN_DIR"`
+  WINDOWS_TOKEN_DIR=$(realpath "$TOKEN_DIR")
+  WINDOWS_TOKEN_DIR=$(cygpath -w "$WINDOWS_TOKEN_DIR")
-SOFTHSM2_CONF=`realpath "$SOFTHSM2_CONF"`
+SOFTHSM2_CONF=$(realpath "$SOFTHSM2_CONF")

Also applies to: 127-127

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/bin/util/test/mldsa44-import-key-test.sh` around lines 106 - 107, Replace
legacy backtick command substitutions with modern $(...) form for the
assignments to WINDOWS_TOKEN_DIR that use TOKEN_DIR (i.e., change
WINDOWS_TOKEN_DIR=`realpath "$TOKEN_DIR"` and WINDOWS_TOKEN_DIR=`cygpath -w
"$WINDOWS_TOKEN_DIR"` to use $(...) syntax) and also update the other backtick
substitution noted later in the script; preserve existing quoting around
variables and command arguments when converting so behavior remains identical.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/bin/util/test/mldsa44-import-key-test.sh`:
- Line 153: The command uses an unquoted variable expansion: change the cat
invocation that references TOKEN_DIR so the path is quoted (i.e., use "
$TOKEN_DIR/token.log " with proper quoting of the whole expansion) to prevent
word-splitting when TOKEN_DIR contains spaces; update the occurrence that
matches the pattern used on the other lines (the cat command referencing
TOKEN_DIR/token.log) to be consistent with the quoted uses on lines 140, 148,
and 158.

---

Nitpick comments:
In `@src/bin/util/test/mldsa44-import-key-test.sh`:
- Around line 106-107: Replace legacy backtick command substitutions with modern
$(...) form for the assignments to WINDOWS_TOKEN_DIR that use TOKEN_DIR (i.e.,
change WINDOWS_TOKEN_DIR=`realpath "$TOKEN_DIR"` and WINDOWS_TOKEN_DIR=`cygpath
-w "$WINDOWS_TOKEN_DIR"` to use $(...) syntax) and also update the other
backtick substitution noted later in the script; preserve existing quoting
around variables and command arguments when converting so behavior remains
identical.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 85d1cd55-6791-49fb-9949-5f35040895cc

📥 Commits

Reviewing files that changed from the base of the PR and between 60d2ec0 and e7a08d3.

📒 Files selected for processing (18)
  • .github/workflows/ci.yml
  • .gitignore
  • cmake/modules/CompilerOptions.cmake
  • cmake/modules/tests/test_openssl_mldsa.c
  • configure.ac
  • src/bin/util/CMakeLists.txt
  • src/bin/util/Makefile.am
  • src/bin/util/softhsm2-util-ossl.cpp
  • src/bin/util/softhsm2-util-ossl.h
  • src/bin/util/test/CMakeLists.txt
  • src/bin/util/test/Makefile.am
  • src/bin/util/test/mldsa44-import-key-test.sh
  • src/lib/common/log.cpp
  • src/lib/common/log.h
  • src/lib/crypto/CMakeLists.txt
  • src/lib/crypto/OSSLMLDSA.cpp
  • src/lib/crypto/OSSLMLDSAPrivateKey.cpp
  • src/lib/win32/syslog.cpp
✅ Files skipped from review due to trivial changes (9)
  • src/bin/util/Makefile.am
  • src/bin/util/CMakeLists.txt
  • src/lib/crypto/OSSLMLDSA.cpp
  • src/lib/common/log.h
  • .gitignore
  • src/bin/util/test/CMakeLists.txt
  • src/bin/util/test/Makefile.am
  • src/lib/common/log.cpp
  • configure.ac
🚧 Files skipped from review as they are similar to previous changes (7)
  • src/lib/crypto/OSSLMLDSAPrivateKey.cpp
  • src/lib/win32/syslog.cpp
  • cmake/modules/CompilerOptions.cmake
  • src/bin/util/softhsm2-util-ossl.h
  • src/lib/crypto/CMakeLists.txt
  • .github/workflows/ci.yml
  • src/bin/util/softhsm2-util-ossl.cpp

Comment thread src/bin/util/test/mldsa44-import-key-test.sh Outdated
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.

ml-dsa key support for utilities

2 participants