BIO_F_CIPHER(3ossl)
π BIO_F_CIPHER(3ossl) β the cipher BIO filter, explained π
okay so bestie, this is the 3ossl manual page for BIO_f_cipher, BIO_set_cipher, BIO_get_cipher_status and BIO_get_cipher_ctx, and honestly? it's giving "small API, big responsibilities." let's get into it π
β¨ NAME β¨
BIO_f_cipher, BIO_set_cipher, BIO_get_cipher_status, BIO_get_cipher_ctx β literally the cipher BIO filter, the whole icon, the main character π«Ά
πΈ 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 BIO_f_cipher() hands you back the cipher BIO method. it's a filter BIO β meaning it encrypts literally any data you write through it, and decrypts any data you read from it. no cap, it's just a cute little BIO wrapper for the cipher routines EVP_CipherInit(), EVP_CipherUpdate() and EVP_CipherFinal(). π
cipher BIOs do not support BIO_gets() or BIO_puts(). periodt, that's just not their thing.
BIO_flush() on an encryption BIO that you're writing through? that's your "okay I'm done, no more data to encrypt" signal β β it's how you flush and possibly pad that final block through the BIO.
BIO_set_cipher() sets the cipher of BIO b to cipher, using key key and IV iv. set enc to 1 for encryption and zero for decryption. simple as that.
when you're reading from an encryption BIO, the final block gets automatically decrypted and checked the moment EOF is detected π. BIO_get_cipher_status() is a BIO_ctrl() macro you can call to find out whether that decryption actually slayed or flopped.
BIO_get_cipher_ctx() is also a BIO_ctrl() macro, and it retrieves the internal BIO cipher context. the retrieved context can be used together with the standard cipher routines to set it up yourself β which is super useful when BIO_set_cipher() just isn't flexible enough for what your app needs. iykyk π
π§ NOTES π§
- when encrypting, you must call
BIO_flush()to flush the final block through the BIO. if you don't? that final block will fail a subsequent decrypt. π not a vibe. - when decrypting, an error on the final block is signaled by a zero return value from the read operation. a successful decrypt followed by EOF will also return zero for the final read β so fr fr, call
BIO_get_cipher_status()to know which one you actually got. - as always, if you need
BIO_gets()orBIO_puts()support, you can achieve it by preceding the cipher BIO with a buffering BIO. π
bestie warning: that "zero means error AND zero means success" situation is exactly why the status check exists. don't skip it, i'm begging π
π₯ RETURN VALUES π₯
BIO_f_cipher()β returns the cipher BIO method. iconic behavior.BIO_set_cipher()β returns1for success,0for 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>.
and that's the whole page, bestie π β this one's from OpenSSL 3.5.6, dated 2026-04-07, and it's the BIO_F_CIPHER(3ossl) manual. go encrypt something, and don't forget the flush ππ
β¨
π¦ 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