{
    "mode": "info",
    "parameter": "PROVIDER-KEYEXCH",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/info/PROVIDER-KEYEXCH/json",
    "generated": "2026-07-05T23:22:02Z",
    "synopsis": "#include <openssl/coredispatch.h>\n#include <openssl/corenames.h>\n/*\n* None of these are actual functions, but are displayed like this for\n* the function signatures for functions that are offered as function\n* pointers in OSSLDISPATCH arrays.\n*/\n/* Context management */\nvoid *OSSLFUNCkeyexchnewctx(void *provctx);\nvoid OSSLFUNCkeyexchfreectx(void *ctx);\nvoid *OSSLFUNCkeyexchdupctx(void *ctx);\n/* Shared secret derivation */\nint OSSLFUNCkeyexchinit(void *ctx, void *provkey,\nconst OSSLPARAM params[]);\nint OSSLFUNCkeyexchsetpeer(void *ctx, void *provkey);\nint OSSLFUNCkeyexchderive(void *ctx, unsigned char *secret, sizet *secretlen,\nsizet outlen);\n/* Key Exchange parameters */\nint OSSLFUNCkeyexchsetctxparams(void *ctx, const OSSLPARAM params[]);\nconst OSSLPARAM *OSSLFUNCkeyexchsettablectxparams(void *ctx,\nvoid *provctx);\nint OSSLFUNCkeyexchgetctxparams(void *ctx, OSSLPARAM params[]);\nconst OSSLPARAM *OSSLFUNCkeyexchgettablectxparams(void *ctx,\nvoid *provctx);",
    "sections": {
        "NAME": {
            "content": "provider-keyexch - The keyexch library <-> provider functions\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "#include <openssl/coredispatch.h>\n#include <openssl/corenames.h>\n\n/*\n* None of these are actual functions, but are displayed like this for\n* the function signatures for functions that are offered as function\n* pointers in OSSLDISPATCH arrays.\n*/\n\n/* Context management */\nvoid *OSSLFUNCkeyexchnewctx(void *provctx);\nvoid OSSLFUNCkeyexchfreectx(void *ctx);\nvoid *OSSLFUNCkeyexchdupctx(void *ctx);\n\n/* Shared secret derivation */\nint OSSLFUNCkeyexchinit(void *ctx, void *provkey,\nconst OSSLPARAM params[]);\nint OSSLFUNCkeyexchsetpeer(void *ctx, void *provkey);\nint OSSLFUNCkeyexchderive(void *ctx, unsigned char *secret, sizet *secretlen,\nsizet outlen);\n\n/* Key Exchange parameters */\nint OSSLFUNCkeyexchsetctxparams(void *ctx, const OSSLPARAM params[]);\nconst OSSLPARAM *OSSLFUNCkeyexchsettablectxparams(void *ctx,\nvoid *provctx);\nint OSSLFUNCkeyexchgetctxparams(void *ctx, OSSLPARAM params[]);\nconst OSSLPARAM *OSSLFUNCkeyexchgettablectxparams(void *ctx,\nvoid *provctx);\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This documentation is primarily aimed at provider authors. See\nprovider(7) for further information.\n\nThe key exchange (OSSLOPKEYEXCH) operation enables providers to\nimplement key exchange algorithms and make them available to\napplications via EVPPKEYderive(3) and other related functions).\n\nAll \"functions\" mentioned here are passed as function pointers between\nlibcrypto and the provider in OSSLDISPATCH arrays via OSSLALGORITHM\narrays that are returned by the provider's providerqueryoperation()\nfunction (see \"Provider Functions\" in provider-base(7)).\n\nAll these \"functions\" have a corresponding function type definition\nnamed OSSLFUNC{name}fn, and a helper function to retrieve the\nfunction pointer from an OSSLDISPATCH element named OSSLFUNC{name}.\nFor example, the \"function\" OSSLFUNCkeyexchnewctx() has these:\n\ntypedef void *(OSSLFUNCkeyexchnewctxfn)(void *provctx);\nstatic osslinline OSSLFUNCkeyexchnewctxfn\nOSSLFUNCkeyexchnewctx(const OSSLDISPATCH *opf);\n\nOSSLDISPATCH arrays are indexed by numbers that are provided as macros\nin openssl-coredispatch.h(7), as follows:\n\nOSSLFUNCkeyexchnewctx                OSSLFUNCKEYEXCHNEWCTX\nOSSLFUNCkeyexchfreectx               OSSLFUNCKEYEXCHFREECTX\nOSSLFUNCkeyexchdupctx                OSSLFUNCKEYEXCHDUPCTX\n\nOSSLFUNCkeyexchinit                  OSSLFUNCKEYEXCHINIT\nOSSLFUNCkeyexchsetpeer              OSSLFUNCKEYEXCHSETPEER\nOSSLFUNCkeyexchderive                OSSLFUNCKEYEXCHDERIVE\n\nOSSLFUNCkeyexchsetctxparams        OSSLFUNCKEYEXCHSETCTXPARAMS\nOSSLFUNCkeyexchsettablectxparams   OSSLFUNCKEYEXCHSETTABLECTXPARAMS\nOSSLFUNCkeyexchgetctxparams        OSSLFUNCKEYEXCHGETCTXPARAMS\nOSSLFUNCkeyexchgettablectxparams   OSSLFUNCKEYEXCHGETTABLECTXPARAMS\n\nA key exchange algorithm implementation may not implement all of these\nfunctions.  In order to be a consistent set of functions a provider\nmust implement OSSLFUNCkeyexchnewctx, OSSLFUNCkeyexchfreectx,\nOSSLFUNCkeyexchinit and OSSLFUNCkeyexchderive.  All other\nfunctions are optional.\n\nA key exchange algorithm must also implement some mechanism for\ngenerating, loading or importing keys via the key management\n(OSSLOPKEYMGMT) operation.  See provider-keymgmt(7) for further\ndetails.\n\nContext Management Functions\nOSSLFUNCkeyexchnewctx() should create and return a pointer to a\nprovider side structure for holding context information during a key\nexchange operation.  A pointer to this context will be passed back in a\nnumber of the other key exchange operation function calls.  The\nparameter provctx is the provider context generated during provider\ninitialisation (see provider(7)).\n\nOSSLFUNCkeyexchfreectx() is passed a pointer to the provider side\nkey exchange context in the ctx parameter.  This function should free\nany resources associated with that context.\n\nOSSLFUNCkeyexchdupctx() should duplicate the provider side key\nexchange context in the ctx parameter and return the duplicate copy.\n\nShared Secret Derivation Functions\nOSSLFUNCkeyexchinit() initialises a key exchange operation given a\nprovider side key exchange context in the ctx parameter, and a pointer\nto a provider key object in the provkey parameter.  The params, if not\nNULL, should be set on the context in a manner similar to using\nOSSLFUNCkeyexchsetparams().  The key object should have been\npreviously generated, loaded or imported into the provider using the\nkey management (OSSLOPKEYMGMT) operation (see provider-keymgmt(7)>.\n\nOSSLFUNCkeyexchsetpeer() is called to supply the peer's public key\n(in the provkey parameter) to be used when deriving the shared secret.\nIt is also passed a previously initialised key exchange context in the\nctx parameter.  The key object should have been previously generated,\nloaded or imported into the provider using the key management\n(OSSLOPKEYMGMT) operation (see provider-keymgmt(7)>.\n\nOSSLFUNCkeyexchderive() performs the actual key exchange itself by\nderiving a shared secret.  A previously initialised key exchange\ncontext is passed in the ctx parameter.  The derived secret should be\nwritten to the location secret which should not exceed outlen bytes.\nThe length of the shared secret should be written to *secretlen.  If\nsecret is NULL then the maximum length of the shared secret should be\nwritten to *secretlen.\n\nKey Exchange Parameters Functions\nOSSLFUNCkeyexchsetctxparams() sets key exchange parameters\nassociated with the given provider side key exchange context ctx to\nparams, see \"Common Key Exchange parameters\".  Any parameter settings\nare additional to any that were previously set.  Passing NULL for\nparams should return true.\n\nOSSLFUNCkeyexchgetctxparams() gets key exchange parameters\nassociated with the given provider side key exchange context ctx into\nparams, see \"Common Key Exchange parameters\".  Passing NULL for params\nshould return true.\n\nOSSLFUNCkeyexchsettablectxparams() yields a constant OSSLPARAM\narray that describes the settable parameters, i.e. parameters that can\nbe used with OPsignaturesetctxparams().  If\nOSSLFUNCkeyexchsettablectxparams() is present,\nOSSLFUNCkeyexchsetctxparams() must also be present, and vice\nversa.  Similarly, OSSLFUNCkeyexchgettablectxparams() yields a\nconstant OSSLPARAM array that describes the gettable parameters, i.e.\nparameters that can be handled by OPsignaturegetctxparams().  If\nOSSLFUNCkeyexchgettablectxparams() is present,\nOSSLFUNCkeyexchgetctxparams() must also be present, and vice\nversa.  See OSSLPARAM(3) for the use of OSSLPARAM as parameter\ndescriptor.\n\nNotice that not all settable parameters are also gettable, and vice\nversa.\n\nCommon Key Exchange parameters\nSee OSSLPARAM(3) for further details on the parameters structure used\nby the OSSLFUNCkeyexchsetctxparams() and\nOSSLFUNCkeyexchgetctxparams() functions.\n\nCommon parameters currently recognised by built-in key exchange\nalgorithms are as follows.\n\n\"kdf-type\" (OSSLEXCHANGEPARAMKDFTYPE) <UTF8 string>\nSets or gets the Key Derivation Function type to apply within the\nassociated key exchange ctx.\n\n\"kdf-digest\" (OSSLEXCHANGEPARAMKDFDIGEST) <UTF8 string>\nSets or gets the Digest algorithm to be used as part of the Key\nDerivation Function associated with the given key exchange ctx.\n\n\"kdf-digest-props\" (OSSLEXCHANGEPARAMKDFDIGESTPROPS) <UTF8 string>\nSets properties to be used upon look up of the implementation for\nthe selected Digest algorithm for the Key Derivation Function\nassociated with the given key exchange ctx.\n\n\"kdf-outlen\" (OSSLEXCHANGEPARAMKDFOUTLEN) <unsigned integer>\nSets or gets the desired size for the output of the chosen Key\nDerivation Function associated with the given key exchange ctx.\nThe length of the \"kdf-outlen\" parameter should not exceed that of\na sizet.\n\n\"kdf-ukm\" (OSSLEXCHANGEPARAMKDFUKM) <octet string>\nSets the User Key Material to be used as part of the selected Key\nDerivation Function associated with the given key exchange ctx.\n\n\"kdf-ukm\" (OSSLEXCHANGEPARAMKDFUKM) <octet string ptr>\nGets a pointer to the User Key Material to be used as part of the\nselected Key Derivation Function associated with the given key\nexchange ctx. Providers usually do not need to support this\ngettable parameter as its sole purpose is to support functionality\nof the deprecated EVPPKEYCTXget0ecdhkdfukm() and\nEVPPKEYCTXget0dhkdfukm() functions.\n",
            "subsections": []
        },
        "RETURN VALUES": {
            "content": "OSSLFUNCkeyexchnewctx() and OSSLFUNCkeyexchdupctx() should return\nthe newly created provider side key exchange context, or NULL on\nfailure.\n\nOSSLFUNCkeyexchinit(), OSSLFUNCkeyexchsetpeer(),\nOSSLFUNCkeyexchderive(), OSSLFUNCkeyexchsetparams(), and\nOSSLFUNCkeyexchgetparams() should return 1 for success or 0 on\nerror.\n\nOSSLFUNCkeyexchsettablectxparams() and\nOSSLFUNCkeyexchgettablectxparams() should always return a constant\nOSSLPARAM array.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "provider(7)\n",
            "subsections": []
        },
        "HISTORY": {
            "content": "The provider KEYEXCH interface was introduced in OpenSSL 3.0.\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.\n\nLicensed under the Apache License 2.0 (the \"License\").  You may not use\nthis file except in compliance with the License.  You can obtain a copy\nin the file LICENSE in the source distribution or at\n<https://www.openssl.org/source/license.html>.\n\n3.0.2                             2026-06-02            PROVIDER-KEYEXCH(7SSL)",
            "subsections": []
        }
    },
    "summary": "provider-keyexch - The keyexch library <-> provider functions",
    "flags": [],
    "examples": [],
    "see_also": [
        {
            "name": "provider",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/provider/7/json"
        }
    ]
}