Skip to content

Add SHA-1, SHA-384, and SHA-512 digest mechanisms - #687

Merged
Jens Topp (jenstopp) merged 3 commits into
feature/pkcs11from
feat/pkcs11-digest
Sep 11, 2026
Merged

Add SHA-1, SHA-384, and SHA-512 digest mechanisms#687
Jens Topp (jenstopp) merged 3 commits into
feature/pkcs11from
feat/pkcs11-digest

Conversation

@jenstopp

Copy link
Copy Markdown
Collaborator

Complete the digest surface the mechanism table advertises. The digests run host-side as self-contained FIPS 180-4 cores.

Why?
PKCS#11 and the device disagree about when hashing is allowed.

C_Digest is a public-session operation: any caller may hash without ever calling C_Login (pkcs11-tool does exactly that, and so do TLS stacks hashing a certificate). The HSM-SDK digest, on the other hand, only works inside an open AZIHSM session and in our design a device session is the login: C_Login maps to (lazily provision, then) sess_open. So "just call the SDK" would leave two options, both bad: fail every not-logged-in digest call (breaks the spec and every tool), or provision and open a device session just to hash public data. That's why digests run on the host.

Why boilerplate code to reimplement SHA?
The module deliberately links no libcrypto: Staying off libcrypto also avoids the SDK/global-libctx interaction we already had to work around in the OpenSSL provider. A digest is keyless public computation, so there's no security argument for the device either.

Copilot AI left a comment

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.

Pull request overview

This PR extends the AZIHSM PKCS#11 module to fully advertise and support host-side digest mechanisms (SHA-1/SHA-256/SHA-384/SHA-512), while introducing a substantial initial PKCS#11 “framework + login slice” implementation (sessions, slot/token/mech enumeration, host-side object store, HSM binding, and generated stubs) and CI/validation scaffolding.

Changes:

  • Add a new plugins/azihsm_pkcs11 PKCS#11 module (C implementation built via a Rust “orchestration crate” + CMake/Corrosion) with complete exported entrypoints (most returning CKR_FUNCTION_NOT_SUPPORTED for now).
  • Implement host-side SHA-1/SHA-256/SHA-384/SHA-512 digests (FIPS 180-4 cores) and validation via a NIST-vector KAT harness plus a dedicated GitHub Actions workflow.
  • Update repo tooling/CI to accommodate the new plugin (copyright stamping exemptions for vendored headers, add workspace member, add workflows/branch triggers).

Reviewed changes

Copilot reviewed 38 out of 38 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
xtask/src/copyright.rs Skip copyright stamping for vendored third-party header directory.
plugins/azihsm_pkcs11/tools/pkcs11f_signatures.tsv Canonical PKCS#11 v3.1 function signatures used for stub generation.
plugins/azihsm_pkcs11/tools/gen_stubs.py Generator producing C stubs for unimplemented PKCS#11 entrypoints.
plugins/azihsm_pkcs11/tests/run_validation.sh Local validation script driving pkcs11-tool + digest KAT + optional pkcs11test.
plugins/azihsm_pkcs11/tests/digest_kat_test.c Standalone C known-answer tests for digest cores (NIST FIPS 180-4 vectors).
plugins/azihsm_pkcs11/src/lib.rs Rust crate placeholder documenting build-only orchestration intent.
plugins/azihsm_pkcs11/src/azihsm_pkcs11_stubs.c Generated stubs for unimplemented PKCS#11 functions (complete symbol surface).
plugins/azihsm_pkcs11/src/azihsm_pkcs11_status.h Declares AZIHSM-status → CK_RV translation API.
plugins/azihsm_pkcs11/src/azihsm_pkcs11_status.c Implements AZIHSM-status → CK_RV mapping table.
plugins/azihsm_pkcs11/src/azihsm_pkcs11_slot.c Slot/token/mechanism enumeration including digest mechanisms.
plugins/azihsm_pkcs11/src/azihsm_pkcs11_session.c Session lifecycle, login state machine, host-side digest entrypoints, object delegation.
plugins/azihsm_pkcs11/src/azihsm_pkcs11_objstore.h Defines host-side object-store vtable seam.
plugins/azihsm_pkcs11/src/azihsm_pkcs11_objstore_mem.c Implements in-memory object store backend.
plugins/azihsm_pkcs11/src/azihsm_pkcs11_module.c Module-global state and core PKCS#11 general functions/helpers.
plugins/azihsm_pkcs11/src/azihsm_pkcs11_internal.h Shared internal types/constants and global module state definition.
plugins/azihsm_pkcs11/src/azihsm_pkcs11_hsm.h HSM-binding interface used by framework layer.
plugins/azihsm_pkcs11/src/azihsm_pkcs11_hsm.c Real-device binding (AZIHSM_WITH_HSM) and no-device stubs.
plugins/azihsm_pkcs11/src/azihsm_pkcs11_dispatch.c Exposes CK_FUNCTION_LIST / CK_FUNCTION_LIST_3_0 and interface enumeration.
plugins/azihsm_pkcs11/src/azihsm_pkcs11_digest.h Host-side digest operation API surface.
plugins/azihsm_pkcs11/src/azihsm_pkcs11_digest.c Self-contained SHA-1/SHA-256/SHA-512(+SHA-384) implementations.
plugins/azihsm_pkcs11/src/azihsm_pkcs11_config.h Environment-based configuration struct and loader declaration.
plugins/azihsm_pkcs11/src/azihsm_pkcs11_config.c Loads provisioning configuration from environment with simulator defaults.
plugins/azihsm_pkcs11/src/azihsm_pkcs11_compat.h Centralizes PKCS#11 platform macros and packing behavior.
plugins/azihsm_pkcs11/README.md Documents layering, build, configuration, and current support surface.
plugins/azihsm_pkcs11/include/pkcs11-v3.1/pkcs11f.h Vendored PKCS#11 v3.1 upstream header.
plugins/azihsm_pkcs11/include/pkcs11-v3.1/pkcs11.h Vendored PKCS#11 v3.1 upstream header.
plugins/azihsm_pkcs11/CMakeLists.txt CMake build wiring via Corrosion + OpenSSL dependency and install rules.
plugins/azihsm_pkcs11/Cargo.toml Adds the build-orchestration crate to the workspace.
plugins/azihsm_pkcs11/build.rs Drives the CMake build and copies the produced .so into Cargo target dir.
Cargo.toml Registers plugins/azihsm_pkcs11 as a workspace member.
api/native/cbindgen.toml Adjusts generated C header prologue formatting to line comments.
.github/workflows/rust.yml Adds feature/pkcs11 branch to workflow triggers.
.github/workflows/pkcs11.yml New workflow to build and drive the PKCS#11 module + digest KAT on Ubuntu.
.github/workflows/fw_uno.yml Adds feature/pkcs11 branch to workflow triggers.
.github/workflows/coverage.yml Adds feature/pkcs11 branch to workflow triggers.
.github/workflows/codeql.yml Adds feature/pkcs11 branch to workflow triggers.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread plugins/azihsm_pkcs11/src/azihsm_pkcs11_objstore_mem.c
Comment thread plugins/azihsm_pkcs11/src/azihsm_pkcs11_objstore_mem.c
@jenstopp
Jens Topp (jenstopp) changed the base branch from main to feature/pkcs11 September 2, 2026 08:55
Comment thread plugins/azihsm_pkcs11/src/azihsm_pkcs11_session.c Outdated
Comment thread plugins/azihsm_pkcs11/src/azihsm_pkcs11_digest.c Outdated
Comment thread plugins/azihsm_pkcs11/src/azihsm_pkcs11_digest.c
Comment thread plugins/azihsm_pkcs11/src/azihsm_pkcs11_digest.c
Comment thread plugins/azihsm_pkcs11/src/azihsm_pkcs11_digest.c
Comment thread plugins/azihsm_pkcs11/src/azihsm_pkcs11_digest.c Outdated
Complete the digest surface the mechanism table advertises. The digests
run host-side as self-contained FIPS 180-4 cores: the SDK digest needs a
logged-in AZIHSM session, while PKCS#11 digests must work in public
sessions, and the no-device build stays free of libcrypto.

- Move the SHA-256 core out of the session layer into a new
  azihsm_pkcs11_digest.{h,c} pair, add SHA-1 and SHA-512/384 cores, and
  put them behind a mechanism-keyed operation API that
  C_DigestInit/Update/Digest/Final dispatch through.
- Reject mechanism parameters on the (parameterless) digest mechanisms
  with CKR_MECHANISM_PARAM_INVALID.
- Add a NIST known-answer test (tests/digest_kat_test.c) covering the
  FIPS 180-4 example vectors per algorithm, one-shot and chunked across
  the block boundaries, run by run_validation.sh and a new CI job.
- Drive all four mechanisms against coreutils in the pkcs11-tool CI step.
…explicit switch cases, defensive guards + state wipe, CI out-dir
@jenstopp
Jens Topp (jenstopp) merged commit b74f980 into feature/pkcs11 Sep 11, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants