COMP_CTX_NEW(3SSL)
π COMP_CTX_NEW π
okay bestie, welcome to the 3SSL manual page for compression support in OpenSSL π this is where all the squeezing and unsqueezing lives. sit down, hydrate, let's go.
β¨ NAME β¨
COMP_CTX_new, COMP_CTX_get_method, COMP_CTX_get_type, COMP_get_type, COMP_get_name, COMP_CTX_free, COMP_compress_block, COMP_expand_block, COMP_zlib, COMP_zlib_oneshot, COMP_brotli, COMP_brotli_oneshot, COMP_zstd, COMP_zstd_oneshot, BIO_f_zlib, BIO_f_brotli, BIO_f_zstd β Compression support ποΈβ¨
π¦ SYNOPSIS π¦
#include <openssl/comp.h>
COMP_CTX *COMP_CTX_new(COMP_METHOD *meth);
void COMP_CTX_free(COMP_CTX *ctx);
const COMP_METHOD *COMP_CTX_get_method(const COMP_CTX *ctx);
int COMP_CTX_get_type(const COMP_CTX* comp);
int COMP_get_type(const COMP_METHOD *meth);
const char *COMP_get_name(const COMP_METHOD *meth);
int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
unsigned char *in, int ilen);
int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
unsigned char *in, int ilen);
COMP_METHOD *COMP_zlib(void);
COMP_METHOD *COMP_zlib_oneshot(void);
COMP_METHOD *COMP_brotli(void);
COMP_METHOD *COMP_brotli_oneshot(void);
COMP_METHOD *COMP_zstd(void);
COMP_METHOD *COMP_zstd_oneshot(void);
const BIO_METHOD *BIO_f_zlib(void);
const BIO_METHOD *BIO_f_brotli(void);
const BIO_METHOD *BIO_f_zstd(void);
πΈ DESCRIPTION πΈ
so basically these functions are the whole compression support situation for OpenSSL. compression gets used inside the OpenSSL library to support TLS record compression and certificate compression. that's the vibe π
COMP_CTX_new()β creates a brand newCOMP_CTXstructure, which is the thing you use to actually compress data. main character creation moment πCOMP_CTX_free()β frees theCOMP_CTXyou got back. and if the argument isNULL? nothing happens. no drama, we simply do nothing πCOMP_CTX_get_method()β hands you theCOMP_METHODof thectxyou gave it.COMP_CTX_get_type()andCOMP_get_type()β these give you the NID for theCOMP_CTXandCOMP_METHODrespectively. andCOMP_get_name()gives you the name of the algorithm of theCOMP_METHODyou passed in.COMP_compress_block()β compressesilenbytes from the bufferininto the bufferout, which is sizeolen, using the algorithm thatctxspecifies. squish ποΈCOMP_expand_block()β expandsilenbytes from the bufferininto the bufferout, which is sizeolen, using the algorithm thatctxspecifies. un-squish π«§
Methods (COMP_METHOD) can be specified by one of these functions. and here's the tea: these functions will be available even if their corresponding compression algorithm isn't configured into the OpenSSL library. in that case? NULL gets returned. periodt.
COMP_zlib()β returns aCOMP_METHODfor stream-based ZLIB compression.COMP_zlib_oneshot()β returns aCOMP_METHODfor one-shot ZLIB compression.COMP_brotli()β returns aCOMP_METHODfor stream-based Brotli compression.COMP_brotli_oneshot()β returns aCOMP_METHODfor one-shot Brotli compression.COMP_zstd()β returns aCOMP_METHODfor stream-based Zstandard compression.COMP_zstd_oneshot()β returns aCOMP_METHODfor one-shot Zstandard compression.
BIO_f_zlib(), BIO_f_brotli() and BIO_f_zstd() each return a BIO_METHOD that you can use to create a BIO via BIO_new(3) so you can read and write compressed files or streams. subtle but important: these functions are only available if the corresponding algorithm is compiled into the OpenSSL library. and NULL may be returned if the algorithm fails to load dynamically. π
π NOTES π
lowkey the most important bit, bestie, don't skip:
- while compressing non-compressible data, the output may be larger than the input. so size your output buffers appropriately β for both compression and expansion. please. for me. π«Ά
- compression support and compression algorithms must be enabled and built into the library before use. refer to the
INSTALL.mdfile when configuring OpenSSL. - ZLIB may be found at <https://zlib.net>
- Brotli may be found at <https://github.com/google/brotli>.
- Zstandard may be found at <https://github.com/facebook/zstd>.
π¨ Compression of SSL/TLS records is not recommended, because it has been shown to lead to the CRIME attack <https://en.wikipedia.org/wiki/CRIME>. It is disabled by default, and may be enabled by clearing theSSL_OP_NO_COMPRESSIONoption and setting the security level as appropriate. See the documentation for theSSL_CTX_set_options(3)andSSL_set_options(3)functions.
Compression is also used to support certificate compression as described in RFC8879 <https://datatracker.ietf.org/doc/html/rfc8879>. It may be disabled via the SSL_OP_NO_TX_CERTIFICATE_COMPRESSION and SSL_OP_NO_RX_CERTIFICATE_COMPRESSION options of the SSL_CTX_set_options(3) or SSL_set_options(3) functions.
COMP_zlib(), COMP_brotli() and COMP_zstd() are stream-based compression methods. internal state (including the compression dictionary) is maintained between calls. and if an error is returned? the stream is corrupted, and should be closed. like, genuinely close it, no cap. π
COMP_zlib_oneshot(), COMP_brotli_oneshot() and COMP_zstd_oneshot() are not stream-based. these methods do not maintain state between calls. an error in one call does not affect future calls. so chill, one bad call doesn't ruin the whole era β¨
π RETURN VALUES π
COMP_CTX_new()returns aCOMP_CTXon success, orNULLon failure.COMP_CTX_get_method(),COMP_zlib(),COMP_zlib_oneshot(),COMP_brotli(),COMP_brotli_oneshot(),COMP_zstd(), andCOMP_zstd_oneshot()return aCOMP_METHODon success, orNULLon failure.COMP_CTX_get_type()andCOMP_get_type()return a NID value. on failure,NID_undefis returned.COMP_compress_block()andCOMP_expand_block()return the number of bytes stored in the output bufferout. this may be0. on failure,-1is returned.COMP_get_name()returns aconst char *that must not be freed on success, orNULLon failure.BIO_f_zlib(),BIO_f_brotli()andBIO_f_zstd()returnNULLon error, and aBIO_METHODon success.
π SEE ALSO π
BIO_new(3), SSL_CTX_set_options(3), SSL_set_options(3)
π HISTORY π
Brotli and Zstandard functions were added in OpenSSL 3.2. ok history lesson over, you're so educated now π
β COPYRIGHT β
Copyright 2022-2025 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 version 4.0.3, dated 2026-09-29, brought to you by the COMP_CTX_NEW(3SSL) manual π go forth and compress responsibly, mwah πππ¦
π¦ 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