BIO_F_CIPHER(3ossl)
π BIO_F_CIPHER β the cipher BIO filter, explained by your favorite Unix bestie
okay so this is the <pink>BIO_f_cipher(3ossl)</pink> page, from the OpenSSL manual, and bestie we are about to get so cozy with cipher filters. it's giving "crypto but make it a stream" energy. let's go β¨
πΈ NAME πΈ
BIO_f_cipher, BIO_set_cipher, BIO_get_cipher_status, BIO_get_cipher_ctx β the whole cipher BIO filter squad. literally all four of them, no cap π
π¦ SYNOPSIS π¦
#include <openssl/bio.h>
#include <openssl/evp.h>
const BIO_METHOD *BIO_f_cipher(void);
int BIO_set_cipher(BIO *b, const EVP_CIPHER *cipher,
const unsigned char *key, const unsigned char *iv, int enc);
int BIO_get_cipher_status(BIO *b);
int BIO_get_cipher_ctx(BIO *b, EVP_CIPHER_CTX **pctx);
π DESCRIPTION π
so here's the tea π:
BIO_f_cipher()β returns the cipher BIO method. it's a filter BIO, which means it encrypts every single thing you write through it, and decrypts every single thing you read from it. it's basically a little BIO wrapper around the cipher routinesEVP_CipherInit(),EVP_CipherUpdate()andEVP_CipherFinal(). iconic behavior honestly.- π¨ cipher BIOs do not support
BIO_gets()orBIO_puts(). not today, not ever. (okay, see NOTES below, there's a workaround, breathe.) BIO_flush()on an encryption BIO that you're writing through is how you signal "okay bestie, no more data to encrypt." that's the call that flushes and possibly pads the final block through the BIO. do not skip it, i'm serious πBIO_set_cipher()β sets the cipher of BIObtocipher, using keykeyand IViv. andenc? set it to1for encryption, and zero for decryption. yes,1and0, that's the whole vibe.- when you're reading from an encryption BIO, the final block gets automatically decrypted and checked when EOF is detected. and
BIO_get_cipher_status()is aBIO_ctrl()macro you can call to find out whether the decryption actually succeeded. main character status check fr fr π₯ BIO_get_cipher_ctx()β also aBIO_ctrl()macro, and it retrieves the internal BIO cipher context. the retrieved context can be used alongside the standard cipher routines to set it up yourself. super useful whenBIO_set_cipher()just isn't flexible enough for what your application needs β like when you need β¨moreβ¨.
π NOTES π (the important warnings section, pay attention)
when encrypting, BIO_flush() must be called to flush the final block through the BIO. if it isn't, then the final block will fail a subsequent decrypt. that's it, that's the whole disaster. π
when decrypting, an error on the final block is signaled by a zero return value from the read operation. but plot twist: a successful decrypt followed by EOF will also return zero for that final read. so you can't tell them apart by the return value alone π β call BIO_get_cipher_status() to figure out if the decrypt was actually successful.
and as always, if you truly need BIO_gets() or BIO_puts() support, you can get it by preceding the cipher BIO with a buffering BIO. problem solved, slay π
β RETURN VALUES β
BIO_f_cipher()β returns the cipher BIO method.BIO_set_cipher()β returns1for success and0for failure.BIO_get_cipher_status()β returns1for a successful decrypt and<=0for failure.BIO_get_cipher_ctx()β returns1for success and<=0for failure.
π COPYRIGHT π
Copyright 2000-2020 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>.
okay that's the whole page, you ate that π«Ά mwah! this was OpenSSL 3.5.0, dated 2026-09-25, and yes the manual is literally called BIO_F_CIPHER(3ossl) β go encrypt something, bestie ππ
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3-doc 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms