]> git.ipfire.org Git - thirdparty/kernel/linux.git/blob - include/crypto/internal/scompress.h
crypto: remove CONFIG_CRYPTO_STATS
[thirdparty/kernel/linux.git] / include / crypto / internal / scompress.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * Synchronous Compression operations
4 *
5 * Copyright 2015 LG Electronics Inc.
6 * Copyright (c) 2016, Intel Corporation
7 * Author: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
8 */
9 #ifndef _CRYPTO_SCOMP_INT_H
10 #define _CRYPTO_SCOMP_INT_H
11
12 #include <crypto/acompress.h>
13 #include <crypto/algapi.h>
14
15 #define SCOMP_SCRATCH_SIZE 131072
16
17 struct acomp_req;
18
19 struct crypto_scomp {
20 struct crypto_tfm base;
21 };
22
23 /**
24 * struct scomp_alg - synchronous compression algorithm
25 *
26 * @alloc_ctx: Function allocates algorithm specific context
27 * @free_ctx: Function frees context allocated with alloc_ctx
28 * @compress: Function performs a compress operation
29 * @decompress: Function performs a de-compress operation
30 * @base: Common crypto API algorithm data structure
31 */
32 struct scomp_alg {
33 void *(*alloc_ctx)(struct crypto_scomp *tfm);
34 void (*free_ctx)(struct crypto_scomp *tfm, void *ctx);
35 int (*compress)(struct crypto_scomp *tfm, const u8 *src,
36 unsigned int slen, u8 *dst, unsigned int *dlen,
37 void *ctx);
38 int (*decompress)(struct crypto_scomp *tfm, const u8 *src,
39 unsigned int slen, u8 *dst, unsigned int *dlen,
40 void *ctx);
41 struct crypto_alg base;
42 };
43
44 static inline struct scomp_alg *__crypto_scomp_alg(struct crypto_alg *alg)
45 {
46 return container_of(alg, struct scomp_alg, base);
47 }
48
49 static inline struct crypto_scomp *__crypto_scomp_tfm(struct crypto_tfm *tfm)
50 {
51 return container_of(tfm, struct crypto_scomp, base);
52 }
53
54 static inline struct crypto_tfm *crypto_scomp_tfm(struct crypto_scomp *tfm)
55 {
56 return &tfm->base;
57 }
58
59 static inline void crypto_free_scomp(struct crypto_scomp *tfm)
60 {
61 crypto_destroy_tfm(tfm, crypto_scomp_tfm(tfm));
62 }
63
64 static inline struct scomp_alg *crypto_scomp_alg(struct crypto_scomp *tfm)
65 {
66 return __crypto_scomp_alg(crypto_scomp_tfm(tfm)->__crt_alg);
67 }
68
69 static inline void *crypto_scomp_alloc_ctx(struct crypto_scomp *tfm)
70 {
71 return crypto_scomp_alg(tfm)->alloc_ctx(tfm);
72 }
73
74 static inline void crypto_scomp_free_ctx(struct crypto_scomp *tfm,
75 void *ctx)
76 {
77 return crypto_scomp_alg(tfm)->free_ctx(tfm, ctx);
78 }
79
80 static inline int crypto_scomp_compress(struct crypto_scomp *tfm,
81 const u8 *src, unsigned int slen,
82 u8 *dst, unsigned int *dlen, void *ctx)
83 {
84 return crypto_scomp_alg(tfm)->compress(tfm, src, slen, dst, dlen, ctx);
85 }
86
87 static inline int crypto_scomp_decompress(struct crypto_scomp *tfm,
88 const u8 *src, unsigned int slen,
89 u8 *dst, unsigned int *dlen,
90 void *ctx)
91 {
92 return crypto_scomp_alg(tfm)->decompress(tfm, src, slen, dst, dlen,
93 ctx);
94 }
95
96 /**
97 * crypto_register_scomp() -- Register synchronous compression algorithm
98 *
99 * Function registers an implementation of a synchronous
100 * compression algorithm
101 *
102 * @alg: algorithm definition
103 *
104 * Return: zero on success; error code in case of error
105 */
106 int crypto_register_scomp(struct scomp_alg *alg);
107
108 /**
109 * crypto_unregister_scomp() -- Unregister synchronous compression algorithm
110 *
111 * Function unregisters an implementation of a synchronous
112 * compression algorithm
113 *
114 * @alg: algorithm definition
115 */
116 void crypto_unregister_scomp(struct scomp_alg *alg);
117
118 int crypto_register_scomps(struct scomp_alg *algs, int count);
119 void crypto_unregister_scomps(struct scomp_alg *algs, int count);
120
121 #endif