BIO_S_CORE(3ossl)

πŸ“¦
version 15.1 Β· 3 versions
, in freebsd 15.1

πŸ’… BIO_S_CORE β€” the OpenSSL 3ossl girlie's guide

okay so real talk, this one's for the provider authors out there β€” the 3ossl girlies building the actual crypto machinery. It's BIO_s_core and BIO_new_from_core_bio, aka the OSSL_CORE_BIO functions. Come sit with me, I gotchu. 🫢


✨ SYNOPSIS ✨

like, the whole vibe in two lines:

#include <openssl/bio.h>

const BIO_METHOD *BIO_s_core(void);

BIO *BIO_new_from_core_bio(OSSL_LIB_CTX *libctx, OSSL_CORE_BIO *corebio);

🌸 DESCRIPTION 🌸

So BIO_s_core() hands you the core BIO method function. That's it. That's the whole job. ✨

A core BIO is lowkey a source/sink BIO that talks to some external BIO. It's giving middleman, but in a useful way. This is primarily useful to provider authors β€” iykyk. Because here's the tea: a bunch of calls coming from libcrypto into a provider hand you an OSSL_CORE_BIO parameter. That thing represents a BIO inside libcrypto, and you literally cannot use it directly from a provider. Rude, I know. Instead you have to wrap it using a BIO_s_core(). πŸŽ€

Once you've constructed a BIO based on BIO_s_core(), you set the associated OSSL_CORE_BIO object on it with BIO_set_data(3). But bestie, listen β€” the BIO will only operate correctly if it's associated with a library context constructed using OSSL_LIB_CTX_new_from_dispatch(3). That's not optional, that's the vibe check. To associate the BIO with a library context, construct it using BIO_new_ex(3).

Then there's BIO_new_from_core_bio() β€” the convenience function, the main character, the one who does it all for you. 🌈 It constructs a new BIO based on BIO_s_core(), associates it with the library context you gave it, and also sets the OSSL_CORE_BIO object on the BIO using BIO_set_data(3). Two steps, one function, no notes. πŸ’…


πŸ¦‹ RETURN VALUES πŸ¦‹

  • BIO_s_core() returns a core BIO BIO_METHOD structure. Slay.
  • BIO_new_from_core_bio() returns a BIO structure on success, or NULL on failure. And what's the most common reason for failure? Bestie. It's because the library context wasn't constructed using OSSL_LIB_CTX_new_from_dispatch(3). That's it, that's the gotcha. 😭

⭐ HISTORY ⭐

BIO_s_core() and BIO_new_from_core_bio() were added in OpenSSL 3.0. Icons only. πŸ‘‘


πŸ”₯ EXAMPLES πŸ”₯

Create a core BIO and write some data to it β€” watch me:

 int some_function(OSSL_LIB_CTX *libctx, OSSL_CORE_BIO *corebio) {
     BIO *cbio = BIO_new_from_core_bio(libctx, corebio);

     if (cbio == NULL)
         return 0;

     BIO_puts(cbio, "Hello World\n");

     BIO_free(cbio);
     return 1;
 }

Hello World\n β€” the original flex. Never gets old. πŸ’–


Copyright 2021-2022 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>.


k bye bestie!! 🧚 This has been BIO_S_CORE(3ossl) from the OpenSSL fam β€” version 3.5.6, dated 2026-04-07. Go wrap those core BIOs, you got this, mwah πŸ’œπŸ“

πŸ“¦ where this page comes from