PROVIDER-ENCODER(7ossl)
πΈ NAME πΈ
okay so bestie, welcome to provider-encoder β that's the PROVIDER-ENCODER(7ossl) page in the OpenSSL manual, and it's literally about The OSSL_ENCODER library <-> provider functions. yes the <-> is doing a lot of work there, it's giving "these two things talk to each other" π
and that's the whole vibe of this page.
β¨ SYNOPSIS β¨
first things first, you gotta pull in the header, periodt:
#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.
*/
like the comment literally says β none of these are actual functions π they're just written out all pretty so you can see the function signatures for the function pointers that get handed over in OSSL_DISPATCH arrays. it's giving "menu, not the meal" fr fr.
π the encoder parameter accessor + descriptor
/* Encoder parameter accessor and descriptor */
const OSSL_PARAM *OSSL_FUNC_encoder_gettable_params(void *provctx);
int OSSL_FUNC_encoder_get_params(OSSL_PARAM params[]);
π¦ the construct / destruct / manipulate squad
/* Functions to construct / destruct / manipulate the encoder context */
void *OSSL_FUNC_encoder_newctx(void *provctx);
void OSSL_FUNC_encoder_freectx(void *ctx);
int OSSL_FUNC_encoder_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
const OSSL_PARAM *OSSL_FUNC_encoder_settable_ctx_params(void *provctx);
π§ selection support check
/* Functions to check selection support */
int OSSL_FUNC_encoder_does_selection(void *provctx, int selection);
π₯ actually encoding the object data
/* Functions to encode object data */
int OSSL_FUNC_encoder_encode(void *ctx, OSSL_CORE_BIO *out,
const void *obj_raw,
const OSSL_PARAM obj_abstract[],
int selection,
OSSL_PASSPHRASE_CALLBACK *cb,
void *cbarg);
π import + free a temporary object so it can be encoded
/* Functions to import and free a temporary object to be encoded */
void *OSSL_FUNC_encoder_import_object(void *ctx, int selection,
const OSSL_PARAM params[]);
void OSSL_FUNC_encoder_free_object(void *obj);
kk that's the whole synopsis, bestie β every single signature kept exactly where it belongs, no cap π and there's more coming, don't move π
β¨ DESCRIPTION β¨
Okay so first thing: we're using the word "encode" really widely in this manual, bestie. It covers serialization but it is not limited to serialization, iykyk. π
The ENCODER operation is the generic way to take a provider-native object (obj_raw) or an object abstraction (object_abstract, peep provider-object(7)) and turn it into an encoded form, then write the result to the given OSSL_CORE_BIO. And if the caller wants that encoded stream in memory instead? They just hand over a BIO_s_mem(3) BIO. Easy. π
The encoder genuinely doesn't need to know anything else about the OSSL_CORE_BIO pointer beyond being able to pass it to the appropriate BIO upcalls (see "Core functions" in provider-base(7)).
Here's the tea: an ENCODER implementation can be part of a chain, where data gets passed from one to the next. Like, there might be one implementation that encodes an object to DER (and that object is assumed to be provider-native, so it comes in via obj_raw), and then another one that encodes DER to PEM (and that one receives the DER encoding via obj_abstract). Chain goes brrr. π₯
Encoding via the OSSL_PARAM(3) array form is what lets an encoder be used on data that's been exported from another provider β which means those providers can exist independently of each other. Slay, independence.
Encoding via a provider side object, though? That can only be safely used with provider data coming from the same provider. Example: keys with the KEYMGMT provider. No crossover episodes there, sorry. π
Every "function" we mention here is passed as a function pointer between libcrypto and the provider in OSSL_DISPATCH(3) arrays, via OSSL_ALGORITHM(3) arrays that are returned by the provider's provider_query_operation() function (see "Provider Functions" in provider-base(7)).
And each of these "functions" has a matching function type definition named OSSL_FUNC_{name}_fn, plus a lil helper function that grabs the function pointer from an OSSL_DISPATCH(3) element, named OSSL_FUNC_{name}. For example, the "function" OSSL_FUNC_encoder_encode() has these:
typedef int
(OSSL_FUNC_encoder_encode_fn)(void *ctx, OSSL_CORE_BIO *out,
const void *obj_raw,
const OSSL_PARAM obj_abstract[],
int selection,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg);
static ossl_inline OSSL_FUNC_encoder_encode_fn
OSSL_FUNC_encoder_encode(const OSSL_DISPATCH *opf);
The OSSL_DISPATCH(3) arrays are indexed by numbers that are provided as macros in openssl-core_dispatch.h(7), like so:
OSSL_FUNC_encoder_get_params OSSL_FUNC_ENCODER_GET_PARAMS
OSSL_FUNC_encoder_gettable_params OSSL_FUNC_ENCODER_GETTABLE_PARAMS
OSSL_FUNC_encoder_newctx OSSL_FUNC_ENCODER_NEWCTX
OSSL_FUNC_encoder_freectx OSSL_FUNC_ENCODER_FREECTX
OSSL_FUNC_encoder_set_ctx_params OSSL_FUNC_ENCODER_SET_CTX_PARAMS
OSSL_FUNC_encoder_settable_ctx_params OSSL_FUNC_ENCODER_SETTABLE_CTX_PARAMS
OSSL_FUNC_encoder_does_selection OSSL_FUNC_ENCODER_DOES_SELECTION
OSSL_FUNC_encoder_encode OSSL_FUNC_ENCODER_ENCODE
OSSL_FUNC_encoder_import_object OSSL_FUNC_ENCODER_IMPORT_OBJECT
OSSL_FUNC_encoder_free_object OSSL_FUNC_ENCODER_FREE_OBJECT
π·οΈ Names and properties
The name of an implementation should match the type of object it handles. So an implementation that encodes an RSA key should be named "RSA". And an implementation that further encodes DER should be named "DER". Name it after the vibe, basically. β
Properties β as defined in the OSSL_ALGORITHM(3) array element of each decoder implementation β can be used to further specify details about an implementation:
outputβ this property says what type of output the implementation produces.
This property is mandatory. π¨
OpenSSL providers recognize the following output types:
textβ an implementation with that output type outputs human readable text, which makes it suitable for-textoutput in diverseopenssl(1)commands.pemβ an implementation with that output type outputs PEM formatted data.derβ an implementation with that output type outputs DER formatted data.msblobβ an implementation with that output type outputs MSBLOB formatted data.pvkβ an implementation with that output type outputs PVK formatted data.
structureβ this property says which structure is used for the encoded object. An example could be"pkcs8", to specify explicitly that an object (presumably an asymmetric key pair, in this case) will be wrapped in a PKCS#8 structure as part of the encoding.
This property is optional. π¦
The possible values of both these properties are open ended, fr fr β a provider may very well specify output types and structures that libcrypto doesn't know anything about. Main character provider energy. π
βοΈ Subset selections
Sometimes an object has more than one subset of data that's interesting to treat separately, or together. You can specify which subsets are to be encoded with a set of bits selection that are passed in an int.
This set of bits depends entirely on what kind of provider-side object is passed. For example, those bits are assumed to be the same as those used with provider-keymgmt(7) (see "Key Objects" in provider-keymgmt(7)) when the object is an asymmetric keypair.
ENCODER implementations are free to treat the selection as a set of hints, but they must do so with care. At the end of the day the output has to make sense, and if there's a corresponding decoder, the resulting decoded object must match the original object that was encoded. No cap. π§
OSSL_FUNC_encoder_does_selection() should tell you if a particular implementation supports any of the combinations given by selection.
π§ Context functions
OSSL_FUNC_encoder_newctx()returns a context to be used with the rest of the functions. π«ΆOSSL_FUNC_encoder_freectx()frees the givenctx, if it was created byOSSL_FUNC_encoder_newctx().OSSL_FUNC_encoder_set_ctx_params()sets context data according to parameters fromparamsthat it recognises. Unrecognised parameters should be ignored. And passingNULLforparamsshould return true.OSSL_FUNC_encoder_settable_ctx_params()returns a constantOSSL_PARAM(3)array describing the parameters thatOSSL_FUNC_encoder_set_ctx_params()can handle.
See OSSL_PARAM(3) for further details on the parameters structure used by OSSL_FUNC_encoder_set_ctx_params() and OSSL_FUNC_encoder_settable_ctx_params(). π
π₯ Import functions
So a provider-native object may be associated with a foreign provider, and may therefore be unsuitable for direct use with a given ENCODER implementation. But! Provided that the foreign provider's implementation for handling the object has a function to export that object in OSSL_PARAM(3) array form, the ENCODER implementation should be able to import that array and create a suitable object to be passed to OSSL_FUNC_encoder_encode()'s obj_raw. Glow-up arc. β¨
OSSL_FUNC_encoder_import_object()should import the subset ofparamsgiven withselectionto create a provider-native object that can be passed asobj_rawtoOSSL_FUNC_encoder_encode().OSSL_FUNC_encoder_free_object()should free the object that was created withOSSL_FUNC_encoder_import_object().
π¬ Encoding functions
OSSL_FUNC_encoder_encode() should take a provider-native object (in obj_raw) or an object abstraction (in obj_abstract), and should output the object in encoded form to the OSSL_CORE_BIO. The selection bits, if relevant, should determine in greater detail what will be output. The encoding functions also take an OSSL_PASSPHRASE_CALLBACK(3) function pointer along with a pointer to application data cbarg, which should be used when a pass phrase prompt is needed. π
βοΈ Encoder operation parameters
Operation parameters currently recognised by built-in encoders are as follows:
- "cipher" (
OSSL_ENCODER_PARAM_CIPHER) <UTF8 string> β the name of the encryption cipher to be used when generating encrypted encoding. This is used when encoding private keys, as well as other objects that need protection.
Okay so this one's important: if this name is invalid for the encoding implementation, the implementation should refuse to perform the encoding, i.e.OSSL_FUNC_encoder_encode_data()andOSSL_FUNC_encoder_encode_object()should return an error. π
- "properties" (
OSSL_ENCODER_PARAM_PROPERTIES) <UTF8 string> β the properties to be queried when trying to fetch the algorithm given with the"cipher"parameter. This must be given together with the"cipher"parameter to be considered valid.
The encoding implementation isn't obligated to use this value. However, it is recommended that implementations that do not handle property strings return an error on receiving this parameter unless its value is NULL or the empty string.
- "save-parameters" (
OSSL_ENCODER_PARAM_SAVE_PARAMETERS) <integer> β if set to0it disables saving of key domain parameters. Default is1. It currently has an effect only on DSA keys.
Parameters currently recognised by the built-in pass phrase callback:
- "info" (
OSSL_PASSPHRASE_PARAM_INFO) <UTF8 string> β a string of information that will become part of the pass phrase prompt. This could be used to give the user information on what kind of object it's being prompted for. πΈ
π«Ά RETURN VALUES π«Ά
OSSL_FUNC_encoder_newctx()returns a pointer to a context, orNULLon failure.OSSL_FUNC_encoder_set_ctx_params()returns1, unless a recognised parameter was invalid or caused an error, in which case0is returned.OSSL_FUNC_encoder_settable_ctx_params()returns a pointer to an array of constantOSSL_PARAM(3)elements.OSSL_FUNC_encoder_does_selection()returns1if the encoder implementation supports any of theselectionbits, otherwise0.OSSL_FUNC_encoder_encode()returns1on success, or0on failure.
π SEE ALSO π
π°οΈ HISTORY π°οΈ
The ENCODER interface was introduced in OpenSSL 3.0. Baby's a 3.x girlie. π
Β©οΈ COPYRIGHT Β©οΈ
Copyright 2019-2025 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>.
And that's the whole page, bestie β this one's 3.5.6, dated 2026-04-07, filed under PROVIDER-ENCODER(7ossl). Go encode something iconic. π¦ππ
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms