corePKCS11 v3.1.0
PKCS #11 Cryptoki Library
core_pkcs11.c File Reference

corePKCS11 Interface. More...

#include "core_pkcs11_config.h"
#include "core_pkcs11.h"
#include <stdio.h>
#include <stdint.h>
#include <string.h>

Functions

static CK_RV prvOpenSession (CK_SESSION_HANDLE *pxSession, CK_SLOT_ID xSlotId)
 Open a PKCS #11 Session. More...
 
CK_RV xGetSlotList (CK_SLOT_ID **ppxSlotId, CK_ULONG *pxSlotCount)
 Get a list of available PKCS #11 slots. More...
 
CK_RV xInitializePKCS11 (void)
 Initializes a PKCS #11 session. More...
 
CK_RV xInitializePkcs11Token (void)
 Initializes a PKCS #11 module and token. More...
 
CK_RV xInitializePkcs11Session (CK_SESSION_HANDLE *pxSession)
 Initializes the PKCS #11 module and opens a session. More...
 
CK_RV xFindObjectWithLabelAndClass (CK_SESSION_HANDLE xSession, char *pcLabelName, CK_ULONG ulLabelNameLen, CK_OBJECT_CLASS xClass, CK_OBJECT_HANDLE_PTR pxHandle)
 Searches for an object with a matching label and class provided. More...
 
CK_RV vAppendSHA256AlgorithmIdentifierSequence (const uint8_t *puc32ByteHashedMessage, uint8_t *puc51ByteHashOidBuffer)
 Appends digest algorithm sequence to SHA-256 hash for RSA signatures. More...
 

Detailed Description

corePKCS11 Interface.

This file contains wrapper functions for common PKCS #11 operations.

Function Documentation

◆ prvOpenSession()

static CK_RV prvOpenSession ( CK_SESSION_HANDLE *  pxSession,
CK_SLOT_ID  xSlotId 
)
static

Open a PKCS #11 Session.

Parameters
[out]pxSessionPointer to the session handle to be created.
[out]xSlotIdSlot ID to be used for the session.
Returns
CKR_OK or PKCS #11 error code. (PKCS #11 error codes are positive).

◆ xGetSlotList()

CK_RV xGetSlotList ( CK_SLOT_ID **  ppxSlotId,
CK_ULONG *  pxSlotCount 
)

Get a list of available PKCS #11 slots.

Note
This function allocates memory for slots. Freeing this memory is the responsibility of the caller.
Parameters
[out]ppxSlotIdPointer to slot list. This slot list is malloc'ed by the function and must be freed by the caller.
[out]pxSlotCountPointer to the number of slots found.
Returns
CKR_OK or PKCS #11 error code. (PKCS #11 error codes are positive).

◆ xInitializePKCS11()

CK_RV xInitializePKCS11 ( void  )

Initializes a PKCS #11 session.

Returns
CKR_OK if successful.

◆ xInitializePkcs11Token()

CK_RV xInitializePkcs11Token ( void  )

Initializes a PKCS #11 module and token.

Returns
CKR_OK upon success. PKCS #11 error code on failure. Note that PKCS #11 error codes are positive.

◆ xInitializePkcs11Session()

CK_RV xInitializePkcs11Session ( CK_SESSION_HANDLE *  pxSession)

Initializes the PKCS #11 module and opens a session.

Parameters
[out]pxSessionPointer to the PKCS #11 session handle that is created by this function.
Returns
CKR_OK upon success. PKCS #11 error code on failure. Note that PKCS #11 error codes are positive.

◆ xFindObjectWithLabelAndClass()

CK_RV xFindObjectWithLabelAndClass ( CK_SESSION_HANDLE  xSession,
char *  pcLabelName,
CK_ULONG  ulLabelNameLen,
CK_OBJECT_CLASS  xClass,
CK_OBJECT_HANDLE_PTR  pxHandle 
)

Searches for an object with a matching label and class provided.

Parameters
[in]xSessionAn open PKCS #11 session.
[in]pcLabelNameA pointer to the object's label (CKA_LABEL).
[in]ulLabelNameLenThe size (in bytes) of pcLabelName.
[in]xClassThe class (CKA_CLASS) of the object. ex: CKO_PUBLIC_KEY, CKO_PRIVATE_KEY, CKO_CERTIFICATE
[out]pxHandlePointer to the location where the handle of the found object should be placed.
Note
If no matching object is found, pxHandle will point to an object with handle 0 (Invalid Object Handle).
This function assumes that there is only one object that meets the CLASS/LABEL criteria.

◆ vAppendSHA256AlgorithmIdentifierSequence()

CK_RV vAppendSHA256AlgorithmIdentifierSequence ( const uint8_t *  puc32ByteHashedMessage,
uint8_t *  puc51ByteHashOidBuffer 
)

Appends digest algorithm sequence to SHA-256 hash for RSA signatures.

This function pre-appends the digest algorithm identifier to the SHA-256 hash of a message.

DigestInfo :: = SEQUENCE{ digestAlgorithm DigestAlgorithmIdentifier, digest Digest }

Parameters
[in]puc32ByteHashedMessageA 32-byte buffer containing the SHA-256 hash of the data to be signed.
[out]puc51ByteHashOidBufferA 51-byte output buffer containing the DigestInfo structure. This memory must be allocated by the caller.
Returns
CKR_OK if successful, CKR_ARGUMENTS_BAD if NULL pointer passed in.