12#include <botan/assert.h>
13#include <botan/p11_types.h>
14#include <botan/internal/dyn_load.h>
34 }
else if(return_value !=
nullptr) {
36 *return_value =
static_cast<ReturnValue>(function_result);
49 if(ptr ==
nullptr && len == 0) {
50 static constexpr Byte empty_input = 0;
51 return const_cast<Byte*
>(&empty_input);
53 return const_cast<Byte*
>(ptr);
66 session.
set_pin(old_pin, new_pin);
72 session.
set_pin(old_so_pin, new_so_pin);
82 m_interface_wrapper([&] {
83 BOTAN_ARG_CHECK(ptr !=
nullptr,
"Function list pointer must not be nullptr");
96 return handle_return_value(m_interface_wrapper.func_2_40().C_Initialize(
const_cast<void*
>(init_args)), return_value);
100 return handle_return_value(m_interface_wrapper.func_2_40().C_Finalize(reserved), return_value);
104 return handle_return_value(m_interface_wrapper.func_2_40().C_GetInfo(info_ptr), return_value);
112 get_function_list get_function_list_ptr = pkcs11_module.
resolve<get_function_list>(
"C_GetFunctionList");
122 if(
auto get_interface_list_ptr = pkcs11_module.
try_resolve_symbol<get_interface_list>(
"C_GetInterfaceList");
123 get_interface_list_ptr.has_value()) {
124 return handle_return_value(get_interface_list_ptr.value()(interface_list_ptr, count_ptr), return_value);
139 get_interface_ptr.has_value()) {
141 get_interface_ptr.value()(
142 const_cast<Utf8Char*
>(interface_name_ptr),
const_cast<Version*
>(version_ptr), interface_ptr_ptr,
flags),
155 return handle_return_value(m_interface_wrapper.func_2_40().C_GetSlotList(token_present, slot_list_ptr, count_ptr),
163 Ulong number_slots = 0;
165 const bool success =
C_GetSlotList(
static_cast<Bbool>(token_present),
nullptr, &number_slots, return_value);
167 if(!success || number_slots == 0) {
172 slot_ids.resize(number_slots);
173 if(!
C_GetSlotList(
static_cast<Bbool>(token_present), slot_ids.data(), &number_slots, return_value)) {
177 slot_ids.resize(std::min<size_t>(slot_ids.size(), number_slots));
182 return handle_return_value(m_interface_wrapper.func_2_40().C_GetSlotInfo(slot_id, info_ptr), return_value);
186 return handle_return_value(m_interface_wrapper.func_2_40().C_GetTokenInfo(slot_id, info_ptr), return_value);
204 std::vector<MechanismType>& mechanisms,
209 Ulong number_mechanisms = 0;
211 const bool success =
C_GetMechanismList(slot_id,
nullptr, &number_mechanisms, return_value);
213 if(!success || number_mechanisms == 0) {
218 mechanisms.resize(number_mechanisms);
220 slot_id,
reinterpret_cast<MechanismType*
>(mechanisms.data()), &number_mechanisms, return_value)) {
224 mechanisms.resize(std::min<size_t>(mechanisms.size(), number_mechanisms));
233 m_interface_wrapper.func_2_40().C_GetMechanismInfo(slot_id,
static_cast<CK_MECHANISM_TYPE>(type), info_ptr),
243 m_interface_wrapper.func_2_40().C_InitToken(
244 slot_id,
const_cast<Utf8Char*
>(so_pin_ptr), so_pin_len,
const_cast<Utf8Char*
>(label_ptr)),
253 m_interface_wrapper.func_2_40().C_InitPIN(session,
const_cast<Utf8Char*
>(pin_ptr), pin_len), return_value);
263 m_interface_wrapper.func_2_40().C_SetPIN(
264 session,
const_cast<Utf8Char*
>(old_pin_ptr), old_len,
const_cast<Utf8Char*
>(new_pin_ptr), new_len),
277 m_interface_wrapper.func_2_40().C_OpenSession(slot_id,
flags, application, notify, session_ptr), return_value);
281 return handle_return_value(m_interface_wrapper.func_2_40().C_CloseSession(session), return_value);
285 return handle_return_value(m_interface_wrapper.func_2_40().C_CloseAllSessions(slot_id), return_value);
289 return handle_return_value(m_interface_wrapper.func_2_40().C_GetSessionInfo(session, info_ptr), return_value);
297 Byte* operation_state_ptr,
298 Ulong* operation_state_len_ptr,
301 m_interface_wrapper.func_2_40().C_GetOperationState(session, operation_state_ptr, operation_state_len_ptr),
306 const Byte* operation_state_ptr,
307 Ulong operation_state_len,
312 m_interface_wrapper.func_2_40().C_SetOperationState(
313 session,
const_cast<Byte*
>(operation_state_ptr), operation_state_len, encryption_key, authentication_key),
320 m_interface_wrapper.func_2_40().C_Login(
336 const_cast<Utf8Char*
>(username_ptr),
342 return handle_return_value(m_interface_wrapper.func_2_40().C_Logout(session), return_value);
349 return handle_return_value(m_interface_wrapper.func_3_2().C_GetSessionValidationFlags(session, type, flags_ptr),
361 m_interface_wrapper.func_2_40().C_CreateObject(session, attribute_template_ptr, count, object_ptr), return_value);
371 m_interface_wrapper.func_2_40().C_CopyObject(session,
object, attribute_template_ptr, count, new_object_ptr),
376 return handle_return_value(m_interface_wrapper.func_2_40().C_DestroyObject(session,
object), return_value);
383 return handle_return_value(m_interface_wrapper.func_2_40().C_GetObjectSize(session,
object, size_ptr), return_value);
392 m_interface_wrapper.func_2_40().C_GetAttributeValue(session,
object, attribute_template_ptr, count),
402 m_interface_wrapper.func_2_40().C_SetAttributeValue(session,
object, attribute_template_ptr, count),
410 return handle_return_value(m_interface_wrapper.func_2_40().C_FindObjectsInit(session, attribute_template_ptr, count),
416 Ulong max_object_count,
417 Ulong* object_count_ptr,
420 m_interface_wrapper.func_2_40().C_FindObjects(session, object_ptr, max_object_count, object_count_ptr),
425 return handle_return_value(m_interface_wrapper.func_2_40().C_FindObjectsFinal(session), return_value);
435 m_interface_wrapper.func_2_40().C_EncryptInit(session,
const_cast<Mechanism*
>(mechanism_ptr), key), return_value);
439 const Byte* data_ptr,
441 Byte* encrypted_data_ptr,
442 Ulong* encrypted_data_len_ptr,
445 m_interface_wrapper.func_2_40().C_Encrypt(
446 session, nonnull_input(data_ptr, data_len), data_len, encrypted_data_ptr, encrypted_data_len_ptr),
451 const Byte* part_ptr,
453 Byte* encrypted_part_ptr,
454 Ulong* encrypted_part_len_ptr,
457 m_interface_wrapper.func_2_40().C_EncryptUpdate(
458 session,
const_cast<Byte*
>(part_ptr), part_len, encrypted_part_ptr, encrypted_part_len_ptr),
463 Byte* last_encrypted_part_ptr,
464 Ulong* last_encrypted_part_len_ptr,
467 m_interface_wrapper.func_2_40().C_EncryptFinal(session, last_encrypted_part_ptr, last_encrypted_part_len_ptr),
478 m_interface_wrapper.func_3_0().C_MessageEncryptInit(session,
const_cast<Mechanism*
>(mechanism_ptr), key),
483 const void* parameter_ptr,
485 const Byte* associated_data_ptr,
486 Ulong associated_data_len,
487 const Byte* plaintext_ptr,
489 Byte* ciphertext_ptr,
490 Ulong* ciphertext_len_ptr,
493 const_cast<void*
>(parameter_ptr),
495 const_cast<Byte*
>(associated_data_ptr),
497 const_cast<Byte*
>(plaintext_ptr),
505 const void* parameter_ptr,
507 const Byte* associated_data_ptr,
508 Ulong associated_data_len,
511 m_interface_wrapper.func_3_0().C_EncryptMessageBegin(session,
512 const_cast<void*
>(parameter_ptr),
514 const_cast<Byte*
>(associated_data_ptr),
515 associated_data_len),
520 const void* parameter_ptr,
522 const Byte* plaintext_part_ptr,
523 Ulong plaintext_part_len,
524 Byte* ciphertext_ptr,
525 Ulong* ciphertext_part_len_ptr,
529 const_cast<void*
>(parameter_ptr),
531 const_cast<Byte*
>(plaintext_part_ptr),
534 ciphertext_part_len_ptr,
540 return handle_return_value(m_interface_wrapper.func_3_0().C_MessageEncryptFinal(session), return_value);
550 m_interface_wrapper.func_2_40().C_DecryptInit(session,
const_cast<Mechanism*
>(mechanism_ptr), key), return_value);
554 const Byte* encrypted_data_ptr,
555 Ulong encrypted_data_len,
560 m_interface_wrapper.func_2_40().C_Decrypt(
561 session,
const_cast<Byte*
>(encrypted_data_ptr), encrypted_data_len, data_ptr, data_len_ptr),
566 const Byte* encrypted_part_ptr,
567 Ulong encrypted_part_len,
572 m_interface_wrapper.func_2_40().C_DecryptUpdate(
573 session,
const_cast<Byte*
>(encrypted_part_ptr), encrypted_part_len, part_ptr, part_len_ptr),
579 Ulong* last_part_len_ptr,
581 return handle_return_value(m_interface_wrapper.func_2_40().C_DecryptFinal(session, last_part_ptr, last_part_len_ptr),
592 m_interface_wrapper.func_3_0().C_MessageDecryptInit(session,
const_cast<Mechanism*
>(mechanism_ptr), key),
597 const void* parameter_ptr,
599 const Byte* associated_data_ptr,
600 Ulong associated_data_len,
601 const Byte* ciphertext_ptr,
602 Ulong ciphertext_len,
604 Ulong* plaintext_len_ptr,
607 const_cast<void*
>(parameter_ptr),
609 const_cast<Byte*
>(associated_data_ptr),
611 const_cast<Byte*
>(ciphertext_ptr),
619 const void* parameter_ptr,
621 const Byte* associated_data_ptr,
622 Ulong associated_data_len,
625 m_interface_wrapper.func_3_0().C_DecryptMessageBegin(session,
626 const_cast<void*
>(parameter_ptr),
628 const_cast<Byte*
>(associated_data_ptr),
629 associated_data_len),
634 const void* parameter_ptr,
636 const Byte* ciphertext_part_ptr,
637 Ulong ciphertext_part_len,
639 Ulong* plaintext_part_len_ptr,
643 m_interface_wrapper.func_3_0().C_DecryptMessageNext(session,
644 const_cast<void*
>(parameter_ptr),
646 const_cast<Byte*
>(ciphertext_part_ptr),
649 plaintext_part_len_ptr,
655 return handle_return_value(m_interface_wrapper.func_3_0().C_MessageDecryptFinal(session), return_value);
666 const Byte* data_ptr,
669 Ulong* digest_len_ptr,
672 session,
const_cast<Byte*
>(data_ptr), data_len, digest_ptr, digest_len_ptr),
677 const Byte* part_ptr,
681 m_interface_wrapper.func_2_40().C_DigestUpdate(session,
const_cast<Byte*
>(part_ptr), part_len), return_value);
685 return handle_return_value(m_interface_wrapper.func_2_40().C_DigestKey(session, key), return_value);
690 Ulong* digest_len_ptr,
692 return handle_return_value(m_interface_wrapper.func_2_40().C_DigestFinal(session, digest_ptr, digest_len_ptr),
703 m_interface_wrapper.func_2_40().C_SignInit(session,
const_cast<Mechanism*
>(mechanism_ptr), key), return_value);
707 const Byte* data_ptr,
710 Ulong* signature_len_ptr,
713 m_interface_wrapper.func_2_40().C_Sign(
714 session, nonnull_input(data_ptr, data_len), data_len, signature_ptr, signature_len_ptr),
719 const Byte* part_ptr,
723 m_interface_wrapper.func_2_40().C_SignUpdate(session, nonnull_input(part_ptr, part_len), part_len), return_value);
728 Ulong* signature_len_ptr,
730 return handle_return_value(m_interface_wrapper.func_2_40().C_SignFinal(session, signature_ptr, signature_len_ptr),
739 m_interface_wrapper.func_2_40().C_SignRecoverInit(session,
const_cast<Mechanism*
>(mechanism_ptr), key),
747 Ulong* signature_len,
750 session,
const_cast<Byte*
>(data), data_len, signature, signature_len),
761 m_interface_wrapper.func_3_0().C_MessageSignInit(session,
const_cast<Mechanism*
>(mechanism_ptr), key),
766 const void* parameter_ptr,
768 const Byte* data_ptr,
771 Ulong* signature_len_ptr,
774 const_cast<void*
>(parameter_ptr),
776 const_cast<Byte*
>(data_ptr),
784 const void* parameter_ptr,
788 m_interface_wrapper.func_3_0().C_SignMessageBegin(session,
const_cast<void*
>(parameter_ptr), parameter_len),
793 const void* parameter_ptr,
795 const Byte* data_ptr,
798 Ulong* signature_len_ptr,
801 const_cast<void*
>(parameter_ptr),
803 const_cast<Byte*
>(data_ptr),
811 return handle_return_value(m_interface_wrapper.func_3_0().C_MessageSignFinal(session), return_value);
821 m_interface_wrapper.func_2_40().C_VerifyInit(session,
const_cast<Mechanism*
>(mechanism_ptr), key), return_value);
825 const Byte* data_ptr,
827 const Byte* signature_ptr,
831 m_interface_wrapper.func_2_40().C_Verify(
832 session, nonnull_input(data_ptr, data_len), data_len,
const_cast<Byte*
>(signature_ptr), signature_len),
837 const Byte* part_ptr,
841 m_interface_wrapper.func_2_40().C_VerifyUpdate(session, nonnull_input(part_ptr, part_len), part_len),
846 const Byte* signature_ptr,
850 m_interface_wrapper.func_2_40().C_VerifyFinal(session,
const_cast<Byte*
>(signature_ptr), signature_len),
859 m_interface_wrapper.func_2_40().C_VerifyRecoverInit(session,
const_cast<Mechanism*
>(mechanism_ptr), key),
864 const Byte* signature_ptr,
870 session,
const_cast<Byte*
>(signature_ptr), signature_len, data_ptr, data_len_ptr),
877 const Byte* signature_ptr,
881 m_interface_wrapper.func_3_2().C_VerifySignatureInit(
882 session,
const_cast<Mechanism*
>(mechanism_ptr), key,
const_cast<Byte*
>(signature_ptr), signature_len),
887 const Byte* data_ptr,
891 m_interface_wrapper.func_3_2().C_VerifySignature(session,
const_cast<Byte*
>(data_ptr), data_len), return_value);
895 const Byte* part_ptr,
899 m_interface_wrapper.func_3_2().C_VerifySignatureUpdate(session,
const_cast<Byte*
>(part_ptr), part_len),
904 return handle_return_value(m_interface_wrapper.func_3_2().C_VerifySignatureFinal(session), return_value);
914 m_interface_wrapper.func_3_0().C_MessageVerifyInit(session,
const_cast<Mechanism*
>(mechanism_ptr), key),
919 const void* parameter_ptr,
921 const Byte* data_ptr,
923 const Byte* signature_ptr,
927 const_cast<void*
>(parameter_ptr),
929 const_cast<Byte*
>(data_ptr),
931 const_cast<Byte*
>(signature_ptr),
937 const void* parameter_ptr,
941 m_interface_wrapper.func_3_0().C_VerifyMessageBegin(session,
const_cast<void*
>(parameter_ptr), parameter_len),
946 const void* parameter_ptr,
948 const Byte* data_ptr,
950 const Byte* signature_ptr,
954 const_cast<void*
>(parameter_ptr),
956 const_cast<Byte*
>(data_ptr),
958 const_cast<Byte*
>(signature_ptr),
964 return handle_return_value(m_interface_wrapper.func_3_0().C_MessageVerifyFinal(session), return_value);
970 const Byte* part_ptr,
972 Byte* encrypted_part_ptr,
973 Ulong* encrypted_part_len_ptr,
976 m_interface_wrapper.func_2_40().C_DigestEncryptUpdate(
977 session,
const_cast<Byte*
>(part_ptr), part_len, encrypted_part_ptr, encrypted_part_len_ptr),
982 const Byte* encrypted_part_ptr,
983 Ulong encrypted_part_len,
988 m_interface_wrapper.func_2_40().C_DecryptDigestUpdate(
989 session,
const_cast<Byte*
>(encrypted_part_ptr), encrypted_part_len, part_ptr, part_len_ptr),
994 const Byte* part_ptr,
996 Byte* encrypted_part_ptr,
997 Ulong* encrypted_part_len_ptr,
1000 m_interface_wrapper.func_2_40().C_SignEncryptUpdate(
1001 session,
const_cast<Byte*
>(part_ptr), part_len, encrypted_part_ptr, encrypted_part_len_ptr),
1006 const Byte* encrypted_part_ptr,
1007 Ulong encrypted_part_len,
1009 Ulong* part_len_ptr,
1012 m_interface_wrapper.func_2_40().C_DecryptVerifyUpdate(
1013 session,
const_cast<Byte*
>(encrypted_part_ptr), encrypted_part_len, part_ptr, part_len_ptr),
1026 m_interface_wrapper.func_2_40().C_GenerateKey(
1027 session,
const_cast<Mechanism*
>(mechanism_ptr), attribute_template_ptr, count, key_ptr),
1034 Ulong public_key_attribute_count,
1036 Ulong private_key_attribute_count,
1042 public_key_template_ptr,
1043 public_key_attribute_count,
1044 private_key_template_ptr,
1045 private_key_attribute_count,
1055 Byte* wrapped_key_ptr,
1056 Ulong* wrapped_key_len_ptr,
1059 m_interface_wrapper.func_2_40().C_WrapKey(
1060 session,
const_cast<Mechanism*
>(mechanism_ptr), wrapping_key, key, wrapped_key_ptr, wrapped_key_len_ptr),
1067 const Byte* wrapped_key_ptr,
1068 Ulong wrapped_key_len,
1070 Ulong attribute_count,
1076 const_cast<Byte*
>(wrapped_key_ptr),
1078 attribute_template_ptr,
1088 Ulong attribute_count,
1092 m_interface_wrapper.func_2_40().C_DeriveKey(
1093 session,
const_cast<Mechanism*
>(mechanism_ptr), base_key, attribute_template_ptr, attribute_count, key_ptr),
1101 const Byte* associated_data_ptr,
1102 Ulong associated_data_len,
1103 Byte* wrapped_key_ptr,
1104 Ulong* wrapped_key_len_ptr,
1107 m_interface_wrapper.func_3_2().C_WrapKeyAuthenticated(session,
1111 const_cast<Byte*
>(associated_data_ptr),
1112 associated_data_len,
1114 wrapped_key_len_ptr),
1121 const Byte* wrapped_key_ptr,
1122 Ulong wrapped_key_len,
1124 Ulong attribute_count,
1125 const Byte* associated_data_ptr,
1126 Ulong associated_data_len,
1130 m_interface_wrapper.func_3_2().C_UnwrapKeyAuthenticated(session,
1133 const_cast<Byte*
>(wrapped_key_ptr),
1135 attribute_template_ptr,
1137 const_cast<Byte*
>(associated_data_ptr),
1138 associated_data_len,
1147 Ulong attribute_count,
1148 Byte* ciphertext_ptr,
1149 Ulong* ciphertext_len_ptr,
1167 Ulong attribute_count,
1168 const Byte* ciphertext_ptr,
1169 Ulong ciphertext_len,
1177 const_cast<Byte*
>(ciphertext_ptr),
1186 const Byte* seed_ptr,
1190 m_interface_wrapper.func_2_40().C_SeedRandom(session,
const_cast<Byte*
>(seed_ptr), seed_len), return_value);
1194 Byte* random_data_ptr,
1197 return handle_return_value(m_interface_wrapper.func_2_40().C_GenerateRandom(session, random_data_ptr, random_len),
1204 return handle_return_value(m_interface_wrapper.func_2_40().C_GetFunctionStatus(session), return_value);
1208 return handle_return_value(m_interface_wrapper.func_2_40().C_CancelFunction(session), return_value);
1218 m_interface_wrapper.func_3_2().C_AsyncComplete(session,
const_cast<Utf8Char*
>(function_name_ptr), result_ptr),
1227 m_interface_wrapper.func_3_2().C_AsyncGetID(session,
const_cast<Utf8Char*
>(function_name_ptr), id_ptr),
1238 session,
const_cast<Utf8Char*
>(function_name_ptr),
id, data_ptr, data_len),
1243 return reinterpret_cast<FunctionList*
>(m_interface_wrapper.raw_interface().pFunctionList);
#define BOTAN_ARG_CHECK(expr, msg)
std::optional< PtrT > try_resolve_symbol(const std::string &symbol) const
PtrT resolve(const std::string &symbol) const
Wraps a PKCS #11 Interface object.
static Utf8Char * p11_interface_name_ptr()
bool C_VerifyMessage(SessionHandle session, const void *parameter_ptr, Ulong parameter_len, const Byte *data_ptr, Ulong data_len, const Byte *signature_ptr, Ulong signature_len, ReturnValue *return_value=ThrowException)
bool C_CancelFunction(SessionHandle session, ReturnValue *return_value=ThrowException) const
static bool C_GetInterface(const Dynamically_Loaded_Library &pkcs11_module, const Utf8Char *interface_name_ptr, const Version *version_ptr, Interface **interface_ptr_ptr, Flags flags, ReturnValue *return_value=ThrowException)
bool C_MessageSignFinal(SessionHandle session, ReturnValue *return_value=ThrowException)
bool C_EncryptMessageBegin(SessionHandle session, const void *parameter_ptr, Ulong parameter_len, const Byte *associated_data_ptr, Ulong associated_data_len, ReturnValue *return_value=ThrowException)
bool C_SignEncryptUpdate(SessionHandle session, const Byte *part_ptr, Ulong part_len, Byte *encrypted_part_ptr, Ulong *encrypted_part_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_GetSessionInfo(SessionHandle session, SessionInfo *info_ptr, ReturnValue *return_value=ThrowException) const
bool C_VerifySignatureInit(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle key, const Byte *signature_ptr, Ulong signature_len, ReturnValue *return_value=ThrowException)
bool C_Logout(SessionHandle session, ReturnValue *return_value=ThrowException) const
bool C_MessageEncryptFinal(SessionHandle session, ReturnValue *return_value=ThrowException)
bool C_WrapKey(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle wrapping_key, ObjectHandle key, Byte *wrapped_key_ptr, Ulong *wrapped_key_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_InitPIN(SessionHandle session, const Utf8Char *pin_ptr, Ulong pin_len, ReturnValue *return_value=ThrowException) const
bool C_GetOperationState(SessionHandle session, Byte *operation_state_ptr, Ulong *operation_state_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_DigestKey(SessionHandle session, ObjectHandle key, ReturnValue *return_value=ThrowException) const
bool C_DecryptUpdate(SessionHandle session, const Byte *encrypted_part_ptr, Ulong encrypted_part_len, Byte *part_ptr, Ulong *part_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_MessageDecryptFinal(SessionHandle session, ReturnValue *return_value=ThrowException)
bool C_GetTokenInfo(SlotId slot_id, TokenInfo *info_ptr, ReturnValue *return_value=ThrowException) const
bool C_SetAttributeValue(SessionHandle session, ObjectHandle object, Attribute *attribute_template_ptr, Ulong count, ReturnValue *return_value=ThrowException) const
bool C_VerifyMessageNext(SessionHandle session, const void *parameter_ptr, Ulong parameter_len, const Byte *data_ptr, Ulong data_len, const Byte *signature_ptr, Ulong signature_len, ReturnValue *return_value=ThrowException)
bool C_SignRecover(SessionHandle session, const Byte *data_ptr, Ulong data_len, Byte *signature_ptr, Ulong *signature_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_MessageDecryptInit(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle key, ReturnValue *return_value=ThrowException)
bool C_DecryptFinal(SessionHandle session, Byte *last_part_ptr, Ulong *last_part_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_VerifyRecover(SessionHandle session, const Byte *signature_ptr, Ulong signature_len, Byte *data_ptr, Ulong *data_len_ptr, ReturnValue *return_value=ThrowException) const
static bool C_GetFunctionList(const Dynamically_Loaded_Library &pkcs11_module, FunctionList **function_list_ptr_ptr, ReturnValue *return_value=ThrowException)
bool C_EncapsulateKey(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle public_key, Attribute *template_ptr, Ulong attribute_count, Byte *ciphertext_ptr, Ulong *ciphertext_len_ptr, ObjectHandle *key_ptr, ReturnValue *return_value=ThrowException)
bool C_InitToken(SlotId slot_id, const Utf8Char *so_pin_ptr, Ulong so_pin_len, const Utf8Char *label_ptr, ReturnValue *return_value=ThrowException) const
bool C_GetSlotInfo(SlotId slot_id, SlotInfo *info_ptr, ReturnValue *return_value=ThrowException) const
bool C_EncryptFinal(SessionHandle session, Byte *last_encrypted_part_ptr, Ulong *last_encrypted_part_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_FindObjectsInit(SessionHandle session, Attribute *attribute_template_ptr, Ulong count, ReturnValue *return_value=ThrowException) const
bool C_VerifyUpdate(SessionHandle session, const Byte *part_ptr, Ulong part_len, ReturnValue *return_value=ThrowException) const
bool C_GetAttributeValue(SessionHandle session, ObjectHandle object, Attribute *attribute_template_ptr, Ulong count, ReturnValue *return_value=ThrowException) const
bool C_DestroyObject(SessionHandle session, ObjectHandle object, ReturnValue *return_value=ThrowException) const
bool C_VerifyMessageBegin(SessionHandle session, const void *parameter_ptr, Ulong parameter_len, ReturnValue *return_value=ThrowException)
bool C_Login(SessionHandle session, UserType user_type, const Utf8Char *pin_ptr, Ulong pin_len, ReturnValue *return_value=ThrowException) const
bool C_CopyObject(SessionHandle session, ObjectHandle object, Attribute *attribute_template_ptr, Ulong count, ObjectHandle *new_object_ptr, ReturnValue *return_value=ThrowException) const
bool C_EncryptMessage(SessionHandle session, const void *parameter_ptr, Ulong parameter_len, const Byte *associated_data_ptr, Ulong associated_data_len, const Byte *plaintext_ptr, Ulong plaintext_len, Byte *ciphertext_ptr, Ulong *ciphertext_len_ptr, ReturnValue *return_value=ThrowException)
bool C_GenerateRandom(SessionHandle session, Byte *random_data_ptr, Ulong random_len, ReturnValue *return_value=ThrowException) const
LowLevel(FunctionList *ptr)
bool C_VerifySignature(SessionHandle session, const Byte *data_ptr, Ulong data_len, ReturnValue *return_value=ThrowException)
bool C_EncryptMessageNext(SessionHandle session, const void *parameter_ptr, Ulong parameter_len, const Byte *plaintext_part_ptr, Ulong plaintext_part_len, Byte *ciphertext_ptr, Ulong *ciphertext_part_len_ptr, Flags flags, ReturnValue *return_value=ThrowException)
bool C_Sign(SessionHandle session, const Byte *data_ptr, Ulong data_len, Byte *signature_ptr, Ulong *signature_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_DecryptMessage(SessionHandle session, const void *parameter_ptr, Ulong parameter_len, const Byte *associated_data_ptr, Ulong associated_data_len, const Byte *ciphertext_ptr, Ulong ciphertext_len, Byte *plaintext_ptr, Ulong *plaintext_len_ptr, ReturnValue *return_value=ThrowException)
bool C_GetFunctionStatus(SessionHandle session, ReturnValue *return_value=ThrowException) const
bool C_AsyncGetID(SessionHandle session, const Utf8Char *function_name_ptr, Ulong *id_ptr, ReturnValue *return_value=ThrowException)
bool C_CloseSession(SessionHandle session, ReturnValue *return_value=ThrowException) const
const InterfaceWrapper & get_interface()
bool C_Initialize(const void *init_args, ReturnValue *return_value=ThrowException) const
bool C_Encrypt(SessionHandle session, const Byte *data_ptr, Ulong data_len, Byte *encrypted_data, Ulong *encrypted_data_len_ptr, ReturnValue *return_value=ThrowException) const
static bool C_GetInterfaceList(const Dynamically_Loaded_Library &pkcs11_module, Interface *interface_list_ptr, Ulong *count_ptr, ReturnValue *return_value=ThrowException)
bool C_LoginUser(SessionHandle session, UserType user_type, const Utf8Char *pin_ptr, Ulong pin_len, const Utf8Char *username_ptr, Ulong username_len, ReturnValue *return_value=ThrowException)
bool C_SignUpdate(SessionHandle session, const Byte *part_ptr, Ulong part_len, ReturnValue *return_value=ThrowException) const
bool C_DecapsulateKey(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle private_key, Attribute *template_ptr, Ulong attribute_count, const Byte *ciphertext_ptr, Ulong ciphertext_len, ObjectHandle *key_ptr, ReturnValue *return_value=ThrowException)
bool C_GetInfo(Info *info_ptr, ReturnValue *return_value=ThrowException) const
bool C_GetMechanismList(SlotId slot_id, MechanismType *mechanism_list_ptr, Ulong *count_ptr, ReturnValue *return_value=ThrowException) const
bool C_WaitForSlotEvent(Flags flags, SlotId *slot_ptr, void *reserved, ReturnValue *return_value=ThrowException) const
bool C_MessageVerifyInit(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle key, ReturnValue *return_value=ThrowException)
bool C_GetSessionValidationFlags(SessionHandle session, Ulong type, Flags *flags_ptr, ReturnValue *return_value=ThrowException)
bool C_OpenSession(SlotId slot_id, Flags flags, void *application, Notify notify, SessionHandle *session_ptr, ReturnValue *return_value=ThrowException) const
bool C_FindObjectsFinal(SessionHandle session, ReturnValue *return_value=ThrowException) const
static bool handle_return_value(CK_RV function_result, ReturnValue *return_value)
bool C_Decrypt(SessionHandle session, const Byte *encrypted_data_ptr, Ulong encrypted_data_len, Byte *data_ptr, Ulong *data_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_DigestInit(SessionHandle session, const Mechanism *mechanism_ptr, ReturnValue *return_value=ThrowException) const
bool C_VerifySignatureFinal(SessionHandle session, ReturnValue *return_value=ThrowException)
bool C_AsyncComplete(SessionHandle session, const Utf8Char *function_name_ptr, AsyncData *result_ptr, ReturnValue *return_value=ThrowException)
bool C_DecryptInit(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle key, ReturnValue *return_value=ThrowException) const
bool C_MessageSignInit(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle key, ReturnValue *return_value=ThrowException)
bool C_SessionCancel(SessionHandle session, Flags flags, ReturnValue *return_value=ThrowException)
bool C_CloseAllSessions(SlotId slot_id, ReturnValue *return_value=ThrowException) const
bool C_AsyncJoin(SessionHandle session, const Utf8Char *function_name_ptr, Ulong id, Byte *data_ptr, Ulong data_len, ReturnValue *return_value=ThrowException)
bool C_SeedRandom(SessionHandle session, const Byte *seed_ptr, Ulong seed_len, ReturnValue *return_value=ThrowException) const
bool C_CreateObject(SessionHandle session, Attribute *attribute_template_ptr, Ulong count, ObjectHandle *object_ptr, ReturnValue *return_value=ThrowException) const
bool C_Finalize(void *reserved, ReturnValue *return_value=ThrowException) const
bool C_SignMessageNext(SessionHandle session, const void *parameter_ptr, Ulong parameter_len, const Byte *data_ptr, Ulong data_len, Byte *signature_ptr, Ulong *signature_len_ptr, ReturnValue *return_value=ThrowException)
bool C_FindObjects(SessionHandle session, ObjectHandle *object_ptr, Ulong max_object_count, Ulong *object_count_ptr, ReturnValue *return_value=ThrowException) const
bool C_GenerateKeyPair(SessionHandle session, const Mechanism *mechanism_ptr, Attribute *public_key_template_ptr, Ulong public_key_attribute_count, Attribute *private_key_template_ptr, Ulong private_key_attribute_count, ObjectHandle *public_key_ptr, ObjectHandle *private_key_ptr, ReturnValue *return_value=ThrowException) const
bool C_UnwrapKeyAuthenticated(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle unwrapping_key, const Byte *wrapped_key_ptr, Ulong wrapped_key_len, Attribute *attribute_template_ptr, Ulong attribute_count, const Byte *associated_data_ptr, Ulong associated_data_len, ObjectHandle *key_ptr, ReturnValue *return_value=ThrowException) const
bool C_VerifyInit(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle key, ReturnValue *return_value=ThrowException) const
bool C_GetSlotList(Bbool token_present, SlotId *slot_list_ptr, Ulong *count_ptr, ReturnValue *return_value=ThrowException) const
bool C_GetMechanismInfo(SlotId slot_id, MechanismType type, MechanismInfo *info_ptr, ReturnValue *return_value=ThrowException) const
bool C_DigestEncryptUpdate(SessionHandle session, const Byte *part_ptr, Ulong part_len, Byte *encrypted_part_ptr, Ulong *encrypted_part_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_DecryptMessageNext(SessionHandle session, const void *parameter_ptr, Ulong parameter_len, const Byte *ciphertext_part_ptr, Ulong ciphertext_part_len, Byte *plaintext_ptr, Ulong *plaintext_part_len_ptr, Flags flags, ReturnValue *return_value=ThrowException)
bool C_SignMessage(SessionHandle session, const void *parameter_ptr, Ulong parameter_len, const Byte *data_ptr, Ulong data_len, Byte *signature_ptr, Ulong *signature_len_ptr, ReturnValue *return_value=ThrowException)
bool C_SetPIN(SessionHandle session, const Utf8Char *old_pin_ptr, Ulong old_len, const Utf8Char *new_pin_ptr, Ulong new_len, ReturnValue *return_value=ThrowException) const
bool C_VerifyFinal(SessionHandle session, const Byte *signature_ptr, Ulong signature_len, ReturnValue *return_value=ThrowException) const
bool C_Digest(SessionHandle session, const Byte *data_ptr, Ulong data_len, Byte *digest_ptr, Ulong *digest_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_MessageVerifyFinal(SessionHandle session, ReturnValue *return_value=ThrowException)
FunctionList * get_functions() const
bool C_UnwrapKey(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle unwrapping_key, const Byte *wrapped_key_ptr, Ulong wrapped_key_len, Attribute *attribute_template_ptr, Ulong attribute_count, ObjectHandle *key_ptr, ReturnValue *return_value=ThrowException) const
bool C_VerifySignatureUpdate(SessionHandle session, const Byte *part_ptr, Ulong part_len, ReturnValue *return_value=ThrowException)
bool C_EncryptInit(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle key, ReturnValue *return_value=ThrowException) const
bool C_WrapKeyAuthenticated(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle wrapping_key, ObjectHandle key, const Byte *associated_data_ptr, Ulong associated_data_len, Byte *wrapped_key_ptr, Ulong *wrapped_key_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_SignFinal(SessionHandle session, Byte *signature_ptr, Ulong *signature_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_SignMessageBegin(SessionHandle session, const void *parameter_ptr, Ulong parameter_len, ReturnValue *return_value=ThrowException)
bool C_MessageEncryptInit(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle key, ReturnValue *return_value=ThrowException)
bool C_VerifyRecoverInit(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle key, ReturnValue *return_value=ThrowException) const
bool C_DigestUpdate(SessionHandle session, const Byte *part_ptr, Ulong part_len, ReturnValue *return_value=ThrowException) const
bool C_SignInit(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle key, ReturnValue *return_value=ThrowException) const
bool C_DigestFinal(SessionHandle session, Byte *digest_ptr, Ulong *digest_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_Verify(SessionHandle session, const Byte *data_ptr, Ulong data_len, const Byte *signature_ptr, Ulong signature_len, ReturnValue *return_value=ThrowException) const
bool C_GetObjectSize(SessionHandle session, ObjectHandle object, Ulong *size_ptr, ReturnValue *return_value=ThrowException) const
bool C_SetOperationState(SessionHandle session, const Byte *operation_state_ptr, Ulong operation_state_len, ObjectHandle encryption_key, ObjectHandle authentication_key, ReturnValue *return_value=ThrowException) const
bool C_GenerateKey(SessionHandle session, const Mechanism *mechanism_ptr, Attribute *attribute_template_ptr, Ulong count, ObjectHandle *key_ptr, ReturnValue *return_value=ThrowException) const
bool C_EncryptUpdate(SessionHandle session, const Byte *part_ptr, Ulong part_len, Byte *encrypted_part_ptr, Ulong *encrypted_part_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_DecryptMessageBegin(SessionHandle session, const void *parameter_ptr, Ulong parameter_len, const Byte *associated_data_ptr, Ulong associated_data_len, ReturnValue *return_value=ThrowException)
bool C_DecryptDigestUpdate(SessionHandle session, const Byte *encrypted_part_ptr, Ulong encrypted_part_len, Byte *part_ptr, Ulong *part_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_SignRecoverInit(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle key, ReturnValue *return_value=ThrowException) const
bool C_DecryptVerifyUpdate(SessionHandle session, const Byte *encrypted_part_ptr, Ulong encrypted_part_len, Byte *part_ptr, Ulong *part_len_ptr, ReturnValue *return_value=ThrowException) const
bool C_DeriveKey(SessionHandle session, const Mechanism *mechanism_ptr, ObjectHandle base_key, Attribute *attribute_template_ptr, Ulong attribute_count, ObjectHandle *key_ptr, ReturnValue *return_value=ThrowException) const
Represents a PKCS#11 session.
void set_pin(const secure_string &old_pin, const secure_string &new_pin)
Calls C_SetPIN to change the PIN using the old PIN (requires a logged in session).
void init_pin(const secure_string &new_pin)
Calls C_InitPIN to change or initialize the PIN using the SO_PIN (requires a logged in session).
void login(UserType userType, const secure_string &pin)
Represents a PKCS#11 Slot, i.e., a card reader.
void initialize(std::string_view label, const secure_string &so_pin) const
ReturnValue * ThrowException
secure_vector< uint8_t > secure_string
CK_FUNCTION_LIST FunctionList
void change_pin(Slot &slot, const secure_string &old_pin, const secure_string &new_pin)
CK_OBJECT_HANDLE ObjectHandle
void change_so_pin(Slot &slot, const secure_string &old_so_pin, const secure_string &new_so_pin)
CK_SESSION_INFO SessionInfo
void set_pin(Slot &slot, const secure_string &so_pin, const secure_string &pin)
CK_MECHANISM_INFO MechanismInfo
void initialize_token(Slot &slot, std::string_view label, const secure_string &so_pin, const secure_string &pin)
CK_SESSION_HANDLE SessionHandle
#define CKR_GENERAL_ERROR
CK_MECHANISM_TYPE * CK_MECHANISM_TYPE_PTR
CK_ULONG CK_MECHANISM_TYPE