BF_ENCRYPT(3SSL)
π BF_ENCRYPT π (3SSL)
okay bestie, welcome to the BF_ENCRYPT(3SSL) page, aka the Blowfish manual, aka the OpenSSL cryptofiles. it's giving "grandma cipher but she still kinda ate" energy. let's get into it β¨
πΈ NAME πΈ
BF_set_key, BF_encrypt, BF_decrypt, BF_ecb_encrypt, BF_cbc_encrypt, BF_cfb64_encrypt, BF_ofb64_encrypt, BF_options β Blowfish encryption, babes. π
β¨ SYNOPSIS β¨
first things first, you gotta pull in the header:
#include <openssl/blowfish.h>
β οΈ heads up: the following functions have been deprecated since OpenSSL 3.0, and you can hide them entirely by defining OPENSSL_API_COMPAT with a suitable version value. see openssl_user_macros(7) for the deets.
void BF_set_key(BF_KEY *key, int len, const unsigned char *data);
void BF_ecb_encrypt(const unsigned char *in, unsigned char *out,
BF_KEY *key, int enc);
void BF_cbc_encrypt(const unsigned char *in, unsigned char *out,
long length, BF_KEY *schedule,
unsigned char *ivec, int enc);
void BF_cfb64_encrypt(const unsigned char *in, unsigned char *out,
long length, BF_KEY *schedule,
unsigned char *ivec, int *num, int enc);
void BF_ofb64_encrypt(const unsigned char *in, unsigned char *out,
long length, BF_KEY *schedule,
unsigned char *ivec, int *num);
const char *BF_options(void);
void BF_encrypt(BF_LONG *data, const BF_KEY *key);
void BF_decrypt(BF_LONG *data, const BF_KEY *key);
π¦ DESCRIPTION π¦
okay so ALL of the functions on this page are deprecated. no cap. if you're writing new code, you should be using EVP_EncryptInit_ex(3), EVP_EncryptUpdate(3) and EVP_EncryptFinal_ex(3) instead β or the equivalently named decrypt functions, obviously. the EVP era is the main character, these BF ones are the side characters who peaked in high school. π
so what even is this thing? this library implements the Blowfish cipher, which was invented and described by Counterpane β you can go look at it over at http://www.counterpane.com/blowfish.html if you're nosy like that π«Ά
Blowfish is a block cipher that operates on 64 bit (8 byte) blocks of data. it uses a variable size key, but typically 128 bit (16 byte) keys are considered good for strong encryption. and bestie, Blowfish can be used in the same modes as DES (peep des_modes(7) for that whole situation). lowkey Blowfish is currently one of the faster block ciphers β it's quite a bit faster than DES, and much faster than IDEA or RC2. ate. π
Blowfish consists of two phases, and the vibes are distinct:
- a key setup phase
- the actual encryption or decryption phase
let's break down who does what π
BF_set_key()β this one sets up theBF_KEYkey using thelenbytes long key atdata. that's the whole job. iconic.BF_ecb_encrypt()β the basic Blowfish encryption and decryption function. it encrypts or decrypts the first 64 bits ofinusing the keykey, and drops the result intoout.encdecides whether encryption (BF_ENCRYPT) or decryption (BF_DECRYPT) shall be performed. the vector pointed at byinandoutmust be 64 bits in length, no less. if they're larger than that? everything after the first 64 bits is ignored. so don't be extra, it won't reward you.- the mode functions β
BF_cbc_encrypt(),BF_cfb64_encrypt()andBF_ofb64_encrypt()all operate on variable length data. they all take an initialization vectorivecwhich needs to be passed along into the next call of the same function for the same message.ivecmay be initialized with anything, but the recipient needs to know what it was initialized with, or it won't be able to decrypt β yeah that's just how it is, communication is key bestie π some programs and protocols simplify this, like SSH, whereivecis simply initialized to zero.BF_cbc_encrypt()operates on data that is a multiple of 8 bytes long, whileBF_cfb64_encrypt()andBF_ofb64_encrypt()are used to encrypt a variable number of bytes (the amount does not have to be an exact multiple of 8). the purpose of the latter two is to simulate stream ciphers, and therefore they need the parameternum, which is a pointer to an integer where the current offset inivecis stored between calls. β οΈ this integer must be initialized to zero whenivecis initialized. zero it. do it. it's important fr fr. BF_cbc_encrypt()β the Cipher Block Chaining function for Blowfish. it encrypts or decrypts the 64 bits chunks ofinusing the keyschedule, putting the result inout.encdecides if encryption (BF_ENCRYPT) or decryption (BF_DECRYPT) shall be performed.ivecmust point at an 8 byte long initialization vector. eight bytes. not seven. not nine. eight. πΈBF_cfb64_encrypt()β the CFB mode for Blowfish with 64 bit feedback. it encrypts or decrypts the bytes ininusing the keyschedule, putting the result inout.encdecides if encryption (BF_ENCRYPT) or decryption (BF_DECRYPT) shall be performed.ivecmust point at an 8 byte long initialization vector.nummust point at an integer which must be initially zero. (say it with me: initially zero) β¨BF_ofb64_encrypt()β the OFB mode for Blowfish with 64 bit feedback. it uses the same parameters asBF_cfb64_encrypt(), which must be initialized the same way. same energy, different mode. π₯BF_encrypt()andBF_decrypt()β the lowest level functions for Blowfish encryption. they encrypt/decrypt the first 64 bits of the vector pointed bydata, using the keykey. these functions should not be used unless you implement 'modes' of Blowfish. the alternative is to useBF_ecb_encrypt(). if you still want to use these functions, you should be aware that they take each 32-bit chunk in host-byte order, which is little-endian on little-endian platforms and big-endian on big-endian ones. it's giving "your mileage may vary by architecture" and honestly that's a jump scare if you weren't expecting it π
β RETURN VALUES β
none of the functions presented here return any value. not one. zero. they are void, they are unbothered, they give nothing back and that's simply their brand. π
π«Ά NOTE π«Ά
applications should use the higher level functions EVP_EncryptInit(3) etc. instead of calling these functions directly. seriously bestie, the EVP girls are the ones winning here. β
π SEE ALSO π
π§ HISTORY π§
all of these functions were deprecated in OpenSSL 3.0. that's the whole history lesson. periodt. π
π 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. read the license, it's the law but like, in a cute way π
and that's a wrap on the Blowfish era, bestie. this whole page came to you courtesy of OpenSSL version 4.0.3, dated 2026-09-29. now go call EVP_EncryptInit_ex(3) instead, ily, bye π¦β¨π
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms