1 | =pod
|
---|
2 |
|
---|
3 | =head1 NAME
|
---|
4 |
|
---|
5 | COMP_CTX_new,
|
---|
6 | COMP_CTX_get_method,
|
---|
7 | COMP_CTX_get_type,
|
---|
8 | COMP_get_type,
|
---|
9 | COMP_get_name,
|
---|
10 | COMP_CTX_free,
|
---|
11 | COMP_compress_block,
|
---|
12 | COMP_expand_block,
|
---|
13 | COMP_zlib,
|
---|
14 | COMP_zlib_oneshot,
|
---|
15 | COMP_brotli,
|
---|
16 | COMP_brotli_oneshot,
|
---|
17 | COMP_zstd,
|
---|
18 | COMP_zstd_oneshot,
|
---|
19 | BIO_f_zlib,
|
---|
20 | BIO_f_brotli,
|
---|
21 | BIO_f_zstd
|
---|
22 | - Compression support
|
---|
23 |
|
---|
24 | =head1 SYNOPSIS
|
---|
25 |
|
---|
26 | #include <openssl/comp.h>
|
---|
27 |
|
---|
28 | COMP_CTX *COMP_CTX_new(COMP_METHOD *meth);
|
---|
29 | void COMP_CTX_free(COMP_CTX *ctx);
|
---|
30 | const COMP_METHOD *COMP_CTX_get_method(const COMP_CTX *ctx);
|
---|
31 | int COMP_CTX_get_type(const COMP_CTX* comp);
|
---|
32 | int COMP_get_type(const COMP_METHOD *meth);
|
---|
33 | const char *COMP_get_name(const COMP_METHOD *meth);
|
---|
34 |
|
---|
35 | int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
|
---|
36 | unsigned char *in, int ilen);
|
---|
37 | int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
|
---|
38 | unsigned char *in, int ilen);
|
---|
39 |
|
---|
40 | COMP_METHOD *COMP_zlib(void);
|
---|
41 | COMP_METHOD *COMP_zlib_oneshot(void);
|
---|
42 | COMP_METHOD *COMP_brotli(void);
|
---|
43 | COMP_METHOD *COMP_brotli_oneshot(void);
|
---|
44 | COMP_METHOD *COMP_zstd(void);
|
---|
45 | COMP_METHOD *COMP_zstd_oneshot(void);
|
---|
46 |
|
---|
47 | const BIO_METHOD *BIO_f_zlib(void);
|
---|
48 | const BIO_METHOD *BIO_f_brotli(void);
|
---|
49 | const BIO_METHOD *BIO_f_zstd(void);
|
---|
50 |
|
---|
51 | =head1 DESCRIPTION
|
---|
52 |
|
---|
53 | These functions provide compression support for OpenSSL. Compression is used within
|
---|
54 | the OpenSSL library to support TLS record and certificate compression.
|
---|
55 |
|
---|
56 | COMP_CTX_new() is used to create a new B<COMP_CTX> structure used to compress data.
|
---|
57 |
|
---|
58 | COMP_CTX_free() is used to free the returned B<COMP_CTX>.
|
---|
59 | If the argument is NULL, nothing is done.
|
---|
60 |
|
---|
61 | COMP_CTX_get_method() returns the B<COMP_METHOD> of the given I<ctx>.
|
---|
62 |
|
---|
63 | COMP_CTX_get_type() and COMP_get_type() return the NID for the B<COMP_CTX> and
|
---|
64 | B<COMP_METHOD>, respectively. COMP_get_name() returns the name of the algorithm
|
---|
65 | of the given B<COMP_METHOD>.
|
---|
66 |
|
---|
67 | COMP_compress_block() compresses b<ilen> bytes from the buffer I<in> into the
|
---|
68 | buffer b<out> of size I<olen> using the algorithm specified by I<ctx>.
|
---|
69 |
|
---|
70 | COMP_expand_block() expands I<ilen> bytes from the buffer I<in> into the
|
---|
71 | buffer I<out> of size I<olen> using the algorithm specified by I<ctx>.
|
---|
72 |
|
---|
73 | Methods (B<COMP_METHOD>) may be specified by one of these functions. These functions
|
---|
74 | will be available even if their corresponding compression algorithm is not configured
|
---|
75 | into the OpenSSL library. In such a case, NULL will be returned.
|
---|
76 |
|
---|
77 | =over 4
|
---|
78 |
|
---|
79 | =item *
|
---|
80 |
|
---|
81 | COMP_zlib() returns a B<COMP_METHOD> for stream-based ZLIB compression.
|
---|
82 |
|
---|
83 | =item *
|
---|
84 |
|
---|
85 | COMP_zlib_oneshot() returns a B<COMP_METHOD> for one-shot ZLIB compression.
|
---|
86 |
|
---|
87 | =item *
|
---|
88 |
|
---|
89 | COMP_brotli() returns a B<COMP_METHOD> for stream-based Brotli compression.
|
---|
90 |
|
---|
91 | =item *
|
---|
92 |
|
---|
93 | COMP_brotli_oneshot() returns a B<COMP_METHOD> for one-shot Brotli compression.
|
---|
94 |
|
---|
95 | =item *
|
---|
96 |
|
---|
97 | COMP_zstd() returns a B<COMP_METHOD> for stream-based Zstandard compression.
|
---|
98 |
|
---|
99 | =item *
|
---|
100 |
|
---|
101 | COMP_zstd_oneshot() returns a B<COMP_METHOD> for one-shot Zstandard compression.
|
---|
102 |
|
---|
103 | =back
|
---|
104 |
|
---|
105 | BIO_f_zlib(), BIO_f_brotli() BIO_f_zstd() each return a B<BIO_METHOD> that may be used to
|
---|
106 | create a B<BIO> via B<BIO_new(3)> to read and write compressed files or streams.
|
---|
107 | The functions are only available if the corresponding algorithm is compiled into
|
---|
108 | the OpenSSL library. NULL may be returned if the algorithm fails to load dynamically.
|
---|
109 |
|
---|
110 | =head1 NOTES
|
---|
111 |
|
---|
112 | While compressing non-compressible data, the output may be larger than the
|
---|
113 | input. Care should be taken to size output buffers appropriate for both
|
---|
114 | compression and expansion.
|
---|
115 |
|
---|
116 | Compression support and compression algorithms must be enabled and built into
|
---|
117 | the library before use. Refer to the INSTALL.md file when configuring OpenSSL.
|
---|
118 |
|
---|
119 | ZLIB may be found at L<https://zlib.net>
|
---|
120 |
|
---|
121 | Brotli may be found at L<https://github.com/google/brotli>.
|
---|
122 |
|
---|
123 | Zstandard may be found at L<https://github.com/facebook/zstd>.
|
---|
124 |
|
---|
125 | Compression of SSL/TLS records is not recommended, as it has been
|
---|
126 | shown to lead to the CRIME attack L<https://en.wikipedia.org/wiki/CRIME>.
|
---|
127 | It is disabled by default, and may be enabled by clearing the
|
---|
128 | SSL_OP_NO_COMPRESSION option and setting the security level as appropriate.
|
---|
129 | See the documentation for the L<SSL_CTX_set_options(3)> and
|
---|
130 | L<SSL_set_options(3)> functions.
|
---|
131 |
|
---|
132 | Compression is also used to support certificate compression as described
|
---|
133 | in RFC8879 L<https://datatracker.ietf.org/doc/html/rfc8879>.
|
---|
134 | It may be disabled via the SSL_OP_NO_TX_CERTIFICATE_COMPRESSION and
|
---|
135 | SSL_OP_NO_RX_CERTIFICATE_COMPRESSION options of the
|
---|
136 | L<SSL_CTX_set_options(3)> or L<SSL_set_options(3)> functions.
|
---|
137 |
|
---|
138 | COMP_zlib(), COMP_brotli() and COMP_zstd() are stream-based compression methods.
|
---|
139 | Internal state (including compression dictionary) is maintained between calls.
|
---|
140 | If an error is returned, the stream is corrupted, and should be closed.
|
---|
141 |
|
---|
142 | COMP_zlib_oneshot(), COMP_brotli_oneshot() and COMP_zstd_oneshot() are not stream-based. These
|
---|
143 | methods do not maintain state between calls. An error in one call does not affect
|
---|
144 | future calls.
|
---|
145 |
|
---|
146 | =head1 RETURN VALUES
|
---|
147 |
|
---|
148 | COMP_CTX_new() returns a B<COMP_CTX> on success, or NULL on failure.
|
---|
149 |
|
---|
150 | COMP_CTX_get_method(), COMP_zlib(), COMP_zlib_oneshot(), COMP_brotli(), COMP_brotli_oneshot(),
|
---|
151 | COMP_zstd(), and COMP_zstd_oneshot() return a B<COMP_METHOD> on success,
|
---|
152 | or NULL on failure.
|
---|
153 |
|
---|
154 | COMP_CTX_get_type() and COMP_get_type() return a NID value. On failure,
|
---|
155 | NID_undef is returned.
|
---|
156 |
|
---|
157 | COMP_compress_block() and COMP_expand_block() return the number of
|
---|
158 | bytes stored in the output buffer I<out>. This may be 0. On failure,
|
---|
159 | -1 is returned.
|
---|
160 |
|
---|
161 | COMP_get_name() returns a B<const char *> that must not be freed
|
---|
162 | on success, or NULL on failure.
|
---|
163 |
|
---|
164 | BIO_f_zlib(), BIO_f_brotli() and BIO_f_zstd() return NULL on error, and
|
---|
165 | a B<BIO_METHOD> on success.
|
---|
166 |
|
---|
167 | =head1 SEE ALSO
|
---|
168 |
|
---|
169 | L<BIO_new(3)>, L<SSL_CTX_set_options(3)>, L<SSL_set_options(3)>
|
---|
170 |
|
---|
171 | =head1 HISTORY
|
---|
172 |
|
---|
173 | Brotli and Zstandard functions were added in OpenSSL 3.2.
|
---|
174 |
|
---|
175 | =head1 COPYRIGHT
|
---|
176 |
|
---|
177 | Copyright 2022-2024 The OpenSSL Project Authors. All Rights Reserved.
|
---|
178 |
|
---|
179 | Licensed under the Apache License 2.0 (the "License"). You may not use
|
---|
180 | this file except in compliance with the License. You can obtain a copy
|
---|
181 | in the file LICENSE in the source distribution or at
|
---|
182 | L<https://www.openssl.org/source/license.html>.
|
---|
183 |
|
---|
184 | =cut
|
---|