aboutsummaryrefslogtreecommitdiff
path: root/crypto/comp
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/comp')
-rw-r--r--crypto/comp/c_zlib.c172
-rw-r--r--crypto/comp/comp_err.c22
-rw-r--r--crypto/comp/comp_lib.c6
-rw-r--r--crypto/comp/comp_local.h22
4 files changed, 110 insertions, 112 deletions
diff --git a/crypto/comp/c_zlib.c b/crypto/comp/c_zlib.c
index 9a7087e44404..3f583ff4f363 100644
--- a/crypto/comp/c_zlib.c
+++ b/crypto/comp/c_zlib.c
@@ -1,5 +1,5 @@
/*
- * Copyright 1998-2021 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 1998-2026 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
@@ -30,19 +30,19 @@ static COMP_METHOD zlib_method_nozlib = {
};
#ifndef ZLIB
-# undef ZLIB_SHARED
+#undef ZLIB_SHARED
#else
-# include <zlib.h>
+#include <zlib.h>
static int zlib_stateful_init(COMP_CTX *ctx);
static void zlib_stateful_finish(COMP_CTX *ctx);
static int zlib_stateful_compress_block(COMP_CTX *ctx, unsigned char *out,
- unsigned int olen, unsigned char *in,
- unsigned int ilen);
+ unsigned int olen, unsigned char *in,
+ unsigned int ilen);
static int zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out,
- unsigned int olen, unsigned char *in,
- unsigned int ilen);
+ unsigned int olen, unsigned char *in,
+ unsigned int ilen);
/* memory allocations functions for zlib initialisation */
static void *zlib_zalloc(void *opaque, unsigned int no, unsigned int size)
@@ -58,7 +58,6 @@ static void zlib_zfree(void *opaque, void *address)
OPENSSL_free(address);
}
-
static COMP_METHOD zlib_stateful_method = {
NID_zlib_compression,
LN_zlib_compression,
@@ -74,26 +73,26 @@ static COMP_METHOD zlib_stateful_method = {
* work. Therefore, all ZLIB routines are loaded at run time
* and we do not link to a .LIB file when ZLIB_SHARED is set.
*/
-# if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
-# include <windows.h>
-# endif /* !(OPENSSL_SYS_WINDOWS ||
- * OPENSSL_SYS_WIN32) */
+#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
+#include <windows.h>
+#endif /* !(OPENSSL_SYS_WINDOWS || \
+ * OPENSSL_SYS_WIN32) */
-# ifdef ZLIB_SHARED
-# include "internal/dso.h"
+#ifdef ZLIB_SHARED
+#include "internal/dso.h"
/* Function pointers */
-typedef int (*compress_ft) (Bytef *dest, uLongf * destLen,
- const Bytef *source, uLong sourceLen);
-typedef int (*inflateEnd_ft) (z_streamp strm);
-typedef int (*inflate_ft) (z_streamp strm, int flush);
-typedef int (*inflateInit__ft) (z_streamp strm,
- const char *version, int stream_size);
-typedef int (*deflateEnd_ft) (z_streamp strm);
-typedef int (*deflate_ft) (z_streamp strm, int flush);
-typedef int (*deflateInit__ft) (z_streamp strm, int level,
- const char *version, int stream_size);
-typedef const char *(*zError__ft) (int err);
+typedef int (*compress_ft)(Bytef *dest, uLongf *destLen,
+ const Bytef *source, uLong sourceLen);
+typedef int (*inflateEnd_ft)(z_streamp strm);
+typedef int (*inflate_ft)(z_streamp strm, int flush);
+typedef int (*inflateInit__ft)(z_streamp strm,
+ const char *version, int stream_size);
+typedef int (*deflateEnd_ft)(z_streamp strm);
+typedef int (*deflate_ft)(z_streamp strm, int flush);
+typedef int (*deflateInit__ft)(z_streamp strm, int level,
+ const char *version, int stream_size);
+typedef const char *(*zError__ft)(int err);
static compress_ft p_compress = NULL;
static inflateEnd_ft p_inflateEnd = NULL;
static inflate_ft p_inflate = NULL;
@@ -105,15 +104,15 @@ static zError__ft p_zError = NULL;
static DSO *zlib_dso = NULL;
-# define compress p_compress
-# define inflateEnd p_inflateEnd
-# define inflate p_inflate
-# define inflateInit_ p_inflateInit_
-# define deflateEnd p_deflateEnd
-# define deflate p_deflate
-# define deflateInit_ p_deflateInit_
-# define zError p_zError
-# endif /* ZLIB_SHARED */
+#define compress p_compress
+#define inflateEnd p_inflateEnd
+#define inflate p_inflate
+#define inflateInit_ p_inflateInit_
+#define deflateEnd p_deflateEnd
+#define deflate p_deflate
+#define deflateInit_ p_deflateInit_
+#define zError p_zError
+#endif /* ZLIB_SHARED */
struct zlib_state {
z_stream istream;
@@ -143,13 +142,13 @@ static int zlib_stateful_init(COMP_CTX *ctx)
state->ostream.next_in = Z_NULL;
state->ostream.next_out = Z_NULL;
err = deflateInit_(&state->ostream, Z_DEFAULT_COMPRESSION,
- ZLIB_VERSION, sizeof(z_stream));
+ ZLIB_VERSION, sizeof(z_stream));
if (err != Z_OK)
goto err;
ctx->data = state;
return 1;
- err:
+err:
OPENSSL_free(state);
return 0;
}
@@ -163,8 +162,8 @@ static void zlib_stateful_finish(COMP_CTX *ctx)
}
static int zlib_stateful_compress_block(COMP_CTX *ctx, unsigned char *out,
- unsigned int olen, unsigned char *in,
- unsigned int ilen)
+ unsigned int olen, unsigned char *in,
+ unsigned int ilen)
{
int err = Z_OK;
struct zlib_state *state = ctx->data;
@@ -184,8 +183,8 @@ static int zlib_stateful_compress_block(COMP_CTX *ctx, unsigned char *out,
}
static int zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out,
- unsigned int olen, unsigned char *in,
- unsigned int ilen)
+ unsigned int olen, unsigned char *in,
+ unsigned int ilen)
{
int err = Z_OK;
struct zlib_state *state = ctx->data;
@@ -207,38 +206,38 @@ static int zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out,
static CRYPTO_ONCE zlib_once = CRYPTO_ONCE_STATIC_INIT;
DEFINE_RUN_ONCE_STATIC(ossl_comp_zlib_init)
{
-# ifdef ZLIB_SHARED
+#ifdef ZLIB_SHARED
/* LIBZ may be externally defined, and we should respect that value */
-# ifndef LIBZ
-# if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
-# define LIBZ "ZLIB1"
-# elif defined(OPENSSL_SYS_VMS)
-# define LIBZ "LIBZ"
-# else
-# define LIBZ "z"
-# endif
-# endif
+#ifndef LIBZ
+#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
+#define LIBZ "ZLIB1"
+#elif defined(OPENSSL_SYS_VMS)
+#define LIBZ "LIBZ"
+#else
+#define LIBZ "z"
+#endif
+#endif
zlib_dso = DSO_load(NULL, LIBZ, NULL, 0);
if (zlib_dso != NULL) {
- p_compress = (compress_ft) DSO_bind_func(zlib_dso, "compress");
- p_inflateEnd = (inflateEnd_ft) DSO_bind_func(zlib_dso, "inflateEnd");
- p_inflate = (inflate_ft) DSO_bind_func(zlib_dso, "inflate");
- p_inflateInit_ = (inflateInit__ft) DSO_bind_func(zlib_dso, "inflateInit_");
- p_deflateEnd = (deflateEnd_ft) DSO_bind_func(zlib_dso, "deflateEnd");
- p_deflate = (deflate_ft) DSO_bind_func(zlib_dso, "deflate");
- p_deflateInit_ = (deflateInit__ft) DSO_bind_func(zlib_dso, "deflateInit_");
- p_zError = (zError__ft) DSO_bind_func(zlib_dso, "zError");
+ p_compress = (compress_ft)DSO_bind_func(zlib_dso, "compress");
+ p_inflateEnd = (inflateEnd_ft)DSO_bind_func(zlib_dso, "inflateEnd");
+ p_inflate = (inflate_ft)DSO_bind_func(zlib_dso, "inflate");
+ p_inflateInit_ = (inflateInit__ft)DSO_bind_func(zlib_dso, "inflateInit_");
+ p_deflateEnd = (deflateEnd_ft)DSO_bind_func(zlib_dso, "deflateEnd");
+ p_deflate = (deflate_ft)DSO_bind_func(zlib_dso, "deflate");
+ p_deflateInit_ = (deflateInit__ft)DSO_bind_func(zlib_dso, "deflateInit_");
+ p_zError = (zError__ft)DSO_bind_func(zlib_dso, "zError");
+ }
- if (p_compress == NULL || p_inflateEnd == NULL
- || p_inflate == NULL || p_inflateInit_ == NULL
- || p_deflateEnd == NULL || p_deflate == NULL
- || p_deflateInit_ == NULL || p_zError == NULL) {
- ossl_comp_zlib_cleanup();
- return 0;
- }
+ if (p_compress == NULL || p_inflateEnd == NULL
+ || p_inflate == NULL || p_inflateInit_ == NULL
+ || p_deflateEnd == NULL || p_deflate == NULL
+ || p_deflateInit_ == NULL || p_zError == NULL) {
+ ossl_comp_zlib_cleanup();
+ return 0;
}
-# endif
+#endif
return 1;
}
#endif
@@ -269,19 +268,19 @@ void ossl_comp_zlib_cleanup(void)
/* Zlib based compression/decompression filter BIO */
typedef struct {
- unsigned char *ibuf; /* Input buffer */
- int ibufsize; /* Buffer size */
- z_stream zin; /* Input decompress context */
- unsigned char *obuf; /* Output buffer */
- int obufsize; /* Output buffer size */
- unsigned char *optr; /* Position in output buffer */
- int ocount; /* Amount of data in output buffer */
- int odone; /* deflate EOF */
- int comp_level; /* Compression level to use */
- z_stream zout; /* Output compression context */
+ unsigned char *ibuf; /* Input buffer */
+ int ibufsize; /* Buffer size */
+ z_stream zin; /* Input decompress context */
+ unsigned char *obuf; /* Output buffer */
+ int obufsize; /* Output buffer size */
+ unsigned char *optr; /* Position in output buffer */
+ int ocount; /* Amount of data in output buffer */
+ int odone; /* deflate EOF */
+ int comp_level; /* Compression level to use */
+ z_stream zout; /* Output compression context */
} BIO_ZLIB_CTX;
-# define ZLIB_DEFAULT_BUFSIZE 1024
+#define ZLIB_DEFAULT_BUFSIZE 1024
static int bio_zlib_new(BIO *bi);
static int bio_zlib_free(BIO *bi);
@@ -297,8 +296,8 @@ static const BIO_METHOD bio_meth_zlib = {
bio_zlib_write,
bread_conv,
bio_zlib_read,
- NULL, /* bio_zlib_puts, */
- NULL, /* bio_zlib_gets, */
+ NULL, /* bio_zlib_puts, */
+ NULL, /* bio_zlib_gets, */
bio_zlib_ctrl,
bio_zlib_new,
bio_zlib_free,
@@ -314,12 +313,12 @@ static int bio_zlib_new(BIO *bi)
{
BIO_ZLIB_CTX *ctx;
-# ifdef ZLIB_SHARED
+#ifdef ZLIB_SHARED
if (!RUN_ONCE(&zlib_once, ossl_comp_zlib_init)) {
ERR_raise(ERR_LIB_COMP, COMP_R_ZLIB_NOT_SUPPORTED);
return 0;
}
-# endif
+#endif
ctx = OPENSSL_zalloc(sizeof(*ctx));
if (ctx == NULL) {
ERR_raise(ERR_LIB_COMP, ERR_R_MALLOC_FAILURE);
@@ -382,7 +381,7 @@ static int bio_zlib_read(BIO *b, char *out, int outl)
}
if ((ret = inflateInit(zin)) != Z_OK) {
ERR_raise_data(ERR_LIB_COMP, COMP_R_ZLIB_INFLATE_ERROR,
- "zlib error: %s", zError(ret));
+ "zlib error: %s", zError(ret));
return 0;
}
zin->next_in = ctx->ibuf;
@@ -398,7 +397,7 @@ static int bio_zlib_read(BIO *b, char *out, int outl)
ret = inflate(zin, 0);
if ((ret != Z_OK) && (ret != Z_STREAM_END)) {
ERR_raise_data(ERR_LIB_COMP, COMP_R_ZLIB_INFLATE_ERROR,
- "zlib error: %s", zError(ret));
+ "zlib error: %s", zError(ret));
return 0;
}
/* If EOF or we've read everything then return */
@@ -449,7 +448,7 @@ static int bio_zlib_write(BIO *b, const char *in, int inl)
ctx->ocount = 0;
if ((ret = deflateInit(zout, ctx->comp_level)) != Z_OK) {
ERR_raise_data(ERR_LIB_COMP, COMP_R_ZLIB_DEFLATE_ERROR,
- "zlib error: %s", zError(ret));
+ "zlib error: %s", zError(ret));
return 0;
}
zout->next_out = ctx->obuf;
@@ -488,7 +487,7 @@ static int bio_zlib_write(BIO *b, const char *in, int inl)
ret = deflate(zout, 0);
if (ret != Z_OK) {
ERR_raise_data(ERR_LIB_COMP, COMP_R_ZLIB_DEFLATE_ERROR,
- "zlib error: %s", zError(ret));
+ "zlib error: %s", zError(ret));
return 0;
}
ctx->ocount = ctx->obufsize - zout->avail_out;
@@ -537,7 +536,7 @@ static int bio_zlib_flush(BIO *b)
ctx->odone = 1;
else if (ret != Z_OK) {
ERR_raise_data(ERR_LIB_COMP, COMP_R_ZLIB_DEFLATE_ERROR,
- "zlib error: %s", zError(ret));
+ "zlib error: %s", zError(ret));
return 0;
}
ctx->ocount = ctx->obufsize - zout->avail_out;
@@ -627,7 +626,6 @@ static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr)
default:
ret = BIO_ctrl(next, cmd, num, ptr);
break;
-
}
return ret;
diff --git a/crypto/comp/comp_err.c b/crypto/comp/comp_err.c
index 70a6eea0f052..b794e0fa22cd 100644
--- a/crypto/comp/comp_err.c
+++ b/crypto/comp/comp_err.c
@@ -14,26 +14,26 @@
#ifndef OPENSSL_NO_COMP
-# ifndef OPENSSL_NO_ERR
+#ifndef OPENSSL_NO_ERR
static const ERR_STRING_DATA COMP_str_reasons[] = {
- {ERR_PACK(ERR_LIB_COMP, 0, COMP_R_ZLIB_DEFLATE_ERROR),
- "zlib deflate error"},
- {ERR_PACK(ERR_LIB_COMP, 0, COMP_R_ZLIB_INFLATE_ERROR),
- "zlib inflate error"},
- {ERR_PACK(ERR_LIB_COMP, 0, COMP_R_ZLIB_NOT_SUPPORTED),
- "zlib not supported"},
- {0, NULL}
+ { ERR_PACK(ERR_LIB_COMP, 0, COMP_R_ZLIB_DEFLATE_ERROR),
+ "zlib deflate error" },
+ { ERR_PACK(ERR_LIB_COMP, 0, COMP_R_ZLIB_INFLATE_ERROR),
+ "zlib inflate error" },
+ { ERR_PACK(ERR_LIB_COMP, 0, COMP_R_ZLIB_NOT_SUPPORTED),
+ "zlib not supported" },
+ { 0, NULL }
};
-# endif
+#endif
int ossl_err_load_COMP_strings(void)
{
-# ifndef OPENSSL_NO_ERR
+#ifndef OPENSSL_NO_ERR
if (ERR_reason_error_string(COMP_str_reasons[0].error) == NULL)
ERR_load_strings_const(COMP_str_reasons);
-# endif
+#endif
return 1;
}
#else
diff --git a/crypto/comp/comp_lib.c b/crypto/comp/comp_lib.c
index bf9069d871a4..36d63700175a 100644
--- a/crypto/comp/comp_lib.c
+++ b/crypto/comp/comp_lib.c
@@ -57,7 +57,7 @@ void COMP_CTX_free(COMP_CTX *ctx)
}
int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
- unsigned char *in, int ilen)
+ unsigned char *in, int ilen)
{
int ret;
if (ctx->meth->compress == NULL) {
@@ -72,7 +72,7 @@ int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
}
int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
- unsigned char *in, int ilen)
+ unsigned char *in, int ilen)
{
int ret;
@@ -87,7 +87,7 @@ int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
return ret;
}
-int COMP_CTX_get_type(const COMP_CTX* comp)
+int COMP_CTX_get_type(const COMP_CTX *comp)
{
return comp->meth ? comp->meth->type : NID_undef;
}
diff --git a/crypto/comp/comp_local.h b/crypto/comp/comp_local.h
index acf113e31cd0..f0161000c0c5 100644
--- a/crypto/comp/comp_local.h
+++ b/crypto/comp/comp_local.h
@@ -8,16 +8,16 @@
*/
struct comp_method_st {
- int type; /* NID for compression library */
- const char *name; /* A text string to identify the library */
- int (*init) (COMP_CTX *ctx);
- void (*finish) (COMP_CTX *ctx);
- int (*compress) (COMP_CTX *ctx,
- unsigned char *out, unsigned int olen,
- unsigned char *in, unsigned int ilen);
- int (*expand) (COMP_CTX *ctx,
- unsigned char *out, unsigned int olen,
- unsigned char *in, unsigned int ilen);
+ int type; /* NID for compression library */
+ const char *name; /* A text string to identify the library */
+ int (*init)(COMP_CTX *ctx);
+ void (*finish)(COMP_CTX *ctx);
+ int (*compress)(COMP_CTX *ctx,
+ unsigned char *out, unsigned int olen,
+ unsigned char *in, unsigned int ilen);
+ int (*expand)(COMP_CTX *ctx,
+ unsigned char *out, unsigned int olen,
+ unsigned char *in, unsigned int ilen);
};
struct comp_ctx_st {
@@ -26,5 +26,5 @@ struct comp_ctx_st {
unsigned long compress_out;
unsigned long expand_in;
unsigned long expand_out;
- void* data;
+ void *data;
};