C_GetSlotList
Enumerates the slots available in the system.If
CK_TRUE, return only slots that contain a token. If CK_FALSE, return all slots including the empty placeholder slot.Pointer to a buffer that receives the array of slot IDs. Pass
NULL_PTR on the first call to obtain the required count without filling a buffer.On input, the size of
pSlotList (ignored when pSlotList is NULL_PTR). On output, the number of slot IDs written (or the total count when pSlotList is NULL_PTR).CKR_OK, CKR_BUFFER_TOO_SMALL, CKR_CRYPTOKI_NOT_INITIALIZED, CKR_ARGUMENTS_BAD.
Call this function twice: once with pSlotList = NULL_PTR to get the count, allocate a buffer, then call again to fill it.
C_GetSlotInfo
Returns descriptive information about a single slot.The ID of the slot to query.
Pointer to a
CK_SLOT_INFO structure that receives the slot description, manufacturer ID, hardware/firmware versions, and flags such as CKF_TOKEN_PRESENT and CKF_REMOVABLE_DEVICE.CKR_OK, CKR_SLOT_ID_INVALID, CKR_CRYPTOKI_NOT_INITIALIZED, CKR_ARGUMENTS_BAD.
C_GetTokenInfo
Returns detailed information about the token in a given slot.The ID of the slot whose token you want to query.
Pointer to a
CK_TOKEN_INFO structure that receives the token label, manufacturer ID, model, serial number, session counts, PIN lengths, memory statistics, and flags (such as CKF_TOKEN_INITIALIZED, CKF_USER_PIN_INITIALIZED, CKF_LOGIN_REQUIRED).CKR_OK, CKR_SLOT_ID_INVALID, CKR_TOKEN_NOT_PRESENT, CKR_TOKEN_NOT_RECOGNIZED, CKR_CRYPTOKI_NOT_INITIALIZED, CKR_ARGUMENTS_BAD.
C_GetMechanismList
Returns the list of cryptographic mechanisms supported by a token.The ID of the slot whose token’s mechanism list you want.
Buffer to receive the array of
CK_MECHANISM_TYPE values. Pass NULL_PTR on the first call to obtain the count only.On input, the capacity of
pMechanismList. On output, the number of mechanisms available.CKR_OK, CKR_BUFFER_TOO_SMALL, CKR_SLOT_ID_INVALID, CKR_TOKEN_NOT_PRESENT, CKR_CRYPTOKI_NOT_INITIALIZED, CKR_ARGUMENTS_BAD.
SoftHSM v2 supports mechanisms including AES (CBC, GCM, CTR, CCM, key wrap), 3DES, RSA (PKCS, OAEP, PSS), DSA, ECDSA, ECDH, EdDSA, DH, GOST, HMAC (SHA-1/224/256/384/512), and digest algorithms. See Mechanisms for the full list.
C_GetMechanismInfo
Returns information about a specific mechanism supported by a token.The ID of the slot whose token supports the mechanism.
The mechanism type to query, for example
CKM_RSA_PKCS or CKM_AES_CBC.Pointer to a
CK_MECHANISM_INFO structure that receives the minimum and maximum key sizes (in bits) and the flags indicating what operations the mechanism supports (CKF_ENCRYPT, CKF_SIGN, CKF_GENERATE_KEY_PAIR, and so on).CKR_OK, CKR_MECHANISM_INVALID, CKR_SLOT_ID_INVALID, CKR_TOKEN_NOT_PRESENT, CKR_CRYPTOKI_NOT_INITIALIZED, CKR_ARGUMENTS_BAD.
C_InitToken
Initializes a token in a slot, erasing any previously stored objects and resetting all PINs.The ID of the slot to initialize. If the slot already contains a token, all objects on the token are destroyed.
The Security Officer (SO) PIN as a UTF-8 byte array. Not null-terminated.
Length in bytes of
pPin.A 32-byte space-padded UTF-8 label for the token. Shorter labels must be right-padded with spaces (
0x20).CKR_OK, CKR_SLOT_ID_INVALID, CKR_PIN_INCORRECT (wrong SO PIN when re-initializing), CKR_SESSION_EXISTS (open sessions prevent re-initialization), CKR_CRYPTOKI_NOT_INITIALIZED, CKR_ARGUMENTS_BAD.
After C_InitToken succeeds the token is in an uninitialized state — the user PIN does not yet exist. Call C_InitPIN in an SO session to set it.
C_InitPIN
Sets the user PIN for a token. Must be called from a read/write SO session opened afterC_InitToken.
Handle of an open read/write SO session (
CKS_RW_SO_FUNCTIONS state).The initial user PIN as a UTF-8 byte array. Not null-terminated.
Length in bytes of
pPin. Must fall within the token’s ulMinPinLen and ulMaxPinLen as reported by C_GetTokenInfo.CKR_OK, CKR_SESSION_HANDLE_INVALID, CKR_USER_NOT_LOGGED_IN (session is not an SO session), CKR_PIN_LEN_RANGE, CKR_TOKEN_WRITE_PROTECTED, CKR_CRYPTOKI_NOT_INITIALIZED, CKR_ARGUMENTS_BAD.
C_SetPIN
Changes the PIN of the currently logged-in user, or the SO PIN when called from an SO session.Handle of an open read/write session. The session must be in
CKS_RW_USER_FUNCTIONS or CKS_RW_SO_FUNCTIONS state.The current PIN as a UTF-8 byte array.
Length in bytes of
pOldPin.The new PIN as a UTF-8 byte array.
Length in bytes of
pNewPin. Must satisfy the token’s PIN length constraints.CKR_OK, CKR_SESSION_HANDLE_INVALID, CKR_PIN_INCORRECT, CKR_PIN_LEN_RANGE, CKR_SESSION_READ_ONLY, CKR_TOKEN_WRITE_PROTECTED, CKR_CRYPTOKI_NOT_INITIALIZED, CKR_ARGUMENTS_BAD.
C_WaitForSlotEvent
Blocks until a slot event (such as a token insertion or removal) occurs, or returns immediately if one is already pending.If
CKF_DONT_BLOCK is set, the function returns immediately even if no event has occurred, returning CKR_NO_EVENT. If 0, the call blocks.Receives the ID of the slot on which the event occurred.
Reserved for future use. Must be
NULL_PTR.CKR_OK, CKR_NO_EVENT (non-blocking, no event pending), CKR_FUNCTION_NOT_SUPPORTED (SoftHSM v2 does not generate hardware slot events; use polling with CKF_DONT_BLOCK), CKR_CRYPTOKI_NOT_INITIALIZED, CKR_ARGUMENTS_BAD.
SoftHSM v2 does not generate real-time slot events because there is no physical hardware. Use
CKF_DONT_BLOCK and poll C_GetSlotList or C_GetTokenInfo to detect changes.Example: slot enumeration
The following example enumerates all slots that contain a token and prints their labels.Call C_GetSlotList with NULL_PTR
Pass
NULL_PTR as pSlotList to retrieve the count of available slots without allocating memory.Call C_GetSlotList again
Pass the allocated buffer and count. The function fills the array with slot IDs.