OSSL_PARAM(3ossl)
β¨ NAME β¨
OSSL_PARAM β a structure to pass or request object parameters. This is the OSSL_PARAM(3ossl) manual page, part 1, bestie π
π SYNOPSIS π
#include <openssl/core.h>
typedef struct ossl_param_st OSSL_PARAM;
struct ossl_param_st {
const char *key; /* the name of the parameter */
unsigned int data_type; /* declare what kind of content is in data */
void *data; /* value being passed in or out */
size_t data_size; /* data size */
size_t return_size; /* returned size */
};
π¦ DESCRIPTION π¦
OSSL_PARAM is a type that lets you pass arbitrary data for some object between two parties that have no or very little shared knowledge about their respective internal structures for that object. Itβs giving βwe donβt need to know each otherβs whole lore, we just need to swap this one thingβ β¨
A typical usage example could be an application that wants to set some parameters for an object, or wants to find out some parameters of an object.
Arrays of this type can be used for the following purposes:
- Setting parameters for some object The caller sets up the
OSSL_PARAMarray and calls some function (the setter) that has intimate knowledge about the object. That setter can take the data from theOSSL_PARAMarray and assign it in a suitable form for the internal structure of the object. - Request parameters of some object The caller (the requester) sets up the
OSSL_PARAMarray and calls some function (the responder) that has intimate knowledge about the object. The responder can take the internal data of the object and copy it (possibly converting it) to the memory prepared by the requester and pointed at with theOSSL_PARAMdata. - Request parameter descriptors The caller gets an array of constant
OSSL_PARAM, which describe available parameters and some of their properties: name, data type and expected data size. For a detailed description of each field for this use, see the field descriptions below. The caller may then use the information from this descriptor array to build up its ownOSSL_PARAMarray to pass down to a setter or responder.
Normally, the order of an OSSL_PARAM array is not relevant. However, if the responder can handle multiple elements with the same key, those elements must be handled in the order they are in.
An OSSL_PARAM array must have a terminating element, where key is NULL. The usual full terminating template is:
{ NULL, 0, NULL, 0, 0 }
This can also be specified using OSSL_PARAM_END(3).
π οΈ Functional support π οΈ
Libcrypto offers a limited set of helper functions to handle OSSL_PARAM items and arrays, please see OSSL_PARAM_get_int(3). Developers are free to extend or replace those as they see fit.
π OSSL_PARAM fields π
keyβ the identity of the parameter in the form of a string. In anOSSL_PARAMarray, an item with this field set toNULLis considered a terminating item.data_typeβ thedata_typeis a value that describes the type and organization of the data. See βSupported typesβ below for a description of the types.data,data_sizeβdatais a pointer to the memory where the parameter data is (when setting parameters) or shall (when requesting parameters) be stored, anddata_sizeis its size in bytes. The organization of the data depends on the parameter type and flag. Thedata_sizeneeds special attention with the parameter typeOSSL_PARAM_UTF8_STRINGin relation to C strings. When setting parameters, the size should be set to the length of the string, not counting the terminatingNULbyte. When requesting parameters, the size should be set to the size of the buffer to be populated, which should accommodate enough space for a terminatingNULbyte. When requesting parameters, itβs acceptable fordatato beNULL. This can be used by the requester to figure out dynamically exactly how much buffer space is needed to store the parameter data. In this case,data_sizeis ignored. When theOSSL_PARAMis used as a parameter descriptor,datashould be ignored. Ifdata_sizeis zero, it means that an arbitrary data size is accepted, otherwise it specifies the maximum size allowed.return_sizeβ when an array ofOSSL_PARAMis used to request data, the responder must set this field to indicate size of the parameter data, including padding as the case may be. In case thedata_sizeis an unsuitable size for the data, the responder must still set this field to indicate the minimum data size required. (further notes on this in βNOTESβ below). When theOSSL_PARAMis used as a parameter descriptor,return_sizeshould be ignored.
NOTE: The key names and associated types are defined by the entity that offers these parameters, i.e. names for parameters provided by the OpenSSL libraries are defined by the libraries, and names for parameters provided by providers are defined by those providers, except for the pointer form of strings (see data type descriptions below). Entities that want to set or request parameters need to know what those keys are and of what type, any functionality between those two entities should remain oblivious and just pass the OSSL_PARAM array along.
π Supported types π
The data_type field can be one of the following types:
OSSL_PARAM_INTEGER,OSSL_PARAM_UNSIGNED_INTEGERβ the parameter data is an integer (signed or unsigned) of arbitrary length, organized in native form, i.e. most significant byte first on Big-Endian systems, and least significant byte first on Little-Endian systems.OSSL_PARAM_REALβ the parameter data is a floating point value in native form.OSSL_PARAM_UTF8_STRINGβ the parameter data is a printable string.OSSL_PARAM_OCTET_STRINGβ the parameter data is an arbitrary string of bytes.OSSL_PARAM_UTF8_PTRβ the parameter data is a pointer to a printable string. The difference between this andOSSL_PARAM_UTF8_STRINGis thatdatadoesnβt point directly at the data, but to a pointer that points to the data. If there is any uncertainty about which to use,OSSL_PARAM_UTF8_STRINGis almost certainly the correct choice. This is used to indicate that constant data is or will be passed, and there is therefore no need to copy the data that is passed, just the pointer to it.data_sizemust be set to the size of the data, not the size of the pointer to the data. If this is used in a parameter request,data_sizeis not relevant. However, the responder will setreturn_sizeto the size of the data. Note that the use of this type is fragile and can only be safely used for data that remains constant and in a constant location for a long enough duration (such as the life-time of the entity that offers these parameters).OSSL_PARAM_OCTET_PTRβ the parameter data is a pointer to an arbitrary string of bytes. The difference between this andOSSL_PARAM_OCTET_STRINGis thatdatadoesnβt point directly at the data, but to a pointer that points to the data. If there is any uncertainty about which to use,OSSL_PARAM_OCTET_STRINGis almost certainly the correct choice. This is used to indicate that constant data is or will be passed, and there is therefore no need to copy the data that is passed, just the pointer to it.data_sizemust be set to the size of the data, not the size of the pointer to the data. If this is used in a parameter request,data_sizeis not relevant. However, the responder will setreturn_sizeto the size of the data. Note that the use of this type is fragile and can only be safely used for data that remains constant and in a constant location for a long enough duration (such as the life-time of the entity that offers these parameters).
π NOTES π
Both when setting and requesting parameters, the functions that are called will have to decide what is and what is not an error. The recommended behaviour is:
- Keys that a setter or responder doesnβt recognise should simply be ignored. That in itself isnβt an error.
- If the keys that a called setter recognises form a consistent enough set of data, that call should succeed.
- Apart from the
return_size, a responder must never change the fields of anOSSL_PARAM. To return a value, it should change the contents of the memory thatdatapoints at. - If the data type for a key that itβs associated with is incorrect, the called function may return an error. The called function may also try to convert the data to a suitable form (for example, itβs plausible to pass a large number as an octet string, so even though a given key is defined as an
OSSL_PARAM_UNSIGNED_INTEGER, it is plausible to pass the value as anOSSL_PARAM_OCTET_STRING), but this is in no way mandatory. - If
datafor aOSSL_PARAM_OCTET_STRINGor aOSSL_PARAM_UTF8_STRINGisNULL, the responder should setreturn_sizeto the size of the item to be returned and return success. Later the responder will be called again withdatapointing at the place for the value to be put. - If a responder finds that some data sizes are too small for the requested data, it must set
return_sizefor each suchOSSL_PARAMitem to the minimum required size, and eventually return an error. - For the integer type parameters (
OSSL_PARAM_UNSIGNED_INTEGERandOSSL_PARAM_INTEGER), a responder may choose to return an error if thedata_sizeisnβt a suitable size (even ifdata_sizeis bigger than needed). If the responder finds the size suitable, it must fill alldata_sizebytes and ensure correct padding for the native endianness, and setreturn_sizeto the same value asdata_size.
πΈ EXAMPLES πΈ
Okay bestie, here's where it gets real β a couple of examples that just show how OSSL_PARAM arrays could be set up. No biggie, just your fave little arrays living their best life. π
β¨ Example 1 β¨
This one is for setting parameters on some object:
#include <openssl/core.h>
const char *foo = "some string";
size_t foo_l = strlen(foo);
const char bar[] = "some other string";
OSSL_PARAM set[] = {
{ "foo", OSSL_PARAM_UTF8_PTR, &foo, foo_l, 0 },
{ "bar", OSSL_PARAM_UTF8_STRING, (void *)&bar, sizeof(bar) - 1, 0 },
{ NULL, 0, NULL, 0, 0 }
};
See that last line? { NULL, 0, NULL, 0, 0 } β that's the terminator, the little "we're done here" that closes out the array. Don't forget it, babes. π
β¨ Example 2 β¨
And this one is for requesting parameters on some object:
const char *foo = NULL;
size_t foo_l;
char bar[1024];
size_t bar_l;
OSSL_PARAM request[] = {
{ "foo", OSSL_PARAM_UTF8_PTR, &foo, 0 /*irrelevant*/, 0 },
{ "bar", OSSL_PARAM_UTF8_STRING, &bar, sizeof(bar), 0 },
{ NULL, 0, NULL, 0, 0 }
};
Notice the 0 /*irrelevant*/ on the foo entry? Yeah β for a request, that size field is just not the moment. π
So a responder that receives this array (as params in this example) could fill in the parameters like this:
/* OSSL_PARAM *params */
int i;
for (i = 0; params[i].key != NULL; i++) {
if (strcmp(params[i].key, "foo") == 0) {
*(char **)params[i].data = "foo value";
params[i].return_size = 9; /* length of "foo value" string */
} else if (strcmp(params[i].key, "bar") == 0) {
memcpy(params[i].data, "bar value", 10);
params[i].return_size = 9; /* length of "bar value" string */
}
/* Ignore stuff we don't know */
}
Notice how the loop runs until it hits a key of NULL β that's your terminator doing its job, icon behavior honestly. And that /* Ignore stuff we don't know */? Very "not my business, moving on" of it. π¦
π SEE ALSO π
Go read these next, bestie, they're literally the whole friend group:
π HISTORY π
OSSL_PARAM was added in OpenSSL 3.0. Periodt. It's giving "newer than your fave's debut album." β
π 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>.
Fr fr, read the license before you go wild with it β "not in compliance" is not the vibe you want. π
Okay that's the whole page, bestie β you ate that. π
β¨ This was OpenSSL 3.5.6, dated 2026-04-07, and it's the OSSL_PARAM(3ossl) manual page, signing off. Mwah! π«Άπ
π¦ 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