libp11 0.4.19
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 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
180extern PKCS11_CTX *PKCS11_CTX_new_ex(int flags);
181
188extern PKCS11_CTX *PKCS11_CTX_new(void);
189
195extern void PKCS11_CTX_init_args(PKCS11_CTX *ctx, const char *init_args);
196
205extern int PKCS11_CTX_load(PKCS11_CTX *ctx, const char *ident);
206
212extern void PKCS11_CTX_unload(PKCS11_CTX *ctx);
213
219extern void PKCS11_CTX_free(PKCS11_CTX *ctx);
220
228extern int PKCS11_open_session(PKCS11_SLOT *slot, int rw);
229
239extern int PKCS11_enumerate_slots(PKCS11_CTX *ctx,
240 PKCS11_SLOT **slotsp, unsigned int *nslotsp);
241
256extern int PKCS11_update_slots(PKCS11_CTX *ctx,
257 PKCS11_SLOT **slotsp, unsigned int *nslotsp);
258
265extern unsigned long PKCS11_get_slotid_from_slot(PKCS11_SLOT *slotp);
266
274extern void PKCS11_release_all_slots(PKCS11_CTX *ctx,
275 PKCS11_SLOT *slots, unsigned int nslots);
276
286PKCS11_SLOT *PKCS11_find_token(PKCS11_CTX *ctx,
287 PKCS11_SLOT *slots, unsigned int nslots);
288
299PKCS11_SLOT *PKCS11_find_next_token(PKCS11_CTX *ctx,
300 PKCS11_SLOT *slots, unsigned int nslots,
301 PKCS11_SLOT *slot);
302
312extern int PKCS11_is_logged_in(PKCS11_SLOT *slot, int so, int *res);
313
323extern int PKCS11_login(PKCS11_SLOT *slot, int so, const char *pin);
324
332extern int PKCS11_logout(PKCS11_SLOT *slot);
333
334/* Get a list of private keys associated with this token */
335extern int PKCS11_enumerate_keys(PKCS11_TOKEN *,
336 PKCS11_KEY **, unsigned int *);
337
338/* Get a list of private keys associated with this token and matching the key template */
339extern int PKCS11_enumerate_keys_ext(PKCS11_TOKEN *,
340 const PKCS11_KEY *, PKCS11_KEY **, unsigned int *);
341
342/* Remove the key from this token */
343extern int PKCS11_remove_key(PKCS11_KEY *);
344
345/* Get a list of public keys associated with this token */
346extern int PKCS11_enumerate_public_keys(PKCS11_TOKEN *,
347 PKCS11_KEY **, unsigned int *);
348
349/* Get a list of public keys associated with this token and matching the key template */
350extern int PKCS11_enumerate_public_keys_ext(PKCS11_TOKEN *,
351 const PKCS11_KEY *, PKCS11_KEY **, unsigned int *);
352
353/* Get the key type (as EVP_PKEY_XXX) */
354extern int PKCS11_get_key_type(PKCS11_KEY *);
355
363extern EVP_PKEY *PKCS11_get_private_key(PKCS11_KEY *key);
364
372extern EVP_PKEY *PKCS11_get_public_key(PKCS11_KEY *key);
373
374/* Find the corresponding certificate (if any) */
375extern PKCS11_CERT *PKCS11_find_certificate(PKCS11_KEY *);
376
377/* Find the corresponding key (if any) */
378extern PKCS11_KEY *PKCS11_find_key(PKCS11_CERT *);
379
380/* Get a list of all certificates associated with this token */
381extern int PKCS11_enumerate_certs(PKCS11_TOKEN *, PKCS11_CERT **, unsigned int *);
382
383/* Get a list of all certificates associated with this token and matching cert template */
384extern int PKCS11_enumerate_certs_ext(PKCS11_TOKEN *,
385 const PKCS11_CERT *, PKCS11_CERT **, unsigned int *);
386
387/* Remove the certificate from this token */
388extern int PKCS11_remove_certificate(PKCS11_CERT *);
389
390/* Set UI method to allow retrieving CKU_CONTEXT_SPECIFIC PINs interactively */
391extern int PKCS11_set_ui_method(PKCS11_CTX *ctx,
392 UI_METHOD *ui_method, void *ui_user_data);
393
403extern int PKCS11_init_token(PKCS11_TOKEN *token, const char *pin,
404 const char *label);
405
414extern int PKCS11_init_pin(PKCS11_TOKEN *token, const char *pin);
415
425extern int PKCS11_change_pin(PKCS11_SLOT *slot, const char *old_pin,
426 const char *new_pin);
427
439extern int PKCS11_store_private_key(PKCS11_TOKEN *token, EVP_PKEY *pk, char *label, unsigned char *id, size_t id_len);
440
452extern int PKCS11_store_public_key(PKCS11_TOKEN *token, EVP_PKEY *pk, char *label, unsigned char *id, size_t id_len);
453
466extern int PKCS11_store_certificate(PKCS11_TOKEN *token, X509 *x509,
467 char *label, unsigned char *id, size_t id_len,
468 PKCS11_CERT **ret_cert);
469
470/* Access the random number generator */
471extern int PKCS11_seed_random(PKCS11_SLOT *slot, const unsigned char *s, unsigned int s_len);
472extern int PKCS11_generate_random(PKCS11_SLOT *slot, unsigned char *r, unsigned int r_len);
473
474/*
475 * PKCS#11 implementation for OpenSSL methods
476 */
477RSA_METHOD *PKCS11_get_rsa_method(void);
478/* Also define unsupported methods to retain backward compatibility */
479#if OPENSSL_VERSION_NUMBER >= 0x10100002L && !defined(LIBRESSL_VERSION_NUMBER)
480EC_KEY_METHOD *PKCS11_get_ec_key_method(void);
481void *PKCS11_get_ecdsa_method(void);
482void *PKCS11_get_ecdh_method(void);
483#else
484void *PKCS11_get_ec_key_method(void);
485ECDSA_METHOD *PKCS11_get_ecdsa_method(void);
486ECDH_METHOD *PKCS11_get_ecdh_method(void);
487#endif
488
489#if OPENSSL_VERSION_NUMBER < 0x40000000L
490int PKCS11_pkey_meths(ENGINE *e, EVP_PKEY_METHOD **pmeth,
491 const int **nids, int nid);
492#else /* OPENSSL_VERSION_NUMBER < 0x40000000L */
493int PKCS11_pkey_meths(void *e, void **pmeth, const int **nids, int nid);
494#endif /* OPENSSL_VERSION_NUMBER < 0x40000000L */
495
502extern void ERR_load_PKCS11_strings(void);
503
504/*
505 * The following functions are discouraged, because they partially
506 * duplicate the functionality OpenSSL provides for EVP_PKEY objects
507 */
508
518extern int PKCS11_keygen(PKCS11_TOKEN *token, PKCS11_KGEN_ATTRS *kgen_attrs);
519
532extern int PKCS11_generate_key(PKCS11_TOKEN *token,
533 int algorithm, unsigned int bits_or_nid,
534 char *label, unsigned char *id, size_t id_len);
535
536/* Get the RSA key modulus size (in bytes) */
537extern int PKCS11_get_key_size(PKCS11_KEY *);
538
539/* Get the RSA key modules as BIGNUM */
540extern int PKCS11_get_key_modulus(PKCS11_KEY *, BIGNUM **);
541
542/* Get the RSA key public exponent as BIGNUM */
543extern int PKCS11_get_key_exponent(PKCS11_KEY *, BIGNUM **);
544
545/* Sign with the EC private key */
546extern int PKCS11_ecdsa_sign(
547 const unsigned char *m, unsigned int m_len,
548 unsigned char *sigret, unsigned int *siglen, PKCS11_KEY *key);
549
550/* Sign with the RSA private key */
551extern int PKCS11_sign(int type,
552 const unsigned char *m, unsigned int m_len,
553 unsigned char *sigret, unsigned int *siglen, PKCS11_KEY *key);
554
555/* This function has never been implemented */
556extern int PKCS11_verify(int type,
557 const unsigned char *m, unsigned int m_len,
558 unsigned char *signature, unsigned int siglen, PKCS11_KEY *key);
559
560#if OPENSSL_VERSION_NUMBER >= 0x30000000L
561/* Perform a private-key operation using a PKCS#11-backed EVP_PKEY */
562extern int PKCS11_evp_pkey_sign(EVP_PKEY *pkey, int type, const char *mdname,
563 const int pad_mode, const int salt_len, const char *mgf1_mdname,
564 unsigned char *sig, size_t *siglen,
565 const unsigned char *tbs, size_t tbslen);
566
567/* Perform a public-key operation using a PKCS#11-backed EVP_PKEY */
568int PKCS11_evp_pkey_verify(EVP_PKEY *pkey, int type,
569 const unsigned char *sig, size_t siglen,
570 const unsigned char *tbs, size_t tbslen);
571
572/* Perform a private-key decryption operation using a PKCS#11-backed EVP_PKEY */
573extern int PKCS11_evp_pkey_decrypt(EVP_PKEY *pk, int type, const char *mdname,
574 const int pad_mode, const char *mgf1_mdname,
575 unsigned char *oaep_label, size_t oaep_labellen,
576 unsigned char *sig, size_t *siglen,
577 const unsigned char *in, size_t inlen);
578
579/* Perform a private-key derive operation using a PKCS#11-backed EVP_PKEY */
580extern int PKCS11_evp_pkey_derive(EVP_PKEY *pk, int type,
581 const unsigned char *peer_pub, size_t peer_pub_len,
582 int cofactor_mode, unsigned char *secret, size_t *secretlen);
583
584#endif /* OPENSSL_VERSION_NUMBER >= 0x30000000L */
585
586/* Encrypts data using the private key */
587extern int PKCS11_private_encrypt(
588 int flen, const unsigned char *from,
589 unsigned char *to, PKCS11_KEY *rsa, int padding);
590
602 int flen, const unsigned char *from,
603 unsigned char *to, PKCS11_KEY *key, int padding);
604
605/* Set the logging callback */
606extern void PKCS11_set_vlog_a_method(PKCS11_CTX *pctx, PKCS11_VLOG_A_CB cb);
607
608/* Function codes */
609# define CKR_F_PKCS11_CHANGE_PIN 100
610# define CKR_F_PKCS11_CHECK_TOKEN 101
611# define CKR_F_PKCS11_CTX_LOAD 102
612# define CKR_F_PKCS11_ECDH_DERIVE 103
613# define CKR_F_PKCS11_ECDSA_SIGN 104
614# define CKR_F_PKCS11_ENUMERATE_SLOTS 105
615# define CKR_F_PKCS11_FIND_CERTS 106
616# define CKR_F_PKCS11_FIND_KEYS 107
617# define CKR_F_PKCS11_GENERATE_RANDOM 108
618# define CKR_F_PKCS11_GETATTR_ALLOC 109
619# define CKR_F_PKCS11_GETATTR_BN 110
620# define CKR_F_PKCS11_GETATTR_INT 111
621# define CKR_F_PKCS11_INIT_PIN 112
622# define CKR_F_PKCS11_INIT_SLOT 113
623# define CKR_F_PKCS11_INIT_TOKEN 114
624# define CKR_F_PKCS11_IS_LOGGED_IN 115
625# define CKR_F_PKCS11_LOGIN 116
626# define CKR_F_PKCS11_LOGOUT 117
627# define CKR_F_PKCS11_NEXT_CERT 118
628# define CKR_F_PKCS11_NEXT_KEY 119
629# define CKR_F_PKCS11_OPEN_SESSION 120
630# define CKR_F_PKCS11_PRIVATE_DECRYPT 121
631# define CKR_F_PKCS11_PRIVATE_ENCRYPT 122
632# define CKR_F_PKCS11_RELOAD_KEY 123
633# define CKR_F_PKCS11_SEED_RANDOM 125
634# define CKR_F_PKCS11_STORE_CERTIFICATE 126
635# define CKR_F_PKCS11_STORE_KEY 127
636# define CKR_F_PKCS11_REMOVE_KEY 128
637# define CKR_F_PKCS11_REMOVE_CERTIFICATE 129
638# define CKR_F_PKCS11_GENERATE_KEY 130
639# define CKR_F_PKCS11_RELOAD_CERTIFICATE 131
640# define CKR_F_PKCS11_GET_SESSION 132
641# define CKR_F_PKCS11_EDDSA_SIGN 133
642
643/* Backward compatibility of error function codes */
644#define PKCS11_F_PKCS11_CHANGE_PIN CKR_F_PKCS11_CHANGE_PIN
645#define PKCS11_F_PKCS11_CHECK_TOKEN CKR_F_PKCS11_CHECK_TOKEN
646#define PKCS11_F_PKCS11_CTX_LOAD CKR_F_PKCS11_CTX_LOAD
647#define PKCS11_F_PKCS11_ECDH_DERIVE CKR_F_PKCS11_ECDH_DERIVE
648#define PKCS11_F_PKCS11_ECDSA_SIGN CKR_F_PKCS11_ECDSA_SIGN
649#define PKCS11_F_PKCS11_ENUMERATE_SLOTS CKR_F_PKCS11_ENUMERATE_SLOTS
650#define PKCS11_F_PKCS11_FIND_CERTS CKR_F_PKCS11_FIND_CERTS
651#define PKCS11_F_PKCS11_FIND_KEYS CKR_F_PKCS11_FIND_KEYS
652#define PKCS11_F_PKCS11_GENERATE_RANDOM CKR_F_PKCS11_GENERATE_RANDOM
653#define PKCS11_F_PKCS11_GETATTR_ALLOC CKR_F_PKCS11_GETATTR_ALLOC
654#define PKCS11_F_PKCS11_GETATTR_BN CKR_F_PKCS11_GETATTR_BN
655#define PKCS11_F_PKCS11_GETATTR_INT CKR_F_PKCS11_GETATTR_INT
656#define PKCS11_F_PKCS11_INIT_PIN CKR_F_PKCS11_INIT_PIN
657#define PKCS11_F_PKCS11_INIT_SLOT CKR_F_PKCS11_INIT_SLOT
658#define PKCS11_F_PKCS11_INIT_TOKEN CKR_F_PKCS11_INIT_TOKEN
659#define PKCS11_F_PKCS11_IS_LOGGED_IN CKR_F_PKCS11_IS_LOGGED_IN
660#define PKCS11_F_PKCS11_LOGIN CKR_F_PKCS11_LOGIN
661#define PKCS11_F_PKCS11_LOGOUT CKR_F_PKCS11_LOGOUT
662#define PKCS11_F_PKCS11_NEXT_CERT CKR_F_PKCS11_NEXT_CERT
663#define PKCS11_F_PKCS11_NEXT_KEY CKR_F_PKCS11_NEXT_KEY
664#define PKCS11_F_PKCS11_OPEN_SESSION CKR_F_PKCS11_OPEN_SESSION
665#define PKCS11_F_PKCS11_PRIVATE_DECRYPT CKR_F_PKCS11_PRIVATE_DECRYPT
666#define PKCS11_F_PKCS11_PRIVATE_ENCRYPT CKR_F_PKCS11_PRIVATE_ENCRYPT
667#define PKCS11_F_PKCS11_RELOAD_KEY CKR_F_PKCS11_RELOAD_KEY
668#define PKCS11_F_PKCS11_SEED_RANDOM CKR_F_PKCS11_SEED_RANDOM
669#define PKCS11_F_PKCS11_STORE_CERTIFICATE CKR_F_PKCS11_STORE_CERTIFICATE
670#define PKCS11_F_PKCS11_STORE_KEY CKR_F_PKCS11_STORE_KEY
671#define PKCS11_F_PKCS11_REMOVE_KEY CKR_F_PKCS11_REMOVE_KEY
672#define PKCS11_F_PKCS11_REMOVE_CERTIFICATE CKR_F_PKCS11_REMOVE_CERTIFICATE
673#define PKCS11_F_PKCS11_GENERATE_KEY CKR_F_PKCS11_GENERATE_KEY
674
675/* Backward compatibility of error reason codes */
676#define PKCS11_LOAD_MODULE_ERROR P11_R_LOAD_MODULE_ERROR
677#define PKCS11_MODULE_LOADED_ERROR -1
678#define PKCS11_SYMBOL_NOT_FOUND_ERROR -1
679#define PKCS11_NOT_SUPPORTED P11_R_NOT_SUPPORTED
680#define PKCS11_NO_SESSION P11_R_NO_SESSION
681#define PKCS11_KEYGEN_FAILED P11_R_KEYGEN_FAILED
682#define PKCS11_UI_FAILED P11_R_UI_FAILED
683
684/* Backward compatibility emulation of the ERR_LIB_PKCS11 constant.
685 * We currently use two separate variables for library error codes:
686 * one for imported PKCS#11 module errors, and one for our own libp11 errors.
687 * We return the value for PKCS#11, as it is more likely to be needed. */
688#define ERR_LIB_PKCS11 (ERR_get_CKR_code())
689
690#ifdef __cplusplus
691}
692#endif
693#endif
694
695/* 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.
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.
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