![]() | Cryptographic Token Interface Standard |
PKCS#11 |
Cryptoki provides the following functions for signing data (for the purposes of Cryptoki, these operations also encompass message authentication codes):
CK_RV C_SignInit( CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, CK_OBJECT_HANDLE hKey);
C_SignInit initializes a signature operation, where the signature is an appendix to the data.
hSession | is the session's handle; |
pMechanism | points to the signature mechanism; |
hKey | is the handle of the signature key. |
After calling C_SignInit, the application can either call C_Sign to sign in a single part; or call C_SignUpdate one or more times, followed by C_SignFinal, to sign data in multiple parts. The signature operation is active until the application uses a call to C_Sign or C_SignFinal to actually obtain the signature. To process additional data (in single or multiple parts), the application must call C_SignInit again.
CK_RV C_Sign( CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDataLen, CK_BYTE_PTR pSignature, CK_ULONG_PTR pulSignatureLen);
C_Sign signs data in a single part, where the signature is an appendix to the data.
hSession | is the session's handle; |
pData | points to the data; |
ulDataLen | is the length of the data; |
pSignature | points to the location that receives the signature; |
pulSignatureLen | points to the location that holds the length of the signature. |
The signing operation must have been initialized with C_SignInit. A call to C_Sign always terminates the active signing operation unless it returns CKR_BUFFER_TOO_SMALL or is a successful call (i.e., one which returns CKR_OK) to determine the length of the buffer needed to hold the signature.
C_Sign can not be used to terminate a multi-part operation, and must be called after C_SignInit without intervening C_SignUpdate calls.
For most mechanisms, C_Sign is equivalent to a sequence of C_SignUpdate operations followed by C_SignFinal.
CK_RV C_SignUpdate( CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, CK_ULONG ulPartLen);
C_SignUpdate continues a multiple-part signature operation, processing another data part.
hSession | is the session's handle, pPart points to the data part; |
ulPartLen | is the length of the data part. |
CK_RV C_SignFinal( CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSignature, CK_ULONG_PTR pulSignatureLen);
C_SignFinal finishes a multiple-part signature operation, returning the signature.
hSession | is the session's handle; |
pSignature | points to the location that receives the signature; |
pulSignatureLen | points to the location that holds the length of the signature. |
The signing operation must have been initialized with C_SignInit. A call to C_SignFinal always terminates the active signing operation unless it returns CKR_BUFFER_TOO_SMALL or is a successful call (i.e., one which returns CKR_OK) to determine the length of the buffer needed to hold the signature.
CK_SESSION_HANDLE hSession; CK_OBJECT_HANDLE hKey; CK_MECHANISM mechanism = { CKM_DES_MAC, NULL_PTR, 0 }; CK_BYTE data[] = {...}; CK_BYTE mac[4]; CK_ULONG ulMacLen; CK_RV rv; . . rv = C_SignInit(hSession, &mechanism, hKey); if (rv == CKR_OK) { rv = C_SignUpdate(hSession, data, sizeof(data)); . . ulMacLen = sizeof(mac); rv = C_SignFinal(hSession, mac, &ulMacLen); . . }
CK_RV C_SignRecoverInit( CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, CK_OBJECT_HANDLE hKey);
C_SignRecoverInit initializes a signature operation, where the data can be recovered from the signature.
hSession | is the session's handle; |
pMechanism | points to the structure that specifies the signature mechanism; |
hKey | is the handle of the signature key. |
After calling C_SignRecoverInit, the application may call C_SignRecover to sign in a single part. The signature operation is active until the application uses a call to C_SignRecover to actually obtain the signature. To process additional data in a single part, the application must call C_SignRecoverInit again.
CK_RV C_SignRecover( CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDataLen, CK_BYTE_PTR pSignature, CK_ULONG_PTR pulSignatureLen);
C_SignRecover signs data in a single operation, where the data can be recovered from the signature.
hSession | is the session's handle; |
pData | points to the data; |
ulDataLen | is the length of the data; |
pSignature | points to the location that receives the signature; |
pulSignatureLen | points to the location that holds the length of the signature. |
The signing operation must have been initialized with C_SignRecoverInit. A call to C_SignRecover always terminates the active signing operation unless it returns CKR_BUFFER_TOO_SMALL or is a successful call (i.e., one which returns CKR_OK) to determine the length of the buffer needed to hold the signature.
CK_SESSION_HANDLE hSession; CK_OBJECT_HANDLE hKey; CK_MECHANISM mechanism = { CKM_RSA_9796, NULL_PTR, 0 }; CK_BYTE data[] = {...}; CK_BYTE signature[128]; CK_ULONG ulSignatureLen; CK_RV rv; . . rv = C_SignRecoverInit(hSession, &mechanism, hKey); if (rv == CKR_OK) { ulSignatureLen = sizeof(signature); rv = C_SignRecover( hSession, data, sizeof(data), signature, &ulSignatureLen); if (rv == CKR_OK) { . . } }