libp11 0.4.21
libp11.h
Go to the documentation of this file.
1/* libp11, a simple layer on top of PKCS#11 API
2 * Copyright (C) 2005 Olaf Kirch <okir@lst.de>
3 * Copyright © 2025-2026 Mobi - Com Polska Sp. z o.o.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
24
25#ifndef _LIB11_H
26#define _LIB11_H
27
28#include "p11_ver.h"
29#include "p11_err.h"
30#include <openssl/bio.h>
31#include <openssl/err.h>
32#include <openssl/bn.h>
33#include <openssl/rsa.h>
34#include <openssl/x509.h>
35#include <openssl/evp.h>
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41#define PKCS11_FLAG_NO_METHODS 1
42
43int ERR_load_CKR_strings(void);
44void ERR_unload_CKR_strings(void);
45void ERR_CKR_error(int function, int reason, char *file, int line);
46# define CKRerr(f,r) ERR_CKR_error((f),(r),__FILE__,__LINE__)
47int ERR_get_CKR_code(void);
48
49/*
50 * The purpose of this library is to provide a simple PKCS#11
51 * interface to OpenSSL application. It was never a goal
52 * of this project to expose the entire PKCS#11 functionality.
53 */
54
55/* opaque type declarations */
56typedef struct pkcs11_object_private PKCS11_OBJECT_private;
57typedef struct pkcs11_slot_private PKCS11_SLOT_private;
58typedef struct pkcs11_ctx_private PKCS11_CTX_private;
59
60/* forward type declarations */
61typedef struct PKCS11_key_st PKCS11_KEY;
62typedef struct PKCS11_cert_st PKCS11_CERT;
63typedef struct PKCS11_token_st PKCS11_TOKEN;
64typedef struct PKCS11_slot_st PKCS11_SLOT;
65typedef struct PKCS11_ctx_st PKCS11_CTX;
66typedef struct PKCS11_ec_kgen_st PKCS11_EC_KGEN;
67typedef struct PKCS11_nid_kgen_st PKCS11_NID_KGEN;
68typedef struct PKCS11_rsa_kgen_st PKCS11_RSA_KGEN;
69typedef struct PKCS11_params PKCS11_params;
70typedef struct PKCS11_kgen_attrs_st PKCS11_KGEN_ATTRS;
71
72/* Legacy EC-specific name retained for compatibility.
73 * Use PKCS11_NID_KGEN for new code. */
74#define PKCS11_EDDSA_KGEN PKCS11_NID_KGEN
75
78 char *label;
79 unsigned char *id;
80 size_t id_len;
81 unsigned char isPrivate;
82 unsigned char needLogin;
83 PKCS11_OBJECT_private *_private;
84};
85
88 char *label;
89 unsigned char *id;
90 size_t id_len;
91 X509 *x509;
92 PKCS11_OBJECT_private *_private;
93};
94
97 char *label;
98 char *manufacturer;
99 char *model;
100 char *serialnr;
101 unsigned char initialized;
102 unsigned char loginRequired;
103 unsigned char secureLogin;
104 unsigned char userPinSet;
105 unsigned char readOnly;
106 unsigned char hasRng;
107 unsigned char userPinCountLow;
108 unsigned char userPinFinalTry;
109 unsigned char userPinLocked;
110 unsigned char userPinToBeChanged;
111 unsigned char soPinCountLow;
112 unsigned char soPinFinalTry;
113 unsigned char soPinLocked;
114 unsigned char soPinToBeChanged;
115 PKCS11_SLOT *slot;
116};
117
120 char *manufacturer;
121 char *description;
122 unsigned char removable;
123 PKCS11_TOKEN *token;
124 PKCS11_SLOT_private *_private;
125};
126
129 char *manufacturer;
130 char *description;
131 PKCS11_CTX_private *_private;
132};
133
135 const char *curve;
136};
137
139 int nid;
140};
141
143 unsigned int bits;
144};
145
147 unsigned char extractable;
148 unsigned char sensitive;
149};
150
152 /* Key generation type from OpenSSL. Given the union below this should
153 * be either EVP_PKEY_EC or EVP_PKEY_RSA or EVP_PKEY_ED25519 or EVP_PKEY_ED448
154 * EVP_PKEY_ML_DSA_* or EVP_PKEY_SLH_DSA_*. or
155 * EVP_PKEY_FALCON512 or EVP_PKEY_FALCON1024
156 */
157 int type;
158 union {
159 PKCS11_EC_KGEN *ec;
160 PKCS11_EDDSA_KGEN *eddsa;
161 PKCS11_NID_KGEN *nid;
162 PKCS11_RSA_KGEN *rsa;
163 } kgen;
164 const char *token_label;
165 const char *key_label;
166 const unsigned char *key_id;
167 size_t id_len;
168 const PKCS11_params *key_params;
169};
170
172typedef void (*PKCS11_VLOG_A_CB)(int, const char *, va_list);
173
181typedef int (*PKCS11_PKEY_CALLBACK)(PKCS11_KEY *, EVP_PKEY *, void *);
182
184#define PKCS11_PKEY_CALLBACK_GET_PRIVATE_KEY 1
185
192extern PKCS11_CTX *PKCS11_CTX_new_ex(int flags);
193
200extern PKCS11_CTX *PKCS11_CTX_new(void);
201
216extern int PKCS11_CTX_set_pkey_callback(PKCS11_CTX *ctx,
217 int callback_type, PKCS11_PKEY_CALLBACK callback, void *user_data);
218
224extern void PKCS11_CTX_init_args(PKCS11_CTX *ctx, const char *init_args);
225
234extern int PKCS11_CTX_load(PKCS11_CTX *ctx, const char *ident);
235
241extern void PKCS11_CTX_unload(PKCS11_CTX *ctx);
242
248extern void PKCS11_CTX_free(PKCS11_CTX *ctx);
249
257extern int PKCS11_open_session(PKCS11_SLOT *slot, int rw);
258
268extern int PKCS11_enumerate_slots(PKCS11_CTX *ctx,
269 PKCS11_SLOT **slotsp, unsigned int *nslotsp);
270
285extern int PKCS11_update_slots(PKCS11_CTX *ctx,
286 PKCS11_SLOT **slotsp, unsigned int *nslotsp);
287
294extern unsigned long PKCS11_get_slotid_from_slot(PKCS11_SLOT *slotp);
295
303extern void PKCS11_release_all_slots(PKCS11_CTX *ctx,
304 PKCS11_SLOT *slots, unsigned int nslots);
305
315PKCS11_SLOT *PKCS11_find_token(PKCS11_CTX *ctx,
316 PKCS11_SLOT *slots, unsigned int nslots);
317
328PKCS11_SLOT *PKCS11_find_next_token(PKCS11_CTX *ctx,
329 PKCS11_SLOT *slots, unsigned int nslots,
330 PKCS11_SLOT *slot);
331
341extern int PKCS11_is_logged_in(PKCS11_SLOT *slot, int so, int *res);
342
352extern int PKCS11_login(PKCS11_SLOT *slot, int so, const char *pin);
353
361extern int PKCS11_logout(PKCS11_SLOT *slot);
362
363/* Get a list of private keys associated with this token */
364extern int PKCS11_enumerate_keys(PKCS11_TOKEN *,
365 PKCS11_KEY **, unsigned int *);
366
367/* Get a list of private keys associated with this token and matching the key template */
368extern int PKCS11_enumerate_keys_ext(PKCS11_TOKEN *,
369 const PKCS11_KEY *, PKCS11_KEY **, unsigned int *);
370
371/* Remove the key from this token */
372extern int PKCS11_remove_key(PKCS11_KEY *);
373
374/* Get a list of public keys associated with this token */
375extern int PKCS11_enumerate_public_keys(PKCS11_TOKEN *,
376 PKCS11_KEY **, unsigned int *);
377
378/* Get a list of public keys associated with this token and matching the key template */
379extern int PKCS11_enumerate_public_keys_ext(PKCS11_TOKEN *,
380 const PKCS11_KEY *, PKCS11_KEY **, unsigned int *);
381
382/* Get the key type (as EVP_PKEY_XXX) */
383extern int PKCS11_get_key_type(PKCS11_KEY *);
384
392extern EVP_PKEY *PKCS11_get_private_key(PKCS11_KEY *key);
393
401extern EVP_PKEY *PKCS11_get_public_key(PKCS11_KEY *key);
402
403/* Find the corresponding certificate (if any) */
404extern PKCS11_CERT *PKCS11_find_certificate(PKCS11_KEY *);
405
406/* Find the corresponding key (if any) */
407extern PKCS11_KEY *PKCS11_find_key(PKCS11_CERT *);
408
409/* Get a list of all certificates associated with this token */
410extern int PKCS11_enumerate_certs(PKCS11_TOKEN *, PKCS11_CERT **, unsigned int *);
411
412/* Get a list of all certificates associated with this token and matching cert template */
413extern int PKCS11_enumerate_certs_ext(PKCS11_TOKEN *,
414 const PKCS11_CERT *, PKCS11_CERT **, unsigned int *);
415
416/* Remove the certificate from this token */
417extern int PKCS11_remove_certificate(PKCS11_CERT *);
418
419/* Set UI method to allow retrieving CKU_CONTEXT_SPECIFIC PINs interactively */
420extern int PKCS11_set_ui_method(PKCS11_CTX *ctx,
421 UI_METHOD *ui_method, void *ui_user_data);
422
432extern int PKCS11_init_token(PKCS11_TOKEN *token, const char *pin,
433 const char *label);
434
443extern int PKCS11_init_pin(PKCS11_TOKEN *token, const char *pin);
444
454extern int PKCS11_change_pin(PKCS11_SLOT *slot, const char *old_pin,
455 const char *new_pin);
456
468extern int PKCS11_store_private_key(PKCS11_TOKEN *token, EVP_PKEY *pk, char *label, unsigned char *id, size_t id_len);
469
481extern int PKCS11_store_public_key(PKCS11_TOKEN *token, EVP_PKEY *pk, char *label, unsigned char *id, size_t id_len);
482
495extern int PKCS11_store_certificate(PKCS11_TOKEN *token, X509 *x509,
496 char *label, unsigned char *id, size_t id_len,
497 PKCS11_CERT **ret_cert);
498
499/* Access the random number generator */
500extern int PKCS11_seed_random(PKCS11_SLOT *slot, const unsigned char *s, unsigned int s_len);
501extern int PKCS11_generate_random(PKCS11_SLOT *slot, unsigned char *r, unsigned int r_len);
502
503/*
504 * PKCS#11 implementation for OpenSSL methods
505 */
506RSA_METHOD *PKCS11_get_rsa_method(void);
507/* Also define unsupported methods to retain backward compatibility */
508#if OPENSSL_VERSION_NUMBER >= 0x10100002L && !defined(LIBRESSL_VERSION_NUMBER)
509EC_KEY_METHOD *PKCS11_get_ec_key_method(void);
510void *PKCS11_get_ecdsa_method(void);
511void *PKCS11_get_ecdh_method(void);
512#else
513void *PKCS11_get_ec_key_method(void);
514ECDSA_METHOD *PKCS11_get_ecdsa_method(void);
515ECDH_METHOD *PKCS11_get_ecdh_method(void);
516#endif
517
518#if OPENSSL_VERSION_NUMBER < 0x40000000L
529int PKCS11_pkey_meths(ENGINE *e, EVP_PKEY_METHOD **pmeth,
530 const int **nids, int nid);
531#else /* OPENSSL_VERSION_NUMBER < 0x40000000L */
532int PKCS11_pkey_meths(void *e, void **pmeth, const int **nids, int nid);
533#endif /* OPENSSL_VERSION_NUMBER < 0x40000000L */
534
541extern void ERR_load_PKCS11_strings(void);
542
543/*
544 * The following functions are discouraged, because they partially
545 * duplicate the functionality OpenSSL provides for EVP_PKEY objects
546 */
547
557extern int PKCS11_keygen(PKCS11_TOKEN *token, PKCS11_KGEN_ATTRS *kgen_attrs);
558
571extern int PKCS11_generate_key(PKCS11_TOKEN *token,
572 int algorithm, unsigned int bits_or_nid,
573 char *label, unsigned char *id, size_t id_len);
574
575extern int PKCS11_generate_key_ext(PKCS11_TOKEN *token,
576 int algorithm, unsigned int bits_or_nid,
577 char *label, unsigned char *id, size_t id_len,
578 PKCS11_KEY **ret_key);
579
580/* Get the RSA key modulus size (in bytes) */
581extern int PKCS11_get_key_size(PKCS11_KEY *);
582
583/* Get the RSA key modules as BIGNUM */
584extern int PKCS11_get_key_modulus(PKCS11_KEY *, BIGNUM **);
585
586/* Get the RSA key public exponent as BIGNUM */
587extern int PKCS11_get_key_exponent(PKCS11_KEY *, BIGNUM **);
588
589/* Sign with the EC private key */
590extern int PKCS11_ecdsa_sign(
591 const unsigned char *m, unsigned int m_len,
592 unsigned char *sigret, unsigned int *siglen, PKCS11_KEY *key);
593
594/* Sign with the RSA private key */
595extern int PKCS11_sign(int type,
596 const unsigned char *m, unsigned int m_len,
597 unsigned char *sigret, unsigned int *siglen, PKCS11_KEY *key);
598
599/* This function has never been implemented */
600extern int PKCS11_verify(int type,
601 const unsigned char *m, unsigned int m_len,
602 unsigned char *signature, unsigned int siglen, PKCS11_KEY *key);
603
604#if OPENSSL_VERSION_NUMBER >= 0x30000000L
605/* Perform a private-key operation using a PKCS#11-backed EVP_PKEY */
606extern int PKCS11_evp_pkey_sign(EVP_PKEY *pkey, int type, const char *mdname,
607 const int pad_mode, const int salt_len, const char *mgf1_mdname,
608 unsigned char *sig, size_t *siglen,
609 const unsigned char *tbs, size_t tbslen);
610
611/* Perform a public-key operation using a PKCS#11-backed EVP_PKEY */
612int PKCS11_evp_pkey_verify(EVP_PKEY *pkey, int type,
613 const unsigned char *sig, size_t siglen,
614 const unsigned char *tbs, size_t tbslen);
615
616/* Perform a private-key decryption operation using a PKCS#11-backed EVP_PKEY */
617extern int PKCS11_evp_pkey_decrypt(EVP_PKEY *pk, int type, const char *mdname,
618 const int pad_mode, const char *mgf1_mdname,
619 unsigned char *oaep_label, size_t oaep_labellen,
620 unsigned char *sig, size_t *siglen,
621 const unsigned char *in, size_t inlen);
622
623/* Perform a private-key derive operation using a PKCS#11-backed EVP_PKEY */
624extern int PKCS11_evp_pkey_derive(EVP_PKEY *pk, int type,
625 const unsigned char *peer_pub, size_t peer_pub_len,
626 int cofactor_mode, unsigned char *secret, size_t *secretlen);
627
628/* Perform a private-key decapsulate operation using a PKCS#11-backed EVP_PKEY */
629extern int PKCS11_evp_pkey_decapsulate(EVP_PKEY *pk, int type,
630 unsigned char *out, size_t *outlen,
631 const unsigned char *in, size_t inlen);
632
633#endif /* OPENSSL_VERSION_NUMBER >= 0x30000000L */
634
635/* Encrypts data using the private key */
636extern int PKCS11_private_encrypt(
637 int flen, const unsigned char *from,
638 unsigned char *to, PKCS11_KEY *rsa, int padding);
639
651 int flen, const unsigned char *from,
652 unsigned char *to, PKCS11_KEY *key, int padding);
653
654/* Set the logging callback */
655extern void PKCS11_set_vlog_a_method(PKCS11_CTX *pctx, PKCS11_VLOG_A_CB cb);
656
657/* Function codes */
658# define CKR_F_PKCS11_CHANGE_PIN 100
659# define CKR_F_PKCS11_CHECK_TOKEN 101
660# define CKR_F_PKCS11_CTX_LOAD 102
661# define CKR_F_PKCS11_ECDH_DERIVE 103
662# define CKR_F_PKCS11_ECDSA_SIGN 104
663# define CKR_F_PKCS11_ENUMERATE_SLOTS 105
664# define CKR_F_PKCS11_FIND_CERTS 106
665# define CKR_F_PKCS11_FIND_KEYS 107
666# define CKR_F_PKCS11_GENERATE_RANDOM 108
667# define CKR_F_PKCS11_GETATTR_ALLOC 109
668# define CKR_F_PKCS11_GETATTR_BN 110
669# define CKR_F_PKCS11_GETATTR_INT 111
670# define CKR_F_PKCS11_INIT_PIN 112
671# define CKR_F_PKCS11_INIT_SLOT 113
672# define CKR_F_PKCS11_INIT_TOKEN 114
673# define CKR_F_PKCS11_IS_LOGGED_IN 115
674# define CKR_F_PKCS11_LOGIN 116
675# define CKR_F_PKCS11_LOGOUT 117
676# define CKR_F_PKCS11_NEXT_CERT 118
677# define CKR_F_PKCS11_NEXT_KEY 119
678# define CKR_F_PKCS11_OPEN_SESSION 120
679# define CKR_F_PKCS11_PRIVATE_DECRYPT 121
680# define CKR_F_PKCS11_PRIVATE_ENCRYPT 122
681# define CKR_F_PKCS11_RELOAD_KEY 123
682# define CKR_F_PKCS11_SEED_RANDOM 125
683# define CKR_F_PKCS11_STORE_CERTIFICATE 126
684# define CKR_F_PKCS11_STORE_KEY 127
685# define CKR_F_PKCS11_REMOVE_KEY 128
686# define CKR_F_PKCS11_REMOVE_CERTIFICATE 129
687# define CKR_F_PKCS11_GENERATE_KEY 130
688# define CKR_F_PKCS11_RELOAD_CERTIFICATE 131
689# define CKR_F_PKCS11_GET_SESSION 132
690# define CKR_F_PKCS11_EDDSA_SIGN 133
691
692/* Backward compatibility of error function codes */
693#define PKCS11_F_PKCS11_CHANGE_PIN CKR_F_PKCS11_CHANGE_PIN
694#define PKCS11_F_PKCS11_CHECK_TOKEN CKR_F_PKCS11_CHECK_TOKEN
695#define PKCS11_F_PKCS11_CTX_LOAD CKR_F_PKCS11_CTX_LOAD
696#define PKCS11_F_PKCS11_ECDH_DERIVE CKR_F_PKCS11_ECDH_DERIVE
697#define PKCS11_F_PKCS11_ECDSA_SIGN CKR_F_PKCS11_ECDSA_SIGN
698#define PKCS11_F_PKCS11_ENUMERATE_SLOTS CKR_F_PKCS11_ENUMERATE_SLOTS
699#define PKCS11_F_PKCS11_FIND_CERTS CKR_F_PKCS11_FIND_CERTS
700#define PKCS11_F_PKCS11_FIND_KEYS CKR_F_PKCS11_FIND_KEYS
701#define PKCS11_F_PKCS11_GENERATE_RANDOM CKR_F_PKCS11_GENERATE_RANDOM
702#define PKCS11_F_PKCS11_GETATTR_ALLOC CKR_F_PKCS11_GETATTR_ALLOC
703#define PKCS11_F_PKCS11_GETATTR_BN CKR_F_PKCS11_GETATTR_BN
704#define PKCS11_F_PKCS11_GETATTR_INT CKR_F_PKCS11_GETATTR_INT
705#define PKCS11_F_PKCS11_INIT_PIN CKR_F_PKCS11_INIT_PIN
706#define PKCS11_F_PKCS11_INIT_SLOT CKR_F_PKCS11_INIT_SLOT
707#define PKCS11_F_PKCS11_INIT_TOKEN CKR_F_PKCS11_INIT_TOKEN
708#define PKCS11_F_PKCS11_IS_LOGGED_IN CKR_F_PKCS11_IS_LOGGED_IN
709#define PKCS11_F_PKCS11_LOGIN CKR_F_PKCS11_LOGIN
710#define PKCS11_F_PKCS11_LOGOUT CKR_F_PKCS11_LOGOUT
711#define PKCS11_F_PKCS11_NEXT_CERT CKR_F_PKCS11_NEXT_CERT
712#define PKCS11_F_PKCS11_NEXT_KEY CKR_F_PKCS11_NEXT_KEY
713#define PKCS11_F_PKCS11_OPEN_SESSION CKR_F_PKCS11_OPEN_SESSION
714#define PKCS11_F_PKCS11_PRIVATE_DECRYPT CKR_F_PKCS11_PRIVATE_DECRYPT
715#define PKCS11_F_PKCS11_PRIVATE_ENCRYPT CKR_F_PKCS11_PRIVATE_ENCRYPT
716#define PKCS11_F_PKCS11_RELOAD_KEY CKR_F_PKCS11_RELOAD_KEY
717#define PKCS11_F_PKCS11_SEED_RANDOM CKR_F_PKCS11_SEED_RANDOM
718#define PKCS11_F_PKCS11_STORE_CERTIFICATE CKR_F_PKCS11_STORE_CERTIFICATE
719#define PKCS11_F_PKCS11_STORE_KEY CKR_F_PKCS11_STORE_KEY
720#define PKCS11_F_PKCS11_REMOVE_KEY CKR_F_PKCS11_REMOVE_KEY
721#define PKCS11_F_PKCS11_REMOVE_CERTIFICATE CKR_F_PKCS11_REMOVE_CERTIFICATE
722#define PKCS11_F_PKCS11_GENERATE_KEY CKR_F_PKCS11_GENERATE_KEY
723
724/* Backward compatibility of error reason codes */
725#define PKCS11_LOAD_MODULE_ERROR P11_R_LOAD_MODULE_ERROR
726#define PKCS11_MODULE_LOADED_ERROR -1
727#define PKCS11_SYMBOL_NOT_FOUND_ERROR -1
728#define PKCS11_NOT_SUPPORTED P11_R_NOT_SUPPORTED
729#define PKCS11_NO_SESSION P11_R_NO_SESSION
730#define PKCS11_KEYGEN_FAILED P11_R_KEYGEN_FAILED
731#define PKCS11_UI_FAILED P11_R_UI_FAILED
732
733/* Backward compatibility emulation of the ERR_LIB_PKCS11 constant.
734 * We currently use two separate variables for library error codes:
735 * one for imported PKCS#11 module errors, and one for our own libp11 errors.
736 * We return the value for PKCS#11, as it is more likely to be needed. */
737#define ERR_LIB_PKCS11 (ERR_get_CKR_code())
738
739#ifdef __cplusplus
740}
741#endif
742#endif
743
744/* vim: set noexpandtab: */
unsigned long PKCS11_get_slotid_from_slot(PKCS11_SLOT *slotp)
Get the slot_id from a slot as it is stored in private.
int PKCS11_store_public_key(PKCS11_TOKEN *token, EVP_PKEY *pk, char *label, unsigned char *id, size_t id_len)
Store public key on a token.
void PKCS11_CTX_free(PKCS11_CTX *ctx)
Free a libp11 context.
PKCS11_CTX * PKCS11_CTX_new_ex(int flags)
Create a new libp11 context with specified flags.
int PKCS11_change_pin(PKCS11_SLOT *slot, const char *old_pin, const char *new_pin)
Change the currently used (either USER or SO) PIN on a token.
void(* PKCS11_VLOG_A_CB)(int, const char *, va_list)
PKCS11 ASCII logging callback.
Definition libp11.h:172
int PKCS11_init_pin(PKCS11_TOKEN *token, const char *pin)
Initialize the user PIN on a token.
int PKCS11_store_certificate(PKCS11_TOKEN *token, X509 *x509, char *label, unsigned char *id, size_t id_len, PKCS11_CERT **ret_cert)
Store certificate on a token.
EVP_PKEY * PKCS11_get_public_key(PKCS11_KEY *key)
Returns a EVP_PKEY object with the public key.
int PKCS11_keygen(PKCS11_TOKEN *token, PKCS11_KGEN_ATTRS *kgen_attrs)
Generate key pair on the token.
int PKCS11_login(PKCS11_SLOT *slot, int so, const char *pin)
Authenticate to the card.
void PKCS11_CTX_unload(PKCS11_CTX *ctx)
Unload a PKCS#11 module.
PKCS11_SLOT * PKCS11_find_next_token(PKCS11_CTX *ctx, PKCS11_SLOT *slots, unsigned int nslots, PKCS11_SLOT *slot)
Find the next slot with a token.
int PKCS11_init_token(PKCS11_TOKEN *token, const char *pin, const char *label)
Initialize a token.
int PKCS11_enumerate_slots(PKCS11_CTX *ctx, PKCS11_SLOT **slotsp, unsigned int *nslotsp)
Get a list of all slots.
PKCS11_CTX * PKCS11_CTX_new(void)
Create a new libp11 context.
int PKCS11_CTX_set_pkey_callback(PKCS11_CTX *ctx, int callback_type, PKCS11_PKEY_CALLBACK callback, void *user_data)
Set a callback for EVP_PKEY objects returned by this context.
EVP_PKEY * PKCS11_get_private_key(PKCS11_KEY *key)
Returns a EVP_PKEY object for the private key.
int PKCS11_is_logged_in(PKCS11_SLOT *slot, int so, int *res)
Check if user is already authenticated to a card.
int PKCS11_update_slots(PKCS11_CTX *ctx, PKCS11_SLOT **slotsp, unsigned int *nslotsp)
Get or update a list of all slots.
int(* PKCS11_PKEY_CALLBACK)(PKCS11_KEY *, EVP_PKEY *, void *)
Callback invoked for an EVP_PKEY returned by libp11.
Definition libp11.h:181
int PKCS11_pkey_meths(ENGINE *e, EVP_PKEY_METHOD **pmeth, const int **nids, int nid)
Return supported key types or create a legacy OpenSSL pkey method.
void PKCS11_CTX_init_args(PKCS11_CTX *ctx, const char *init_args)
Specify any private PKCS#11 module initialization args, if necessary.
int PKCS11_CTX_load(PKCS11_CTX *ctx, const char *ident)
Load a PKCS#11 module.
void PKCS11_release_all_slots(PKCS11_CTX *ctx, PKCS11_SLOT *slots, unsigned int nslots)
Free the list of slots allocated by PKCS11_enumerate_slots().
PKCS11_SLOT * PKCS11_find_token(PKCS11_CTX *ctx, PKCS11_SLOT *slots, unsigned int nslots)
Find the first slot with a token.
int PKCS11_open_session(PKCS11_SLOT *slot, int rw)
Open a session in RO or RW mode.
int PKCS11_private_decrypt(int flen, const unsigned char *from, unsigned char *to, PKCS11_KEY *key, int padding)
Decrypts data using the private key.
int PKCS11_store_private_key(PKCS11_TOKEN *token, EVP_PKEY *pk, char *label, unsigned char *id, size_t id_len)
Store private key on a token.
int PKCS11_generate_key(PKCS11_TOKEN *token, int algorithm, unsigned int bits_or_nid, char *label, unsigned char *id, size_t id_len)
Generate a private key on the token.
void ERR_load_PKCS11_strings(void)
Load PKCS11 error strings.
int PKCS11_logout(PKCS11_SLOT *slot)
De-authenticate from the card.
PKCS11 certificate object.
Definition libp11.h:87
PKCS11 context.
Definition libp11.h:128
PKCS11 key object (public or private).
Definition libp11.h:77
unsigned char isPrivate
private key present?
Definition libp11.h:81
unsigned char needLogin
login to read private key?
Definition libp11.h:82
PKCS11 slot: card reader.
Definition libp11.h:119
PKCS11_TOKEN * token
NULL if no token present.
Definition libp11.h:123
PKCS11 token: smart card or USB key.
Definition libp11.h:96

libp11, Copyright (C) 2005 Olaf Kirch <okir@lst.de>OpenSC-Project.org Logo