COMP_CTX_NEW(3ossl)
π COMP_CTX_NEW(3ossl) π
okay so bestie, welcome to the 3ossl manual page β OpenSSL's whole compression-support situation. this is the page that explains how OpenSSL squeezes bytes down and blows them back up again. it's giving "behind the scenes glue" and honestly? iconic. π«Ά
β¨ 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 π
like, that's the whole squad right there. compression support, periodt.
πΈ 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);
copy that header include exactly, bestie β openssl/comp.h, no cap. π
π¦ DESCRIPTION π¦
so these functions are literally the compression support system for OpenSSL. the library uses compression internally to support TLS record compression and certificate compression. main character energy for real. β¨
COMP_CTX_new()β makes you a brand newCOMP_CTXstructure, which is the thing you use to compress data. your compression purse, if you will. πCOMP_CTX_free()β frees theCOMP_CTXyou got back. and listen: if the argument isNULL, nothing is done. it just vibes. no crash, no drama.COMP_CTX_get_method()β hands you back theCOMP_METHODof the given ctx.COMP_CTX_get_type()andCOMP_get_type()β return theNIDfor theCOMP_CTXandCOMP_METHODrespectively. two functions, same energy.COMP_get_name()β returns the name of the algorithm of the givenCOMP_METHOD. name reveal! πCOMP_compress_block()β compressesilenbytes from the buffer in into the bufferoutof size olen, using the algorithm specified by ctx. squeeze squeeze. ποΈCOMP_expand_block()β expandsilenbytes from the buffer in into the bufferoutof size olen, using the algorithm specified by ctx. un-squeeze. π
π§ Methods (COMP_METHOD) π§
you can get a method from any one of these functions. and here's the lowkey important bit: these functions will be available even if their corresponding compression algorithm is not configured into the OpenSSL library. in that case, NULL gets returned. so like, the door's always there, but the room might be empty. π
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.
π The BIO ones π
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) to read and write compressed files or streams. so cute, so useful. π«Ά
β οΈ heads up bestie: these functions are only available if the corresponding algorithm is compiled into the OpenSSL library. NULL may be returned if the algorithm fails to load dynamically. no algorithm, no BIO. π
π NOTES π
okay, the fine print, and this part is important so like, pay attention:
π¨ while compressing non-compressible data, the output may be larger than the input. care should be taken to size output buffers appropriate for both compression and expansion. yes, your "compressed" file can be thicc-er. it's giving betrayal.
compression support and compression algorithms must be enabled and built into the library before use. refer to the INSTALL.md file 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>.
π the CRIME situation π
Compression of SSL/TLS records is not recommended, as 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 the SSL_OP_NO_COMPRESSION option and setting the security level as appropriate.
see the documentation for the SSL_CTX_set_options(3) and SSL_set_options(3) functions. like, if you turn this on, that's a choice, and the docs are telling you it's a bad one. π©
π certificate compression π
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. β¨
π₯ stream-based vs one-shot π₯
COMP_zlib(), COMP_brotli() and COMP_zstd() are stream-based compression methods. internal state (including the compression dictionary) is maintained between calls.
π¨ if an error is returned, the stream is corrupted, and should be closed. not "retry", not "ignore it" β closed. periodt. π
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. one-shot means one-shot, and honestly? fresh start energy. πΈ
π 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 aNIDvalue. on failure,NID_undefis returned.COMP_compress_block()andCOMP_expand_block()β return the number of bytes stored in the output bufferout. this may be 0. on failure,-1is returned.COMP_get_name()β returns aconst char *that must not be freed on success, orNULLon failure. do not free it. i'm serious. do not. π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)
go read those next, bestie, iykyk. π¦
π°οΈ HISTORY π°οΈ
Brotli and Zstandard functions were added in OpenSSL 3.2. newer additions, still slaying. β¨
π COPYRIGHT π
Copyright 2022-2024 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!! π this was version 3.5.0, dated 2026-09-25, from the COMP_CTX_NEW(3ossl) manual β and that's the cute little sign-off, mwah, go compress responsibly, no cap ππ
πΈ
π¦ 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