Signing functions
C_SignInit
Initializes a signing operation on a session. You must call this beforeC_Sign, C_SignUpdate, or C_SignFinal.
Handle of the open session.
Pointer to a
CK_MECHANISM structure identifying the signing algorithm. Some mechanisms require parameters (for example, CK_RSA_PKCS_PSS_PARAMS for PSS).Handle of the private key (or secret key for MAC mechanisms). The key must have
CKA_SIGN set to CK_TRUE.MacSignInit for MAC mechanisms or AsymSignInit for asymmetric mechanisms.
C_Sign
Signs data in a single-part operation.Data to sign. For combined hash-and-sign mechanisms (e.g.,
CKM_SHA256_RSA_PKCS), this is the raw message. For raw mechanisms (e.g., CKM_RSA_PKCS, CKM_ECDSA), this is the pre-computed digest.Buffer to receive the signature. Pass
NULL_PTR on the first call to obtain the required buffer size.On input: size of
pSignature. On output: number of bytes written (or required size if pSignature is NULL_PTR).C_SignUpdate / C_SignFinal
Multi-part signing — feed the data incrementally, then finalize.Multi-part signing is only available for mechanisms that include internal hashing (for example,
CKM_SHA256_RSA_PKCS, CKM_DSA_SHA256, CKM_ECDSA_SHA256). Raw mechanisms like CKM_RSA_PKCS and CKM_ECDSA are single-part only (bAllowMultiPartOp = false in the source).C_SignRecoverInit / C_SignRecover
Sign with message recovery (RSA only). The signature output contains the embedded message soC_VerifyRecover can extract it without the original data.
Verification functions
C_VerifyInit / C_Verify
Initialize and perform single-part signature verification.CKA_VERIFY set to CK_TRUE. C_Verify returns CKR_OK on a valid signature or CKR_SIGNATURE_INVALID / CKR_SIGNATURE_LEN_RANGE on failure.
C_VerifyUpdate / C_VerifyFinal
Multi-part verification.C_VerifyRecoverInit / C_VerifyRecover
Verify a signature and recover the embedded message.Supported signing mechanisms
RSA
| Mechanism | Hash | Multi-part | Notes |
|---|---|---|---|
CKM_RSA_PKCS | External (pre-hash) | No | PKCS#1 v1.5 raw sign |
CKM_SHA1_RSA_PKCS | SHA-1 | Yes | |
CKM_SHA224_RSA_PKCS | SHA-224 | Yes | |
CKM_SHA256_RSA_PKCS | SHA-256 | Yes | |
CKM_SHA384_RSA_PKCS | SHA-384 | Yes | |
CKM_SHA512_RSA_PKCS | SHA-512 | Yes | |
CKM_MD5_RSA_PKCS | MD5 | Yes | Not available in FIPS mode |
CKM_RSA_PKCS_PSS | External (pre-hash) | No | PSS with explicit params; requires WITH_RAW_PSS build |
CKM_SHA1_RSA_PKCS_PSS | SHA-1 | Yes | PSS |
CKM_SHA224_RSA_PKCS_PSS | SHA-224 | Yes | PSS |
CKM_SHA256_RSA_PKCS_PSS | SHA-256 | Yes | PSS |
CKM_SHA384_RSA_PKCS_PSS | SHA-384 | Yes | PSS |
CKM_SHA512_RSA_PKCS_PSS | SHA-512 | Yes | PSS |
CKM_RSA_X_509 | External | No | Raw RSA (no padding) |
DSA
| Mechanism | Hash | Multi-part |
|---|---|---|
CKM_DSA | External | No |
CKM_DSA_SHA1 | SHA-1 | Yes |
CKM_DSA_SHA224 | SHA-224 | Yes |
CKM_DSA_SHA256 | SHA-256 | Yes |
CKM_DSA_SHA384 | SHA-384 | Yes |
CKM_DSA_SHA512 | SHA-512 | Yes |
ECDSA
| Mechanism | Hash | Multi-part | Notes |
|---|---|---|---|
CKM_ECDSA | External (pre-hash) | No | |
CKM_ECDSA_SHA1 | SHA-1 | No | |
CKM_ECDSA_SHA224 | SHA-224 | No | |
CKM_ECDSA_SHA256 | SHA-256 | No | |
CKM_ECDSA_SHA384 | SHA-384 | No | |
CKM_ECDSA_SHA512 | SHA-512 | No |
The ECDSA-with-hash mechanisms (
CKM_ECDSA_SHA256 etc.) were added in SoftHSM v2.7.0. Earlier versions only supported CKM_ECDSA with an externally computed digest.EdDSA
| Mechanism | Notes |
|---|---|
CKM_EDDSA | Ed25519 and Ed448; single-part only; requires WITH_EDDSA build |
GOST
| Mechanism | Hash | Notes |
|---|---|---|
CKM_GOSTR3410 | External | Requires WITH_GOST build |
CKM_GOSTR3410_WITH_GOSTR3411 | GOST R 34.11-94 | Multi-part; requires WITH_GOST build |
MAC mechanisms
MAC mechanisms useC_SignInit / C_Sign with a secret key rather than a private key. The key must have CKA_SIGN.
| Mechanism | Key type |
|---|---|
CKM_SHA_1_HMAC | CKK_GENERIC_SECRET or CKK_SHA_1_HMAC |
CKM_SHA256_HMAC | CKK_GENERIC_SECRET |
CKM_SHA384_HMAC | CKK_GENERIC_SECRET |
CKM_SHA512_HMAC | CKK_GENERIC_SECRET |
CKM_AES_CMAC | CKK_AES |
CKM_DES3_CMAC | CKK_DES2 or CKK_DES3 |
Mechanism parameters
CK_RSA_PKCS_PSS_PARAMS
Required for all PSS mechanisms.CKM_SHA256_RSA_PKCS_PSS the params must specify hashAlg = CKM_SHA256 and mgf = CKG_MGF1_SHA256. For CKM_RSA_PKCS_PSS (raw PSS), any of the supported hash algorithms may be chosen.
Error codes
| Return value | Meaning |
|---|---|
CKR_OK | Success |
CKR_ARGUMENTS_BAD | Missing or malformed mechanism parameters |
CKR_KEY_FUNCTION_NOT_PERMITTED | The key does not have CKA_SIGN / CKA_VERIFY |
CKR_KEY_TYPE_INCONSISTENT | Key type does not match mechanism |
CKR_BUFFER_TOO_SMALL | Output buffer too small |
CKR_SIGNATURE_INVALID | Signature verification failed |
CKR_SIGNATURE_LEN_RANGE | Signature length is wrong for the mechanism |
CKR_OPERATION_ACTIVE | Another operation is already in progress |
CKR_OPERATION_NOT_INITIALIZED | C_SignInit / C_VerifyInit has not been called |
CKR_USER_NOT_LOGGED_IN | Key requires re-authentication (CKA_ALWAYS_AUTHENTICATE) |