2
0

COMP_CTX_new.pod 5.9 KB

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