"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.16.7/lib/isc/include/pk11/pk11.h" (4 Sep 2020, 7837 Bytes) of package /linux/misc/dns/bind9/9.16.7/bind-9.16.7.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "pk11.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
    3  *
    4  * This Source Code Form is subject to the terms of the Mozilla Public
    5  * License, v. 2.0. If a copy of the MPL was not distributed with this
    6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    7  *
    8  * See the COPYRIGHT file distributed with this work for additional
    9  * information regarding copyright ownership.
   10  */
   11 
   12 #ifndef PK11_PK11_H
   13 #define PK11_PK11_H 1
   14 
   15 /*! \file pk11/pk11.h */
   16 
   17 #include <stdbool.h>
   18 #include <unistd.h>
   19 
   20 #include <isc/lang.h>
   21 #include <isc/magic.h>
   22 #include <isc/types.h>
   23 
   24 #define PK11_FATALCHECK(func, args)              \
   25     ((void)(((rv = (func)args) == CKR_OK) || \
   26         ((pk11_error_fatalcheck)(__FILE__, __LINE__, #func, rv), 0)))
   27 
   28 #include <pk11/site.h>
   29 #include <pkcs11/pkcs11.h>
   30 
   31 ISC_LANG_BEGINDECLS
   32 
   33 #define SES_MAGIC ISC_MAGIC('P', 'K', 'S', 'S')
   34 #define TOK_MAGIC ISC_MAGIC('P', 'K', 'T', 'K')
   35 
   36 #define VALID_SES(x) ISC_MAGIC_VALID(x, SES_MAGIC)
   37 #define VALID_TOK(x) ISC_MAGIC_VALID(x, TOK_MAGIC)
   38 
   39 typedef struct pk11_context pk11_context_t;
   40 
   41 struct pk11_object {
   42     CK_OBJECT_HANDLE object;
   43     CK_SLOT_ID   slot;
   44     CK_BBOOL     ontoken;
   45     CK_BBOOL     reqlogon;
   46     CK_BYTE      attrcnt;
   47     CK_ATTRIBUTE *   repr;
   48 };
   49 
   50 struct pk11_context {
   51     void *        handle;
   52     CK_SESSION_HANDLE session;
   53     CK_BBOOL      ontoken;
   54     CK_OBJECT_HANDLE  object;
   55 };
   56 
   57 typedef struct pk11_object pk11_object_t;
   58 
   59 typedef enum {
   60     OP_ANY = 0,
   61     OP_RSA = 1,
   62     OP_DH = 3,
   63     OP_ECDSA = 4,
   64     OP_EDDSA = 5,
   65     OP_MAX = 6
   66 } pk11_optype_t;
   67 
   68 /*%
   69  * Global flag to make choose_slots() verbose
   70  */
   71 LIBISC_EXTERNAL_DATA extern bool pk11_verbose_init;
   72 
   73 /*%
   74  * Function prototypes
   75  */
   76 
   77 void
   78 pk11_set_lib_name(const char *lib_name);
   79 /*%<
   80  * Set the PKCS#11 provider (aka library) path/name.
   81  */
   82 
   83 isc_result_t
   84 pk11_initialize(isc_mem_t *mctx, const char *engine);
   85 /*%<
   86  * Initialize PKCS#11 device
   87  *
   88  * mctx:   memory context to attach to pk11_mctx.
   89  * engine: PKCS#11 provider (aka library) path/name.
   90  *
   91  * returns:
   92  *         ISC_R_SUCCESS
   93  *         PK11_R_NOPROVIDER: can't load the provider
   94  *         PK11_R_INITFAILED: C_Initialize() failed
   95  *         PK11_R_NORANDOMSERVICE: can't find required random service
   96  *         PK11_R_NODIGESTSERVICE: can't find required digest service
   97  *         PK11_R_NOAESSERVICE: can't find required AES service
   98  */
   99 
  100 isc_result_t
  101 pk11_get_session(pk11_context_t *ctx, pk11_optype_t optype, bool need_services,
  102          bool rw, bool logon, const char *pin, CK_SLOT_ID slot);
  103 /*%<
  104  * Initialize PKCS#11 device and acquire a session.
  105  *
  106  * need_services:
  107  *    if true, this session requires full PKCS#11 API
  108  *    support including random and digest services, and
  109  *    the lack of these services will cause the session not
  110  *    to be initialized.  If false, the function will return
  111  *    an error code indicating the missing service, but the
  112  *    session will be usable for other purposes.
  113  * rw:    if true, session will be read/write (useful for
  114  *        generating or destroying keys); otherwise read-only.
  115  * login: indicates whether to log in to the device
  116  * pin:   optional PIN, overriding any PIN currently associated
  117  *        with the
  118  * slot:  device slot ID
  119  */
  120 
  121 void
  122 pk11_return_session(pk11_context_t *ctx);
  123 /*%<
  124  * Release an active PKCS#11 session for reuse.
  125  */
  126 
  127 isc_result_t
  128 pk11_finalize(void);
  129 /*%<
  130  * Shut down PKCS#11 device and free all sessions.
  131  */
  132 
  133 isc_result_t
  134 pk11_parse_uri(pk11_object_t *obj, const char *label, isc_mem_t *mctx,
  135            pk11_optype_t optype);
  136 
  137 ISC_PLATFORM_NORETURN_PRE void
  138 pk11_error_fatalcheck(const char *file, int line, const char *funcname,
  139               CK_RV rv) ISC_PLATFORM_NORETURN_POST;
  140 
  141 void
  142 pk11_dump_tokens(void);
  143 
  144 CK_RV
  145 pkcs_C_Initialize(CK_VOID_PTR pReserved);
  146 
  147 char *
  148 pk11_get_load_error_message(void);
  149 
  150 CK_RV
  151 pkcs_C_Finalize(CK_VOID_PTR pReserved);
  152 
  153 CK_RV
  154 pkcs_C_GetSlotList(CK_BBOOL tokenPresent, CK_SLOT_ID_PTR pSlotList,
  155            CK_ULONG_PTR pulCount);
  156 
  157 CK_RV
  158 pkcs_C_GetTokenInfo(CK_SLOT_ID slotID, CK_TOKEN_INFO_PTR pInfo);
  159 
  160 CK_RV
  161 pkcs_C_GetMechanismInfo(CK_SLOT_ID slotID, CK_MECHANISM_TYPE type,
  162             CK_MECHANISM_INFO_PTR pInfo);
  163 
  164 CK_RV
  165 pkcs_C_OpenSession(CK_SLOT_ID slotID, CK_FLAGS flags, CK_VOID_PTR pApplication,
  166            CK_RV (*Notify)(CK_SESSION_HANDLE hSession,
  167                    CK_NOTIFICATION   event,
  168                    CK_VOID_PTR       pApplication),
  169            CK_SESSION_HANDLE_PTR phSession);
  170 
  171 CK_RV
  172 pkcs_C_CloseSession(CK_SESSION_HANDLE hSession);
  173 
  174 CK_RV
  175 pkcs_C_Login(CK_SESSION_HANDLE hSession, CK_USER_TYPE userType,
  176          CK_CHAR_PTR pPin, CK_ULONG usPinLen);
  177 
  178 CK_RV
  179 pkcs_C_Logout(CK_SESSION_HANDLE hSession);
  180 
  181 CK_RV
  182 pkcs_C_CreateObject(CK_SESSION_HANDLE hSession, CK_ATTRIBUTE_PTR pTemplate,
  183             CK_ULONG usCount, CK_OBJECT_HANDLE_PTR phObject);
  184 
  185 CK_RV
  186 pkcs_C_DestroyObject(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject);
  187 
  188 CK_RV
  189 pkcs_C_GetAttributeValue(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject,
  190              CK_ATTRIBUTE_PTR pTemplate, CK_ULONG usCount);
  191 
  192 CK_RV
  193 pkcs_C_SetAttributeValue(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject,
  194              CK_ATTRIBUTE_PTR pTemplate, CK_ULONG usCount);
  195 
  196 CK_RV
  197 pkcs_C_FindObjectsInit(CK_SESSION_HANDLE hSession, CK_ATTRIBUTE_PTR pTemplate,
  198                CK_ULONG usCount);
  199 
  200 CK_RV
  201 pkcs_C_FindObjects(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE_PTR phObject,
  202            CK_ULONG usMaxObjectCount, CK_ULONG_PTR pusObjectCount);
  203 
  204 CK_RV
  205 pkcs_C_FindObjectsFinal(CK_SESSION_HANDLE hSession);
  206 
  207 CK_RV
  208 pkcs_C_EncryptInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism,
  209            CK_OBJECT_HANDLE hKey);
  210 
  211 CK_RV
  212 pkcs_C_Encrypt(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData,
  213            CK_ULONG ulDataLen, CK_BYTE_PTR pEncryptedData,
  214            CK_ULONG_PTR pulEncryptedDataLen);
  215 
  216 CK_RV
  217 pkcs_C_DigestInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism);
  218 
  219 CK_RV
  220 pkcs_C_DigestUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart,
  221             CK_ULONG ulPartLen);
  222 
  223 CK_RV
  224 pkcs_C_DigestFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pDigest,
  225            CK_ULONG_PTR pulDigestLen);
  226 
  227 CK_RV
  228 pkcs_C_SignInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism,
  229         CK_OBJECT_HANDLE hKey);
  230 
  231 CK_RV
  232 pkcs_C_Sign(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDataLen,
  233         CK_BYTE_PTR pSignature, CK_ULONG_PTR pulSignatureLen);
  234 
  235 CK_RV
  236 pkcs_C_SignUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart,
  237           CK_ULONG ulPartLen);
  238 
  239 CK_RV
  240 pkcs_C_SignFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSignature,
  241          CK_ULONG_PTR pulSignatureLen);
  242 
  243 CK_RV
  244 pkcs_C_VerifyInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism,
  245           CK_OBJECT_HANDLE hKey);
  246 
  247 CK_RV
  248 pkcs_C_Verify(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDataLen,
  249           CK_BYTE_PTR pSignature, CK_ULONG ulSignatureLen);
  250 
  251 CK_RV
  252 pkcs_C_VerifyUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart,
  253             CK_ULONG ulPartLen);
  254 
  255 CK_RV
  256 pkcs_C_VerifyFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSignature,
  257            CK_ULONG ulSignatureLen);
  258 
  259 CK_RV
  260 pkcs_C_GenerateKey(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism,
  261            CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount,
  262            CK_OBJECT_HANDLE_PTR phKey);
  263 
  264 CK_RV
  265 pkcs_C_GenerateKeyPair(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism,
  266                CK_ATTRIBUTE_PTR     pPublicKeyTemplate,
  267                CK_ULONG         usPublicKeyAttributeCount,
  268                CK_ATTRIBUTE_PTR     pPrivateKeyTemplate,
  269                CK_ULONG         usPrivateKeyAttributeCount,
  270                CK_OBJECT_HANDLE_PTR phPrivateKey,
  271                CK_OBJECT_HANDLE_PTR phPublicKey);
  272 
  273 CK_RV
  274 pkcs_C_DeriveKey(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism,
  275          CK_OBJECT_HANDLE hBaseKey, CK_ATTRIBUTE_PTR pTemplate,
  276          CK_ULONG ulAttributeCount, CK_OBJECT_HANDLE_PTR phKey);
  277 
  278 CK_RV
  279 pkcs_C_SeedRandom(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSeed,
  280           CK_ULONG ulSeedLen);
  281 
  282 CK_RV
  283 pkcs_C_GenerateRandom(CK_SESSION_HANDLE hSession, CK_BYTE_PTR RandomData,
  284               CK_ULONG ulRandomLen);
  285 
  286 ISC_LANG_ENDDECLS
  287 
  288 #endif /* PK11_PK11_H */