OSSL_PARAM_BLD(3ossl)

πŸ“¦ version 3.5.0, in opensuse-leap 16.0

πŸ’… OSSL_PARAM_BLD β€” like, the manual page, but make it make sense

okay so this is the OSSL_PARAM_BLD(3ossl) page from the OpenSSL fam ✨ it's all about the functions that help you build OSSL_PARAM arrays without losing your entire mind. bestie, it's giving "helper struct that does the boring parts for you" and honestly? we stan 🫢


🌸 NAME 🌸

OSSL_PARAM_BLD, OSSL_PARAM_BLD_new, OSSL_PARAM_BLD_to_param, OSSL_PARAM_BLD_free, OSSL_PARAM_BLD_push_int, OSSL_PARAM_BLD_push_uint, OSSL_PARAM_BLD_push_long, OSSL_PARAM_BLD_push_ulong, OSSL_PARAM_BLD_push_int32, OSSL_PARAM_BLD_push_uint32, OSSL_PARAM_BLD_push_int64, OSSL_PARAM_BLD_push_uint64, OSSL_PARAM_BLD_push_size_t, OSSL_PARAM_BLD_push_time_t, OSSL_PARAM_BLD_push_double, OSSL_PARAM_BLD_push_BN, OSSL_PARAM_BLD_push_BN_pad, OSSL_PARAM_BLD_push_utf8_string, OSSL_PARAM_BLD_push_utf8_ptr, OSSL_PARAM_BLD_push_octet_string, OSSL_PARAM_BLD_push_octet_ptr β€” literally all of these are the functions that assist in the creation of OSSL_PARAM arrays πŸ’–


✨ SYNOPSIS ✨

#include <openssl/param_build.h>

typedef struct OSSL_PARAM_BLD;

OSSL_PARAM_BLD *OSSL_PARAM_BLD_new(void);
OSSL_PARAM *OSSL_PARAM_BLD_to_param(OSSL_PARAM_BLD *bld);
void OSSL_PARAM_BLD_free(OSSL_PARAM_BLD *bld);

int OSSL_PARAM_BLD_push_TYPE(OSSL_PARAM_BLD *bld, const char *key, TYPE val);

int OSSL_PARAM_BLD_push_BN(OSSL_PARAM_BLD *bld, const char *key,
                           const BIGNUM *bn);
int OSSL_PARAM_BLD_push_BN_pad(OSSL_PARAM_BLD *bld, const char *key,
                               const BIGNUM *bn, size_t sz);

int OSSL_PARAM_BLD_push_utf8_string(OSSL_PARAM_BLD *bld, const char *key,
                                    const char *buf, size_t bsize);
int OSSL_PARAM_BLD_push_utf8_ptr(OSSL_PARAM_BLD *bld, const char *key,
                                 char *buf, size_t bsize);
int OSSL_PARAM_BLD_push_octet_string(OSSL_PARAM_BLD *bld, const char *key,
                                     const void *buf, size_t bsize);
int OSSL_PARAM_BLD_push_octet_ptr(OSSL_PARAM_BLD *bld, const char *key,
                                  void *buf, size_t bsize);

πŸ¦‹ DESCRIPTION πŸ¦‹

so basically this is a lil collection of utility functions that simplify the creation of OSSL_PARAM arrays 🌈 the TYPE names are as per OSSL_PARAM_int(3), iykyk.

  • OSSL_PARAM_BLD_new() β€” allocates and initialises a brand new OSSL_PARAM_BLD structure so you can start adding values. any existing values get cleared, fresh start energy πŸ’…
  • OSSL_PARAM_BLD_free() β€” deallocates the memory allocated by OSSL_PARAM_BLD_new(). if the argument is NULL, nothing happens. no drama, no crash, we love a graceful no-op πŸŽ€
  • OSSL_PARAM_BLD_to_param() β€” converts a built-up OSSL_PARAM_BLD structure bld into an allocated OSSL_PARAM array πŸ”₯ the OSSL_PARAM array and all associated storage must be freed by calling OSSL_PARAM_free() with the function's return value. and yes, OSSL_PARAM_BLD_free() can safely be called any time after this function is. main character cleanup routine ✨
  • OSSL_PARAM_BLD_push_TYPE() β€” a whole series of functions that create OSSL_PARAM objects of the specified size and correct type for the val argument πŸ’– val is stored by value, so an expression or auto variable can be used. convenient? obsessed.
when TYPE denotes an integer type, signed integer types will normally get the OSSL_PARAM type OSSL_PARAM_INTEGER params. when TYPE denotes an unsigned integer type, it'll get the OSSL_PARAM type OSSL_PARAM_UNSIGNED_INTEGER.
  • OSSL_PARAM_BLD_push_BN() β€” creates an OSSL_PARAM object that holds the specified BIGNUM bn 🌸 when bn is zero or positive, its OSSL_PARAM type becomes OSSL_PARAM_UNSIGNED_INTEGER. when bn is negative, its OSSL_PARAM type becomes OSSL_PARAM_INTEGER. if bn is marked as being securely allocated, its OSSL_PARAM representation will also be securely allocated πŸ” the bn argument is stored by reference and the underlying BIGNUM object must exist until after OSSL_PARAM_BLD_to_param() has been called β€” do not let it ghost you, bestie 😭
  • OSSL_PARAM_BLD_push_BN_pad() β€” same deal, creates an OSSL_PARAM object holding the specified BIGNUM bn, but the object will be padded to occupy exactly sz bytes πŸŽ€ if insufficient space is specified, an error results. when bn is zero or positive, its OSSL_PARAM type becomes OSSL_PARAM_UNSIGNED_INTEGER. when bn is negative, its OSSL_PARAM type becomes OSSL_PARAM_INTEGER. if bn is marked as being securely allocated, its OSSL_PARAM representation will also be securely allocated. the bn argument is stored by reference and the underlying BIGNUM object must exist until after OSSL_PARAM_BLD_to_param() has been called.
  • OSSL_PARAM_BLD_push_utf8_string() β€” creates an OSSL_PARAM object that references the UTF8 string specified by buf 🌟 the length of the string bsize should not include the terminating NUL byte. if it is zero then it will be calculated (the math is done for you, slay). the string that buf points to is stored by reference and must remain in scope until after OSSL_PARAM_BLD_to_param() has been called.
  • OSSL_PARAM_BLD_push_octet_string() β€” creates an OSSL_PARAM object that references the octet string specified by buf and <bsize> 🧚 the memory that buf points to is stored by reference and must remain in scope until after OSSL_PARAM_BLD_to_param() has been called.
  • OSSL_PARAM_BLD_push_utf8_ptr() β€” creates an OSSL_PARAM object that references the UTF8 string specified by buf. the length of the string bsize should not include the terminating NUL byte, and if it is zero then it will be calculated. the string buf points to is stored by reference and must remain in scope until the OSSL_PARAM array is freed πŸ‘‘ (yeah, the lifetime is longer than the string version β€” noted, fr fr)
  • OSSL_PARAM_BLD_push_octet_ptr() β€” creates an OSSL_PARAM object that references the octet string specified by buf. the memory buf points to is stored by reference and must remain in scope until the OSSL_PARAM array is freed 🫢

⭐ RETURN VALUES ⭐

  • OSSL_PARAM_BLD_new() returns the allocated OSSL_PARAM_BLD structure, or NULL on error πŸ’€
  • OSSL_PARAM_BLD_to_param() returns the allocated OSSL_PARAM array, or NULL on error.
  • all of the OSSL_PARAM_BLD_push_TYPE functions return 1 on success and 0 on error βœ…

πŸ“ NOTES πŸ“

okay important, this is the plot twist: OSSL_PARAM_BLD_push_BN() and OSSL_PARAM_BLD_push_BN_pad() only support nonnegative BIGNUMs. they return an error on negative BIGNUMs 🚨 so if you wanna pass signed BIGNUMs, use OSSL_PARAM_BLD_push_signed_BN() instead. periodt.


πŸ’œ EXAMPLES πŸ’œ

both examples create an OSSL_PARAM array that contains an RSA key πŸ”‘ for both, the predefined key variables are:

BIGNUM *n;           /* modulus */
unsigned int e;      /* public exponent */
BIGNUM *d;           /* private exponent */
BIGNUM *p, *q;       /* first two prime factors */
BIGNUM *dmp1, *dmq1; /* first two CRT exponents */
BIGNUM *iqmp;        /* first CRT coefficient */

πŸŽ€ Example 1

this example shows how to create an OSSL_PARAM array that contains an RSA private key 🌸 look at all those pushes, it's giving organized:

OSSL_PARAM_BLD *bld = OSSL_PARAM_BLD_new();
OSSL_PARAM *params = NULL;

if (bld == NULL
    || !OSSL_PARAM_BLD_push_BN(bld, "n", n)
    || !OSSL_PARAM_BLD_push_uint(bld, "e", e)
    || !OSSL_PARAM_BLD_push_BN(bld, "d", d)
    || !OSSL_PARAM_BLD_push_BN(bld, "rsa-factor1", p)
    || !OSSL_PARAM_BLD_push_BN(bld, "rsa-factor2", q)
    || !OSSL_PARAM_BLD_push_BN(bld, "rsa-exponent1", dmp1)
    || !OSSL_PARAM_BLD_push_BN(bld, "rsa-exponent2", dmq1)
    || !OSSL_PARAM_BLD_push_BN(bld, "rsa-coefficient1", iqmp)
    || (params = OSSL_PARAM_BLD_to_param(bld)) == NULL)
    goto err;
OSSL_PARAM_BLD_free(bld);
/* Use params */
...
OSSL_PARAM_free(params);

🌈 Example 2

and this one shows how to create an OSSL_PARAM array that contains an RSA public key ✨ shorter, cuter, still iconic:

OSSL_PARAM_BLD *bld = OSSL_PARAM_BLD_new();
OSSL_PARAM *params = NULL;

if (nld == NULL
    || !OSSL_PARAM_BLD_push_BN(bld, "n", n)
    || !OSSL_PARAM_BLD_push_uint(bld, "e", e)
    || (params = OSSL_PARAM_BLD_to_param(bld)) == NULL)
    goto err;
OSSL_PARAM_BLD_free(bld);
/* Use params */
...
OSSL_PARAM_free(params);
ngl the nld up there is literally what the manpage says β€” it's in the original, so it's in here too πŸ™ˆ not me changing the source text, i would never.

πŸ”₯ SEE ALSO πŸ”₯

OSSL_PARAM_int(3), OSSL_PARAM(3), OSSL_PARAM_free(3) β€” go read these next, bestie, they're the supporting cast πŸ‘‘


🌟 HISTORY 🌟

the functions described here were all added in OpenSSL 3.0 πŸŽ‰ so like, if you're on something ancient, that's a you problem πŸ’€


Copyright 2019-2024 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 was OpenSSL 3.5.0, dated 2026-09-25, filed under OSSL_PARAM_BLD(3ossl) β€” go build some param arrays, you're gonna ate πŸ’…βœ¨

πŸ“¦ where this page comes from