# provider-keymgmt(7) - man - phpMan

[PROVIDER-KEYMGMT(7SSL)](https://www.chedong.com/phpMan.php/man/PROVIDER-KEYMGMT/7SSL/markdown)                         OpenSSL                        [PROVIDER-KEYMGMT(7SSL)](https://www.chedong.com/phpMan.php/man/PROVIDER-KEYMGMT/7SSL/markdown)



## NAME
       provider-keymgmt - The KEYMGMT library <-> provider functions

## SYNOPSIS
        #include <openssl/core_dispatch.h>

        /*
         * None of these are actual functions, but are displayed like this for
         * the function signatures for functions that are offered as function
         * pointers in OSSL_DISPATCH arrays.
         */

        /* Key object (keydata) creation and destruction */
        void *OSSL_FUNC_keymgmt_new(void *provctx);
        void OSSL_FUNC_keymgmt_free(void *keydata);

        /* Generation, a more complex constructor */
        void *OSSL_FUNC_keymgmt_gen_init(void *provctx, int selection,
                                         const OSSL_PARAM params[]);
        int OSSL_FUNC_keymgmt_gen_set_template(void *genctx, void *template);
        int OSSL_FUNC_keymgmt_gen_set_params(void *genctx, const OSSL_PARAM params[]);
        const OSSL_PARAM *OSSL_FUNC_keymgmt_gen_settable_params(void *genctx,
                                                                void *provctx);
        void *OSSL_FUNC_keymgmt_gen(void *genctx, OSSL_CALLBACK *cb, void *cbarg);
        void OSSL_FUNC_keymgmt_gen_cleanup(void *genctx);

        /* Key loading by object reference, also a constructor */
        void *OSSL_FUNC_keymgmt_load(const void *reference, size_t *reference_sz);

        /* Key object information */
        int OSSL_FUNC_keymgmt_get_params(void *keydata, OSSL_PARAM params[]);
        const OSSL_PARAM *OSSL_FUNC_keymgmt_gettable_params(void *provctx);
        int OSSL_FUNC_keymgmt_set_params(void *keydata, const OSSL_PARAM params[]);
        const OSSL_PARAM *OSSL_FUNC_keymgmt_settable_params(void *provctx);

        /* Key object content checks */
        int OSSL_FUNC_keymgmt_has(const void *keydata, int selection);
        int OSSL_FUNC_keymgmt_match(const void *keydata1, const void *keydata2,
                                    int selection);

        /* Discovery of supported operations */
        const char *OSSL_FUNC_keymgmt_query_operation_name(int operation_id);

        /* Key object import and export functions */
        int OSSL_FUNC_keymgmt_import(int selection, void *keydata, const OSSL_PARAM params[]);
        const OSSL_PARAM *OSSL_FUNC_keymgmt_import_types(int selection);
        int OSSL_FUNC_keymgmt_export(int selection, void *keydata,
                                     OSSL_CALLBACK *param_cb, void *cbarg);
        const OSSL_PARAM *OSSL_FUNC_keymgmt_export_types(int selection);

        /* Key object duplication, a constructor */
        void *OSSL_FUNC_keymgmt_dup(const void *keydata_from, int selection);

        /* Key object validation */
        int OSSL_FUNC_keymgmt_validate(const void *keydata, int selection, int checktype);

## DESCRIPTION
       The KEYMGMT operation doesn't have much public visibility in OpenSSL libraries, it's rather
       an internal operation that's designed to work in tandem with operations that use
       private/public key pairs.

       Because the KEYMGMT operation shares knowledge with the operations it works with in tandem,
       they must belong to the same provider.  The OpenSSL libraries will ensure that they do.

       The primary responsibility of the KEYMGMT operation is to hold the provider side key data for
       the OpenSSL library EVP_PKEY structure.

       All "functions" mentioned here are passed as function pointers between _libcrypto_ and the
       provider in **OSSL**___**DISPATCH** arrays via **OSSL**___**ALGORITHM** arrays that are returned by the
       provider's **provider**___**query**___**operation()** function (see "Provider Functions" in
       [**provider-base**(7)](https://www.chedong.com/phpMan.php/man/provider-base/7/markdown)).

       All these "functions" have a corresponding function type definition named
       **OSSL**___**FUNC**___**{name}**___**fn**, and a helper function to retrieve the function pointer from a
       **OSSL**___**DISPATCH** element named **OSSL**___**FUNC**___**{name}**.  For example, the "function"
       **OSSL**___**FUNC**___**keymgmt**___**new()** has these:

        typedef void *(OSSL_FUNC_keymgmt_new_fn)(void *provctx);
        static ossl_inline OSSL_FUNC_keymgmt_new_fn
            OSSL_FUNC_keymgmt_new(const OSSL_DISPATCH *opf);

       **OSSL**___**DISPATCH** arrays are indexed by numbers that are provided as macros in
       **openssl-core**___**[dispatch.h**(7)](https://www.chedong.com/phpMan.php/man/dispatch.h/7/markdown), as follows:

        OSSL_FUNC_keymgmt_new                  OSSL_FUNC_KEYMGMT_NEW
        OSSL_FUNC_keymgmt_free                 OSSL_FUNC_KEYMGMT_FREE

        OSSL_FUNC_keymgmt_gen_init             OSSL_FUNC_KEYMGMT_GEN_INIT
        OSSL_FUNC_keymgmt_gen_set_template     OSSL_FUNC_KEYMGMT_GEN_SET_TEMPLATE
        OSSL_FUNC_keymgmt_gen_set_params       OSSL_FUNC_KEYMGMT_GEN_SET_PARAMS
        OSSL_FUNC_keymgmt_gen_settable_params  OSSL_FUNC_KEYMGMT_GEN_SETTABLE_PARAMS
        OSSL_FUNC_keymgmt_gen                  OSSL_FUNC_KEYMGMT_GEN
        OSSL_FUNC_keymgmt_gen_cleanup          OSSL_FUNC_KEYMGMT_GEN_CLEANUP

        OSSL_FUNC_keymgmt_load                 OSSL_FUNC_KEYMGMT_LOAD

        OSSL_FUNC_keymgmt_get_params           OSSL_FUNC_KEYMGMT_GET_PARAMS
        OSSL_FUNC_keymgmt_gettable_params      OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS
        OSSL_FUNC_keymgmt_set_params           OSSL_FUNC_KEYMGMT_SET_PARAMS
        OSSL_FUNC_keymgmt_settable_params      OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS

        OSSL_FUNC_keymgmt_query_operation_name OSSL_FUNC_KEYMGMT_QUERY_OPERATION_NAME

        OSSL_FUNC_keymgmt_has                  OSSL_FUNC_KEYMGMT_HAS
        OSSL_FUNC_keymgmt_validate             OSSL_FUNC_KEYMGMT_VALIDATE
        OSSL_FUNC_keymgmt_match                OSSL_FUNC_KEYMGMT_MATCH

        OSSL_FUNC_keymgmt_import               OSSL_FUNC_KEYMGMT_IMPORT
        OSSL_FUNC_keymgmt_import_types         OSSL_FUNC_KEYMGMT_IMPORT_TYPES
        OSSL_FUNC_keymgmt_export               OSSL_FUNC_KEYMGMT_EXPORT
        OSSL_FUNC_keymgmt_export_types         OSSL_FUNC_KEYMGMT_EXPORT_TYPES

        OSSL_FUNC_keymgmt_dup                  OSSL_FUNC_KEYMGMT_DUP

### Key Objects
       A key object is a collection of data for an asymmetric key, and is represented as _keydata_ in
       this manual.

       The exact contents of a key object are defined by the provider, and it is assumed that
       different operations in one and the same provider use the exact same structure to represent
       this collection of data, so that for example, a key object that has been created using the
       KEYMGMT interface that we document here can be passed as is to other provider operations,
       such as **OP**___**signature**___**sign**___**init()** (see [**provider-signature**(7)](https://www.chedong.com/phpMan.php/man/provider-signature/7/markdown)).

       With some of the KEYMGMT functions, it's possible to select a specific subset of data to
       handle, governed by the bits in a _selection_ indicator.  The bits are:

       **OSSL**___**KEYMGMT**___**SELECT**___**PRIVATE**___**KEY**
           Indicating that the private key data in a key object should be considered.

       **OSSL**___**KEYMGMT**___**SELECT**___**PUBLIC**___**KEY**
           Indicating that the public key data in a key object should be considered.

       **OSSL**___**KEYMGMT**___**SELECT**___**DOMAIN**___**PARAMETERS**
           Indicating that the domain parameters in a key object should be considered.

       **OSSL**___**KEYMGMT**___**SELECT**___**OTHER**___**PARAMETERS**
           Indicating that other parameters in a key object should be considered.

           Other parameters are key parameters that don't fit any other classification.  In other
           words, this particular selector bit works as a last resort bit bucket selector.

       Some selector bits have also been combined for easier use:

       **OSSL**___**KEYMGMT**___**SELECT**___**ALL**___**PARAMETERS**
           Indicating that all key object parameters should be considered, regardless of their more
           granular classification.

           This is a combination of **OSSL**___**KEYMGMT**___**SELECT**___**DOMAIN**___**PARAMETERS** and
           **OSSL**___**KEYMGMT**___**SELECT**___**OTHER**___**PARAMETERS**.

       **OSSL**___**KEYMGMT**___**SELECT**___**KEYPAIR**
           Indicating that both the whole key pair in a key object should be considered, i.e. the
           combination of public and private key.

           This is a combination of **OSSL**___**KEYMGMT**___**SELECT**___**PRIVATE**___**KEY** and
           **OSSL**___**KEYMGMT**___**SELECT**___**PUBLIC**___**KEY**.

       **OSSL**___**KEYMGMT**___**SELECT**___**ALL**
           Indicating that everything in a key object should be considered.

       The exact interpretation of those bits or how they combine is left to each function where you
       can specify a selector.

       It's left to the provider implementation to decide what is reasonable to do with regards to
       received selector bits and how to do it.  Among others, an implementation of
       **OSSL**___**FUNC**___**keymgmt**___**match()** might opt to not compare the private half if it has compared the
       public half, since a match of one half implies a match of the other half.

### Constructing and Destructing Functions
       **OSSL**___**FUNC**___**keymgmt**___**new()** should create a provider side key object.  The provider context
       _provctx_ is passed and may be incorporated in the key object, but that is not mandatory.

       **OSSL**___**FUNC**___**keymgmt**___**free()** should free the passed _keydata_.

       **OSSL**___**FUNC**___**keymgmt**___**gen**___**init()**, **OSSL**___**FUNC**___**keymgmt**___**gen**___**set**___**template()**,
       **OSSL**___**FUNC**___**keymgmt**___**gen**___**set**___**params()**, **OSSL**___**FUNC**___**keymgmt**___**gen**___**settable**___**params()**,
       **OSSL**___**FUNC**___**keymgmt**___**gen()** and **OSSL**___**FUNC**___**keymgmt**___**gen**___**cleanup()** work together as a more elaborate
       context based key object constructor.

       **OSSL**___**FUNC**___**keymgmt**___**gen**___**init()** should create the key object generation context and initialize
       it with _selections_, which will determine what kind of contents the key object to be generated
       should get.  The _params_, if not NULL, should be set on the context in a manner similar to
       using **OSSL**___**FUNC**___**keymgmt**___**set**___**params()**.

       **OSSL**___**FUNC**___**keymgmt**___**gen**___**set**___**template()** should add _template_ to the context _genctx_.  The _template_
       is assumed to be a key object constructed with the same KEYMGMT, and from which content that
       the implementation chooses can be used as a template for the key object to be generated.
       Typically, the generation of a DSA or DH key would get the domain parameters from this
       _template_.

       **OSSL**___**FUNC**___**keymgmt**___**gen**___**set**___**params()** should set additional parameters from _params_ in the key
       object generation context _genctx_.

       **OSSL**___**FUNC**___**keymgmt**___**gen**___**settable**___**params()** should return a constant array of descriptor
       **OSSL**___**PARAM**, for parameters that **OSSL**___**FUNC**___**keymgmt**___**gen**___**set**___**params()** can handle.

       **OSSL**___**FUNC**___**keymgmt**___**gen()** should perform the key object generation itself, and return the
       result.  The callback _cb_ should be called at regular intervals with indications on how the
       key object generation progresses.

       **OSSL**___**FUNC**___**keymgmt**___**gen**___**cleanup()** should clean up and free the key object generation context
       _genctx_

       **OSSL**___**FUNC**___**keymgmt**___**load()** creates a provider side key object based on a _reference_ object with
       a size of _reference_sz_ bytes, that only the provider knows how to interpret, but that may
       come from other operations.  Outside the provider, this reference is simply an array of
       bytes.

       At least one of **OSSL**___**FUNC**___**keymgmt**___**new()**, **OSSL**___**FUNC**___**keymgmt**___**gen()** and **OSSL**___**FUNC**___**keymgmt**___**load()**
       are mandatory, as well as **OSSL**___**FUNC**___**keymgmt**___**free()** and **OSSL**___**FUNC**___**keymgmt**___**has()**. Additionally,
       if **OSSL**___**FUNC**___**keymgmt**___**gen()** is present, **OSSL**___**FUNC**___**keymgmt**___**gen**___**init()** and
       **OSSL**___**FUNC**___**keymgmt**___**gen**___**cleanup()** must be present as well.

### Key Object Information Functions
       **OSSL**___**FUNC**___**keymgmt**___**get**___**params()** should extract information data associated with the given
       _keydata_, see "Common Information Parameters".

       **OSSL**___**FUNC**___**keymgmt**___**gettable**___**params()** should return a constant array of descriptor **OSSL**___**PARAM**,
       for parameters that **OSSL**___**FUNC**___**keymgmt**___**get**___**params()** can handle.

       If **OSSL**___**FUNC**___**keymgmt**___**gettable**___**params()** is present, **OSSL**___**FUNC**___**keymgmt**___**get**___**params()** must also
       be present, and vice versa.

       **OSSL**___**FUNC**___**keymgmt**___**set**___**params()** should update information data associated with the given
       _keydata_, see "Common Information Parameters".

       **OSSL**___**FUNC**___**keymgmt**___**settable**___**params()** should return a constant array of descriptor **OSSL**___**PARAM**,
       for parameters that **OSSL**___**FUNC**___**keymgmt**___**set**___**params()** can handle.

       If **OSSL**___**FUNC**___**keymgmt**___**settable**___**params()** is present, **OSSL**___**FUNC**___**keymgmt**___**set**___**params()** must also
       be present, and vice versa.

### Key Object Checking Functions
       **OSSL**___**FUNC**___**keymgmt**___**query**___**operation**___**name()** should return the name of the supported algorithm
       for the operation _operation_id_.  This is similar to **provider**___**query**___**operation()** (see
       [**provider-base**(7)](https://www.chedong.com/phpMan.php/man/provider-base/7/markdown)), but only works as an advisory.  If this function is not present, or
       returns NULL, the caller is free to assume that there's an algorithm from the same provider,
       of the same name as the one used to fetch the keymgmt and try to use that.

       **OSSL**___**FUNC**___**keymgmt**___**has()** should check whether the given _keydata_ contains the subsets of data
       indicated by the _selector_.  A combination of several selector bits must consider all those
       subsets, not just one.  An implementation is, however, free to consider an empty subset of
       data to still be a valid subset. For algorithms where some selection is not meaningful such
       as **OSSL**___**KEYMGMT**___**SELECT**___**DOMAIN**___**PARAMETERS** for RSA keys the function should just return 1 as
       the selected subset is not really missing in the key.

       **OSSL**___**FUNC**___**keymgmt**___**validate()** should check if the _keydata_ contains valid data subsets
       indicated by _selection_.  Some combined selections of data subsets may cause validation of the
       combined data.  For example, the combination of **OSSL**___**KEYMGMT**___**SELECT**___**PRIVATE**___**KEY** and
       **OSSL**___**KEYMGMT**___**SELECT**___**PUBLIC**___**KEY** (or **OSSL**___**KEYMGMT**___**SELECT**___**KEYPAIR** for short) is expected to
       check that the pairwise consistency of _keydata_ is valid. The _checktype_ parameter controls
       what type of check is performed on the subset of data. Two types of check are defined:
       **OSSL**___**KEYMGMT**___**VALIDATE**___**FULL**___**CHECK** and **OSSL**___**KEYMGMT**___**VALIDATE**___**QUICK**___**CHECK**.  The interpretation
       of how much checking is performed in a full check versus a quick check is key type specific.
       Some providers may have no distinction between a full check and a quick check. For algorithms
       where some selection is not meaningful such as **OSSL**___**KEYMGMT**___**SELECT**___**DOMAIN**___**PARAMETERS** for RSA
       keys the function should just return 1 as there is nothing to validate for that selection.

       **OSSL**___**FUNC**___**keymgmt**___**match()** should check if the data subset indicated by _selection_ in _keydata1_
       and _keydata2_ match.  It is assumed that the caller has ensured that _keydata1_ and _keydata2_ are
       both owned by the implementation of this function.

### Key Object Import, Export and Duplication Functions
       **OSSL**___**FUNC**___**keymgmt**___**import()** should import data indicated by _selection_ into _keydata_ with values
       taken from the **OSSL**___**PARAM** array _params_.

       **OSSL**___**FUNC**___**keymgmt**___**export()** should extract values indicated by _selection_ from _keydata_, create
       an **OSSL**___**PARAM** array with them and call _param_cb_ with that array as well as the given _cbarg_.

       **OSSL**___**FUNC**___**keymgmt**___**import**___**types()** should return a constant array of descriptor **OSSL**___**PARAM** for
       data indicated by _selection_, for parameters that **OSSL**___**FUNC**___**keymgmt**___**import()** can handle.

       **OSSL**___**FUNC**___**keymgmt**___**export**___**types()** should return a constant array of descriptor **OSSL**___**PARAM** for
       data indicated by _selection_, that the **OSSL**___**FUNC**___**keymgmt**___**export()** callback can expect to
       receive.

       **OSSL**___**FUNC**___**keymgmt**___**dup()** should duplicate data subsets indicated by _selection_ or the whole key
       data _keydata_from_ and create a new provider side key object with the data.

### Common Information Parameters
       See **OSSL**___**[PARAM**(3)](https://www.chedong.com/phpMan.php/man/PARAM/3/markdown) for further details on the parameters structure.

       Common information parameters currently recognised by all built-in keymgmt algorithms are as
       follows:

       "bits" (**OSSL**___**PKEY**___**PARAM**___**BITS**) <integer>
           The value should be the cryptographic length of the cryptosystem to which the key
           belongs, in bits.  The definition of cryptographic length is specific to the key
           cryptosystem.

       "max-size" (**OSSL**___**PKEY**___**PARAM**___**MAX**___**SIZE**) <integer>
           The value should be the maximum size that a caller should allocate to safely store a
           signature (called _sig_ in [**provider-signature**(7)](https://www.chedong.com/phpMan.php/man/provider-signature/7/markdown)), the result of asymmmetric encryption /
           decryption (_out_ in **provider-asym**___**[cipher**(7)](https://www.chedong.com/phpMan.php/man/cipher/7/markdown), a derived secret (_secret_ in
           [**provider-keyexch**(7)](https://www.chedong.com/phpMan.php/man/provider-keyexch/7/markdown), and similar data).

           Because an EVP_KEYMGMT method is always tightly bound to another method (signature,
           asymmetric cipher, key exchange, ...) and must be of the same provider, this number only
           needs to be synchronised with the dimensions handled in the rest of the same provider.

       "security-bits" (**OSSL**___**PKEY**___**PARAM**___**SECURITY**___**BITS**) <integer>
           The value should be the number of security bits of the given key.  Bits of security is
           defined in SP800-57.

## RETURN VALUES
       **OSSL**___**FUNC**___**keymgmt**___**new()** and **OSSL**___**FUNC**___**keymgmt**___**dup()** should return a valid reference to the
       newly created provider side key object, or NULL on failure.

       **OSSL**___**FUNC**___**keymgmt**___**import()**, **OSSL**___**FUNC**___**keymgmt**___**export()**, **OSSL**___**FUNC**___**keymgmt**___**get**___**params()** and
       **OSSL**___**FUNC**___**keymgmt**___**set**___**params()** should return 1 for success or 0 on error.

       **OSSL**___**FUNC**___**keymgmt**___**validate()** should return 1 on successful validation, or 0 on failure.

       **OSSL**___**FUNC**___**keymgmt**___**has()** should return 1 if all the selected data subsets are contained in the
       given _keydata_ or 0 otherwise.

       **OSSL**___**FUNC**___**keymgmt**___**query**___**operation**___**name()** should return a pointer to a string matching the
       requested operation, or NULL if the same name used to fetch the keymgmt applies.

       **OSSL**___**FUNC**___**keymgmt**___**gettable**___**params()** and **OSSL**___**FUNC**___**keymgmt**___**settable**___**params()**
       **OSSL**___**FUNC**___**keymgmt**___**import**___**types()**, **OSSL**___**FUNC**___**keymgmt**___**export**___**types()** should always return a
       constant **OSSL**___**PARAM** array.

## SEE ALSO
       [**provider**(7)](https://www.chedong.com/phpMan.php/man/provider/7/markdown), **EVP**___**[PKEY-X25519**(7)](https://www.chedong.com/phpMan.php/man/PKEY-X25519/7/markdown), **EVP**___**[PKEY-X448**(7)](https://www.chedong.com/phpMan.php/man/PKEY-X448/7/markdown), **EVP**___**[PKEY-ED25519**(7)](https://www.chedong.com/phpMan.php/man/PKEY-ED25519/7/markdown), **EVP**___**[PKEY-ED448**(7)](https://www.chedong.com/phpMan.php/man/PKEY-ED448/7/markdown),
       **EVP**___**[PKEY-EC**(7)](https://www.chedong.com/phpMan.php/man/PKEY-EC/7/markdown), **EVP**___**[PKEY-RSA**(7)](https://www.chedong.com/phpMan.php/man/PKEY-RSA/7/markdown), **EVP**___**[PKEY-DSA**(7)](https://www.chedong.com/phpMan.php/man/PKEY-DSA/7/markdown), **EVP**___**[PKEY-DH**(7)](https://www.chedong.com/phpMan.php/man/PKEY-DH/7/markdown)

## HISTORY
       The KEYMGMT interface was introduced in OpenSSL 3.0.

## COPYRIGHT
       Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.

       Licensed under the Apache License 2.0 (the "License").  You may not use this file except in
       compliance with the License.  You can obtain a copy in the file LICENSE in the source
       distribution or at <<https://www.openssl.org/source/license.html>>.



3.0.2                                        2026-04-07                       [PROVIDER-KEYMGMT(7SSL)](https://www.chedong.com/phpMan.php/man/PROVIDER-KEYMGMT/7SSL/markdown)
