Blame crypto/engine/eng_local.h

Packit c4476c
/*
Packit c4476c
 * Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved.
Packit c4476c
 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
Packit c4476c
 *
Packit c4476c
 * Licensed under the OpenSSL license (the "License").  You may not use
Packit c4476c
 * this file except in compliance with the License.  You can obtain a copy
Packit c4476c
 * in the file LICENSE in the source distribution or at
Packit c4476c
 * https://www.openssl.org/source/license.html
Packit c4476c
 */
Packit c4476c
Packit c4476c
#ifndef OSSL_CRYPTO_ENGINE_ENG_LOCAL_H
Packit c4476c
# define OSSL_CRYPTO_ENGINE_ENG_LOCAL_H
Packit c4476c
Packit c4476c
# include "internal/cryptlib.h"
Packit c4476c
# include "crypto/engine.h"
Packit c4476c
# include "internal/thread_once.h"
Packit c4476c
# include "internal/refcount.h"
Packit c4476c
Packit c4476c
extern CRYPTO_RWLOCK *global_engine_lock;
Packit c4476c
Packit c4476c
/*
Packit c4476c
 * If we compile with this symbol defined, then both reference counts in the
Packit c4476c
 * ENGINE structure will be monitored with a line of output on stderr for
Packit c4476c
 * each change. This prints the engine's pointer address (truncated to
Packit c4476c
 * unsigned int), "struct" or "funct" to indicate the reference type, the
Packit c4476c
 * before and after reference count, and the file:line-number pair. The
Packit c4476c
 * "engine_ref_debug" statements must come *after* the change.
Packit c4476c
 */
Packit c4476c
# ifdef ENGINE_REF_COUNT_DEBUG
Packit c4476c
Packit c4476c
#  define engine_ref_debug(e, isfunct, diff) \
Packit c4476c
        fprintf(stderr, "engine: %08x %s from %d to %d (%s:%d)\n", \
Packit c4476c
                (unsigned int)(e), (isfunct ? "funct" : "struct"), \
Packit c4476c
                ((isfunct) ? ((e)->funct_ref - (diff)) : ((e)->struct_ref - (diff))), \
Packit c4476c
                ((isfunct) ? (e)->funct_ref : (e)->struct_ref), \
Packit c4476c
                (OPENSSL_FILE), (OPENSSL_LINE))
Packit c4476c
Packit c4476c
# else
Packit c4476c
Packit c4476c
#  define engine_ref_debug(e, isfunct, diff)
Packit c4476c
Packit c4476c
# endif
Packit c4476c
Packit c4476c
/*
Packit c4476c
 * Any code that will need cleanup operations should use these functions to
Packit c4476c
 * register callbacks. engine_cleanup_int() will call all registered
Packit c4476c
 * callbacks in order. NB: both the "add" functions assume the engine lock to
Packit c4476c
 * already be held (in "write" mode).
Packit c4476c
 */
Packit c4476c
typedef void (ENGINE_CLEANUP_CB) (void);
Packit c4476c
typedef struct st_engine_cleanup_item {
Packit c4476c
    ENGINE_CLEANUP_CB *cb;
Packit c4476c
} ENGINE_CLEANUP_ITEM;
Packit c4476c
DEFINE_STACK_OF(ENGINE_CLEANUP_ITEM)
Packit c4476c
void engine_cleanup_add_first(ENGINE_CLEANUP_CB *cb);
Packit c4476c
void engine_cleanup_add_last(ENGINE_CLEANUP_CB *cb);
Packit c4476c
Packit c4476c
/* We need stacks of ENGINEs for use in eng_table.c */
Packit c4476c
DEFINE_STACK_OF(ENGINE)
Packit c4476c
Packit c4476c
/*
Packit c4476c
 * If this symbol is defined then engine_table_select(), the function that is
Packit c4476c
 * used by RSA, DSA (etc) code to select registered ENGINEs, cache defaults
Packit c4476c
 * and functional references (etc), will display debugging summaries to
Packit c4476c
 * stderr.
Packit c4476c
 */
Packit c4476c
/* #define ENGINE_TABLE_DEBUG */
Packit c4476c
Packit c4476c
/*
Packit c4476c
 * This represents an implementation table. Dependent code should instantiate
Packit c4476c
 * it as a (ENGINE_TABLE *) pointer value set initially to NULL.
Packit c4476c
 */
Packit c4476c
typedef struct st_engine_table ENGINE_TABLE;
Packit c4476c
int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,
Packit c4476c
                          ENGINE *e, const int *nids, int num_nids,
Packit c4476c
                          int setdefault);
Packit c4476c
void engine_table_unregister(ENGINE_TABLE **table, ENGINE *e);
Packit c4476c
void engine_table_cleanup(ENGINE_TABLE **table);
Packit c4476c
# ifndef ENGINE_TABLE_DEBUG
Packit c4476c
ENGINE *engine_table_select(ENGINE_TABLE **table, int nid);
Packit c4476c
# else
Packit c4476c
ENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f,
Packit c4476c
                                int l);
Packit c4476c
#  define engine_table_select(t,n) engine_table_select_tmp(t,n,OPENSSL_FILE,OPENSSL_LINE)
Packit c4476c
# endif
Packit c4476c
typedef void (engine_table_doall_cb) (int nid, STACK_OF(ENGINE) *sk,
Packit c4476c
                                      ENGINE *def, void *arg);
Packit c4476c
void engine_table_doall(ENGINE_TABLE *table, engine_table_doall_cb *cb,
Packit c4476c
                        void *arg);
Packit c4476c
Packit c4476c
/*
Packit c4476c
 * Internal versions of API functions that have control over locking. These
Packit c4476c
 * are used between C files when functionality needs to be shared but the
Packit c4476c
 * caller may already be controlling of the engine lock.
Packit c4476c
 */
Packit c4476c
int engine_unlocked_init(ENGINE *e);
Packit c4476c
int engine_unlocked_finish(ENGINE *e, int unlock_for_handlers);
Packit c4476c
int engine_free_util(ENGINE *e, int not_locked);
Packit c4476c
Packit c4476c
/*
Packit c4476c
 * This function will reset all "set"able values in an ENGINE to NULL. This
Packit c4476c
 * won't touch reference counts or ex_data, but is equivalent to calling all
Packit c4476c
 * the ENGINE_set_***() functions with a NULL value.
Packit c4476c
 */
Packit c4476c
void engine_set_all_null(ENGINE *e);
Packit c4476c
Packit c4476c
/*
Packit c4476c
 * NB: Bitwise OR-able values for the "flags" variable in ENGINE are now
Packit c4476c
 * exposed in engine.h.
Packit c4476c
 */
Packit c4476c
Packit c4476c
/* Free up dynamically allocated public key methods associated with ENGINE */
Packit c4476c
Packit c4476c
void engine_pkey_meths_free(ENGINE *e);
Packit c4476c
void engine_pkey_asn1_meths_free(ENGINE *e);
Packit c4476c
Packit c4476c
/* Once initialisation function */
Packit c4476c
extern CRYPTO_ONCE engine_lock_init;
Packit c4476c
DECLARE_RUN_ONCE(do_engine_lock_init)
Packit c4476c
Packit c4476c
/*
Packit c4476c
 * This is a structure for storing implementations of various crypto
Packit c4476c
 * algorithms and functions.
Packit c4476c
 */
Packit c4476c
struct engine_st {
Packit c4476c
    const char *id;
Packit c4476c
    const char *name;
Packit c4476c
    const RSA_METHOD *rsa_meth;
Packit c4476c
    const DSA_METHOD *dsa_meth;
Packit c4476c
    const DH_METHOD *dh_meth;
Packit c4476c
    const EC_KEY_METHOD *ec_meth;
Packit c4476c
    const RAND_METHOD *rand_meth;
Packit c4476c
    /* Cipher handling is via this callback */
Packit c4476c
    ENGINE_CIPHERS_PTR ciphers;
Packit c4476c
    /* Digest handling is via this callback */
Packit c4476c
    ENGINE_DIGESTS_PTR digests;
Packit c4476c
    /* Public key handling via this callback */
Packit c4476c
    ENGINE_PKEY_METHS_PTR pkey_meths;
Packit c4476c
    /* ASN1 public key handling via this callback */
Packit c4476c
    ENGINE_PKEY_ASN1_METHS_PTR pkey_asn1_meths;
Packit c4476c
    ENGINE_GEN_INT_FUNC_PTR destroy;
Packit c4476c
    ENGINE_GEN_INT_FUNC_PTR init;
Packit c4476c
    ENGINE_GEN_INT_FUNC_PTR finish;
Packit c4476c
    ENGINE_CTRL_FUNC_PTR ctrl;
Packit c4476c
    ENGINE_LOAD_KEY_PTR load_privkey;
Packit c4476c
    ENGINE_LOAD_KEY_PTR load_pubkey;
Packit c4476c
    ENGINE_SSL_CLIENT_CERT_PTR load_ssl_client_cert;
Packit c4476c
    const ENGINE_CMD_DEFN *cmd_defns;
Packit c4476c
    int flags;
Packit c4476c
    /* reference count on the structure itself */
Packit c4476c
    CRYPTO_REF_COUNT struct_ref;
Packit c4476c
    /*
Packit c4476c
     * reference count on usability of the engine type. NB: This controls the
Packit c4476c
     * loading and initialisation of any functionality required by this
Packit c4476c
     * engine, whereas the previous count is simply to cope with
Packit c4476c
     * (de)allocation of this structure. Hence, running_ref <= struct_ref at
Packit c4476c
     * all times.
Packit c4476c
     */
Packit c4476c
    int funct_ref;
Packit c4476c
    /* A place to store per-ENGINE data */
Packit c4476c
    CRYPTO_EX_DATA ex_data;
Packit c4476c
    /* Used to maintain the linked-list of engines. */
Packit c4476c
    struct engine_st *prev;
Packit c4476c
    struct engine_st *next;
Packit c4476c
};
Packit c4476c
Packit c4476c
typedef struct st_engine_pile ENGINE_PILE;
Packit c4476c
Packit c4476c
DEFINE_LHASH_OF(ENGINE_PILE);
Packit c4476c
Packit c4476c
#endif                          /* OSSL_CRYPTO_ENGINE_ENG_LOCAL_H */