aboutsummaryrefslogtreecommitdiff
path: root/include/xfrm/compress.h
blob: b5db98538074b4694688cd40c75fe6e8653b00a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* SPDX-License-Identifier: GPL-3.0-or-later */
/*
 * compress.h
 *
 * Copyright (C) 2021 David Oberhollenzer <goliath@infraroot.at>
 */
#ifndef XFRM_COMPRESS_H
#define XFRM_COMPRESS_H

#include "xfrm/stream.h"

typedef struct {
	uint32_t flags;
	uint32_t level;

	union {
		struct {
			uint8_t vli;
			uint8_t pad0[15];
		} xz;

		struct {
			uint16_t window_size;
			uint16_t padd0[7];
		} gzip;

		struct {
			uint8_t work_factor;
			uint8_t padd0[15];
		} bzip2;

		uint64_t padd0[2];
	} opt;
} compressor_config_t;

typedef enum {
	COMP_FLAG_XZ_EXTREME = 0x0001,
} COMP_FLAG_XZ;

typedef enum {
	COMP_XZ_VLI_X86 = 1,
	COMP_XZ_VLI_POWERPC = 2,
	COMP_XZ_VLI_IA64 = 3,
	COMP_XZ_VLI_ARM = 4,
	COMP_XZ_VLI_ARMTHUMB = 5,
	COMP_XZ_VLI_SPARC = 6,
} COMP_XZ_VLI;

#define COMP_GZIP_MIN_LEVEL (1)
#define COMP_GZIP_MAX_LEVEL (9)
#define COMP_GZIP_DEFAULT_LEVEL (9)

#define COMP_GZIP_MIN_WINDOW (8)
#define COMP_GZIP_MAX_WINDOW (15)
#define COMP_GZIP_DEFAULT_WINDOW (15)

#define COMP_ZSTD_MIN_LEVEL (1)
#define COMP_ZSTD_MAX_LEVEL (22)
#define COMP_ZSTD_DEFAULT_LEVEL (15)

#define COMP_BZIP2_MIN_LEVEL (1)
#define COMP_BZIP2_MAX_LEVEL (9)
#define COMP_BZIP2_DEFAULT_LEVEL (9)

#define COMP_BZIP2_MIN_WORK_FACTOR (0)
#define COMP_BZIP2_MAX_WORK_FACTOR (250)
#define COMP_BZIP2_DEFAULT_WORK_FACTOR (30)

#define COMP_XZ_MIN_LEVEL (0)
#define COMP_XZ_MAX_LEVEL (9)
#define COMP_XZ_DEFAULT_LEVEL (6)

enum {
	XFRM_COMPRESSOR_GZIP = 1,
	XFRM_COMPRESSOR_XZ = 2,
	XFRM_COMPRESSOR_ZSTD = 3,
	XFRM_COMPRESSOR_BZIP2 = 4,

	XFRM_COMPRESSOR_MIN = 1,
	XFRM_COMPRESSOR_MAX = 4,
};

#ifdef __cplusplus
extern "C" {
#endif

xfrm_stream_t *compressor_stream_bzip2_create(const compressor_config_t *cfg);

xfrm_stream_t *decompressor_stream_bzip2_create(void);

xfrm_stream_t *compressor_stream_xz_create(const compressor_config_t *cfg);

xfrm_stream_t *decompressor_stream_xz_create(void);

xfrm_stream_t *compressor_stream_gzip_create(const compressor_config_t *cfg);

xfrm_stream_t *decompressor_stream_gzip_create(void);

xfrm_stream_t *compressor_stream_zstd_create(const compressor_config_t *cfg);

xfrm_stream_t *decompressor_stream_zstd_create(void);

int xfrm_compressor_id_from_name(const char *name);

int xfrm_compressor_id_from_magic(const void *data, size_t count);

const char *xfrm_compressor_name_from_id(int id);

xfrm_stream_t *compressor_stream_create(int id, const compressor_config_t *cfg);

xfrm_stream_t *decompressor_stream_create(int id);

#ifdef __cplusplus
}
#endif

#endif /* XFRM_COMPRESS_H */