Craton HSM

PKCS#11 API Reference

PKCS#11 API Reference

Craton HSM ships as a shared library (craton_hsm.dll on Windows, libcraton_hsm.so on Linux, libcraton_hsm.dylib on macOS) that exports the PKCS#11 v3.0 C ABI. Any PKCS#11 v2.40 consumer will work; the v3.0 additions that are implemented are listed at the bottom of this page.

All entry points are declared #[no_mangle] extern "C". The function pointer table is returned from C_GetFunctionList and follows the CK_FUNCTION_LIST layout in the OASIS specification.

General-purpose functions

FunctionPurpose
C_InitializeInitialise the Cryptoki library. Runs Power-On Self-Tests (17 tests: integrity plus 16 KATs). On POST failure, leaves the module in an error state until a subsequent C_Initialize succeeds.
C_FinalizeRelease resources allocated by C_Initialize. Closes all sessions and unloads token state.
C_GetInfoReturn library version, manufacturer ID (Craton Software), Cryptoki version (3.0), and library description.
C_GetFunctionListReturn the function pointer table.

Slot and token management

FunctionPurpose
C_GetSlotListEnumerate slots. Craton HSM presents a single slot per token configured in craton_hsm.toml.
C_GetSlotInfoReport slot flags (CKF_TOKEN_PRESENT, CKF_REMOVABLE_DEVICE = 0, CKF_HW_SLOT = 0), manufacturer, and firmware version.
C_GetTokenInfoReport label, manufacturer, model, serial number, flags, PIN length bounds, session limits, and free memory counters.
C_GetMechanismListReturn the supported mechanisms filtered by algorithm policy. In default mode this is 41 entries; in FIPS approved mode the PQC mechanisms, Ed25519, and SHA-1 are suppressed.
C_GetMechanismInfoReturn min/max key size and permitted operations for a specific mechanism.
C_InitTokenInitialise a token with an SO PIN and a label. Wipes existing key material on a re-initialised token.
C_WaitForSlotEventUnsupported. Returns CKR_FUNCTION_NOT_SUPPORTED — Craton HSM has no removable-slot concept.

PIN management

FunctionPurpose
C_InitPINSecurity Officer initialises the User PIN after C_InitToken. Requires an R/W SO session.
C_SetPINChange the PIN of whichever role is currently logged in (or the User PIN if not logged in, matching the PKCS#11 v3.0 semantics). PIN hashing uses PBKDF2-HMAC-SHA256 (600 000 iterations by default).

Session management

FunctionPurpose
C_OpenSessionOpen a read-only or read-write session on a slot. Sessions are tracked in a DashMap for safe concurrent access.
C_CloseSessionClose a single session. Active cryptographic operations on that session are cancelled and their intermediate state zeroised.
C_CloseAllSessionsClose all sessions on a slot.
C_GetSessionInfoReturn session state (CKS_RO_PUBLIC_SESSION, CKS_RW_USER_FUNCTIONS, etc.), slot ID, and flags.
C_LoginAuthenticate as CKU_USER or CKU_SO. CKU_CONTEXT_SPECIFIC is honoured for CKA_ALWAYS_AUTHENTICATE keys. PIN comparison is constant-time (subtle::ConstantTimeEq).
C_LogoutEnd the authenticated state for the session's token.
C_GetOperationStateSerialise the active operation with an HMAC-authenticated envelope. Supported for digest and multi-part sign/verify streams.
C_SetOperationStateRestore a serialised operation. The HMAC is validated before any state is applied.

Object management

FunctionPurpose
C_CreateObjectCreate an object from a template. Used for importing keys, certificates, and data objects.
C_DestroyObjectDelete an object. Enforces CKA_DESTROYABLE. Zeroises key material on removal.
C_CopyObjectDuplicate an object with template overrides.
C_GetObjectSizeReturn the approximate in-memory size of an object.
C_GetAttributeValueRead one or more attributes. Sensitive attributes (CKA_VALUE on secret keys, private key components) are never returned if CKA_SENSITIVE = CK_TRUE or CKA_EXTRACTABLE = CK_FALSE.
C_SetAttributeValueModify attributes subject to CKA_MODIFIABLE. Sensitivity transitions are one-way: once CKA_SENSITIVE = CK_TRUE, it cannot be cleared.
C_FindObjectsInitStart a search filtered by an attribute template. Results are confined to the current session's view (public objects on any session, private objects only when logged in).
C_FindObjectsIterate search results.
C_FindObjectsFinalEnd the search and free its iterator state.

Encryption

FunctionPurpose
C_EncryptInitInitialise encryption with the given mechanism and key. Rejects all-zero IVs for AES-CBC / CBC-PAD / CTR. Enforces lifecycle state and CKA_ENCRYPT.
C_EncryptSingle-part encrypt.
C_EncryptUpdateMulti-part encrypt. Supported for CKM_AES_CBC, CKM_AES_CBC_PAD, CKM_AES_CTR. Not supported for CKM_AES_GCM or CKM_RSA_PKCS_OAEP.
C_EncryptFinalFinalise a multi-part encrypt.

Decryption

FunctionPurpose
C_DecryptInitInitialise decryption. Enforces lifecycle state (deactivated keys may decrypt) and CKA_DECRYPT.
C_DecryptSingle-part decrypt.
C_DecryptUpdateMulti-part decrypt. Same mechanism set as C_EncryptUpdate.
C_DecryptFinalFinalise a multi-part decrypt.

Digest

FunctionPurpose
C_DigestInitInitialise a digest. SHA-1 is permitted for digest-only operations outside FIPS approved mode.
C_DigestSingle-part digest.
C_DigestUpdateMulti-part digest.
C_DigestKeyInclude a key's raw value in the running digest.
C_DigestFinalFinalise and return the digest.

Signing and verification

FunctionPurpose
C_SignInitInitialise signing. Enforces lifecycle state and CKA_SIGN.
C_SignSingle-part sign.
C_SignUpdateMulti-part sign. Supported for CKM_SHA*_RSA_PKCS, CKM_SHA*_RSA_PKCS_PSS, CKM_ECDSA_SHA*.
C_SignFinalFinalise a multi-part sign.
C_SignRecoverInitUnsupported. Returns CKR_FUNCTION_NOT_SUPPORTED.
C_SignRecoverUnsupported.
C_VerifyInitInitialise verification. Permitted on deactivated keys.
C_VerifySingle-part verify.
C_VerifyUpdateMulti-part verify.
C_VerifyFinalFinalise a multi-part verify.
C_VerifyRecoverInitUnsupported.
C_VerifyRecoverUnsupported.

Dual-purpose cryptographic functions

Craton HSM exports these stubs for ABI completeness but does not implement the combined operations. Each returns CKR_FUNCTION_NOT_SUPPORTED.

FunctionStatus
C_DigestEncryptUpdateUnsupported
C_DecryptDigestUpdateUnsupported
C_SignEncryptUpdateUnsupported
C_DecryptVerifyUpdateUnsupported

Consumers that need these combinations should drive the component operations on parallel sessions.

Key management

FunctionPurpose
C_GenerateKeyGenerate a symmetric key (CKM_AES_KEY_GEN). All generation routes through the DRBG.
C_GenerateKeyPairGenerate an asymmetric key pair (RSA, EC, Ed25519, ML-KEM, ML-DSA, SLH-DSA). Each pair is followed by a pairwise consistency test (sign/verify or encap/decap roundtrip); failure aborts the generation and enters the error state.
C_WrapKeyWrap a key under another key. CKM_AES_KEY_WRAP (RFC 3394) and CKM_AES_KEY_WRAP_KWP (RFC 5649) are supported. The source key must have CKA_EXTRACTABLE = CK_TRUE.
C_UnwrapKeyImport a wrapped key. Resulting keys default to CKA_EXTRACTABLE = CK_FALSE unless the template says otherwise.
C_DeriveKeyDerive a key via ECDH (CKM_ECDH1_DERIVE, CKM_ECDH1_COFACTOR_DERIVE) with an internal HKDF-SHA256 per SP 800-56C, or via a PQC KEM (CKM_ML_KEM_*, CKM_HYBRID_X25519_ML_KEM_768).

Random number generation

FunctionPurpose
C_GenerateRandomDraw bytes from the SP 800-90A HMAC_DRBG. See DRBG.
C_SeedRandomMix caller-supplied entropy into the DRBG as additional input. Never replaces OS entropy.

Parallel functions

Parallel functions are legacy PKCS#11 v1 holdovers. Craton HSM returns CKR_FUNCTION_NOT_PARALLEL / CKR_FUNCTION_NOT_SUPPORTED.

FunctionStatus
C_GetFunctionStatusReturns CKR_FUNCTION_NOT_PARALLEL
C_CancelFunctionReturns CKR_FUNCTION_NOT_PARALLEL

Notification callbacks

Session notification callbacks passed to C_OpenSession are accepted but never invoked — Craton HSM has no asynchronous events to deliver. The callback pointer is stored and discarded on C_CloseSession.

PKCS#11 v3.0 additions

FeatureStatus
C_GetInterfaceList / C_GetInterfaceNot yet implemented. Consumers that require v3.0 interface negotiation must load through C_GetFunctionList and treat the library as v2.40-compatible.
C_LoginUser (variant with pUsername)Not yet implemented.
C_SessionCancelNot yet implemented.
C_MessageEncryptInit / C_EncryptMessage / C_MessageEncryptFinal (message-based API)Not yet implemented.
New v3.0 mechanisms (CKM_EDDSA, AES-GCM message API)CKM_EDDSA as a mechanism is implemented; the message-based variant is not.

These are tracked as gaps and will be addressed before 1.0. Consumers depending on a specific v3.0 addition should check the changelog or raise an issue.

Deviations from the specification

  • C_InitPIN requires an R/W SO session — the spec allows implementations to reject this, and Craton HSM does.
  • C_SetAttributeValue cannot clear CKA_SENSITIVE once set, matching PKCS#11 v3.0 §5.7.
  • CKA_ALWAYS_AUTHENTICATE keys demand a CKU_CONTEXT_SPECIFIC login between every use.
  • All-zero IVs are rejected at C_EncryptInit for AES-CBC and AES-CTR (a conservative extension of the spec, closing a known misuse pattern).
  • Pairwise consistency tests run after every key pair generation; failure triggers POST-failed state (§9.6 of FIPS 140-3 IG).

Loading the library

# OpenSC pkcs11-tool
pkcs11-tool --module /opt/craton_hsm/libcraton_hsm.so --list-slots

# p11-kit
p11-kit list-modules

See Integrations for OpenSSL, Java, NSS, Vault, and Kubernetes examples.