{
    "content": [
        {
            "type": "text",
            "text": "# provider-keyexch(7) (man)\n\n**Summary:** provider-keyexch - The keyexch library <-> provider functions\n\n**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);\n\n## See Also\n\n- provider(7)\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **SYNOPSIS** (29 lines)\n- **DESCRIPTION** (46 lines) — 4 subsections\n  - Context Management Functions (12 lines)\n  - Shared Secret Derivation Functions (19 lines)\n  - Key Exchange Parameters Functions (20 lines)\n  - Common Key Exchange parameters (32 lines)\n- **RETURN VALUES** (10 lines)\n- **SEE ALSO** (2 lines)\n- **HISTORY** (2 lines)\n- **COPYRIGHT** (9 lines)\n\n## Full Content\n\n### NAME\n\nprovider-keyexch - The keyexch library <-> provider functions\n\n### SYNOPSIS\n\n#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\n### DESCRIPTION\n\nThis documentation is primarily aimed at provider authors. See provider(7) for further\ninformation.\n\nThe key exchange (OSSLOPKEYEXCH) operation enables providers to implement key exchange\nalgorithms and make them available to applications via EVPPKEYderive(3) and other related\nfunctions).\n\nAll \"functions\" mentioned here are passed as function pointers between libcrypto and the\nprovider in OSSLDISPATCH arrays via OSSLALGORITHM arrays that are returned by the\nprovider's providerqueryoperation() function (see \"Provider Functions\" in\nprovider-base(7)).\n\nAll these \"functions\" have a corresponding function type definition named\nOSSLFUNC{name}fn, and a helper function to retrieve the function pointer from an\nOSSLDISPATCH element named OSSLFUNC{name}.  For example, the \"function\"\nOSSLFUNCkeyexchnewctx() 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 in\nopenssl-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 functions.  In order\nto be a consistent set of functions a provider must implement OSSLFUNCkeyexchnewctx,\nOSSLFUNCkeyexchfreectx, OSSLFUNCkeyexchinit and OSSLFUNCkeyexchderive.  All other\nfunctions are optional.\n\nA key exchange algorithm must also implement some mechanism for generating, loading or\nimporting keys via the key management (OSSLOPKEYMGMT) operation.  See provider-keymgmt(7)\nfor further details.\n\n#### Context Management Functions\n\nOSSLFUNCkeyexchnewctx() should create and return a pointer to a provider side structure\nfor holding context information during a key exchange operation.  A pointer to this context\nwill be passed back in a number of the other key exchange operation function calls.  The\nparameter provctx is the provider context generated during provider initialisation (see\nprovider(7)).\n\nOSSLFUNCkeyexchfreectx() is passed a pointer to the provider side key exchange context in\nthe ctx parameter.  This function should free any resources associated with that context.\n\nOSSLFUNCkeyexchdupctx() should duplicate the provider side key exchange context in the ctx\nparameter and return the duplicate copy.\n\n#### Shared Secret Derivation Functions\n\nOSSLFUNCkeyexchinit() initialises a key exchange operation given a provider side key\nexchange context in the ctx parameter, and a pointer to a provider key object in the provkey\nparameter.  The params, if not NULL, should be set on the context in a manner similar to\nusing OSSLFUNCkeyexchsetparams().  The key object should have been previously generated,\nloaded or imported into the provider using the key management (OSSLOPKEYMGMT) operation\n(see provider-keymgmt(7)>.\n\nOSSLFUNCkeyexchsetpeer() is called to supply the peer's public key (in the provkey\nparameter) to be used when deriving the shared secret.  It is also passed a previously\ninitialised key exchange context in the ctx parameter.  The key object should have been\npreviously generated, loaded 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 deriving a shared\nsecret.  A previously initialised key exchange context is passed in the ctx parameter.  The\nderived secret should be written to the location secret which should not exceed outlen bytes.\nThe length of the shared secret should be written to *secretlen.  If secret is NULL then the\nmaximum length of the shared secret should be written to *secretlen.\n\n#### Key Exchange Parameters Functions\n\nOSSLFUNCkeyexchsetctxparams() sets key exchange parameters associated with the given\nprovider side key exchange context ctx to params, see \"Common Key Exchange parameters\".  Any\nparameter settings are additional to any that were previously set.  Passing NULL for params\nshould return true.\n\nOSSLFUNCkeyexchgetctxparams() gets key exchange parameters associated with the given\nprovider side key exchange context ctx into params, see \"Common Key Exchange parameters\".\nPassing NULL for params should return true.\n\nOSSLFUNCkeyexchsettablectxparams() yields a constant OSSLPARAM array that describes the\nsettable parameters, i.e. parameters that can be used with OPsignaturesetctxparams().  If\nOSSLFUNCkeyexchsettablectxparams() is present, OSSLFUNCkeyexchsetctxparams() must\nalso be present, and vice versa.  Similarly, OSSLFUNCkeyexchgettablectxparams() yields a\nconstant OSSLPARAM array that describes the gettable parameters, i.e. parameters that can be\nhandled by OPsignaturegetctxparams().  If OSSLFUNCkeyexchgettablectxparams() is\npresent, OSSLFUNCkeyexchgetctxparams() must also be present, and vice versa.  See\nOSSLPARAM(3) for the use of OSSLPARAM as parameter descriptor.\n\nNotice that not all settable parameters are also gettable, and vice versa.\n\n#### Common Key Exchange parameters\n\nSee OSSLPARAM(3) for further details on the parameters structure used by the\nOSSLFUNCkeyexchsetctxparams() and OSSLFUNCkeyexchgetctxparams() functions.\n\nCommon parameters currently recognised by built-in key exchange algorithms are as follows.\n\n\"kdf-type\" (OSSLEXCHANGEPARAMKDFTYPE) <UTF8 string>\nSets or gets the Key Derivation Function type to apply within the associated key exchange\nctx.\n\n\"kdf-digest\" (OSSLEXCHANGEPARAMKDFDIGEST) <UTF8 string>\nSets or gets the Digest algorithm to be used as part of the Key Derivation Function\nassociated 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 the selected Digest\nalgorithm for the Key Derivation Function associated 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 Derivation Function\nassociated with the given key exchange ctx.  The length of the \"kdf-outlen\" parameter\nshould not exceed that of a sizet.\n\n\"kdf-ukm\" (OSSLEXCHANGEPARAMKDFUKM) <octet string>\nSets the User Key Material to be used as part of the selected Key Derivation Function\nassociated 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 selected Key Derivation\nFunction associated with the given key exchange ctx. Providers usually do not need to\nsupport this gettable parameter as its sole purpose is to support functionality of the\ndeprecated EVPPKEYCTXget0ecdhkdfukm() and EVPPKEYCTXget0dhkdfukm() functions.\n\n### RETURN VALUES\n\nOSSLFUNCkeyexchnewctx() and OSSLFUNCkeyexchdupctx() should return the newly created\nprovider side key exchange context, or NULL on failure.\n\nOSSLFUNCkeyexchinit(), OSSLFUNCkeyexchsetpeer(), OSSLFUNCkeyexchderive(),\nOSSLFUNCkeyexchsetparams(), and OSSLFUNCkeyexchgetparams() should return 1 for\nsuccess or 0 on error.\n\nOSSLFUNCkeyexchsettablectxparams() and OSSLFUNCkeyexchgettablectxparams() should\nalways return a constant OSSLPARAM array.\n\n### SEE ALSO\n\nprovider(7)\n\n### HISTORY\n\nThe provider KEYEXCH interface was introduced in OpenSSL 3.0.\n\n### COPYRIGHT\n\nCopyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.\n\nLicensed under the Apache License 2.0 (the \"License\").  You may not use this file except in\ncompliance with the License.  You can obtain a copy in the file LICENSE in the source\ndistribution or at <https://www.openssl.org/source/license.html>.\n\n\n\n3.0.2                                        2026-04-07                       PROVIDER-KEYEXCH(7SSL)\n\n"
        }
    ],
    "structuredContent": {
        "command": "provider-keyexch",
        "section": "7",
        "mode": "man",
        "summary": "provider-keyexch - The keyexch library <-> provider functions",
        "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);",
        "flags": [],
        "examples": [],
        "see_also": [
            {
                "name": "provider",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/provider/7/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 29,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 46,
                "subsections": [
                    {
                        "name": "Context Management Functions",
                        "lines": 12
                    },
                    {
                        "name": "Shared Secret Derivation Functions",
                        "lines": 19
                    },
                    {
                        "name": "Key Exchange Parameters Functions",
                        "lines": 20
                    },
                    {
                        "name": "Common Key Exchange parameters",
                        "lines": 32
                    }
                ]
            },
            {
                "name": "RETURN VALUES",
                "lines": 10,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "HISTORY",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "COPYRIGHT",
                "lines": 9,
                "subsections": []
            }
        ]
    }
}