1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Asynchronous Compression operations
5 * Copyright (c) 2016, Intel Corporation
6 * Authors: Weigang Li <weigang.li@intel.com>
7 * Giovanni Cabiddu <giovanni.cabiddu@intel.com>
9 #ifndef _CRYPTO_ACOMP_INT_H
10 #define _CRYPTO_ACOMP_INT_H
12 #include <crypto/acompress.h>
13 #include <crypto/algapi.h>
16 * struct acomp_alg - asynchronous compression algorithm
18 * @compress: Function performs a compress operation
19 * @decompress: Function performs a de-compress operation
20 * @dst_free: Frees destination buffer if allocated inside the algorithm
21 * @init: Initialize the cryptographic transformation object.
22 * This function is used to initialize the cryptographic
23 * transformation object. This function is called only once at
24 * the instantiation time, right after the transformation context
25 * was allocated. In case the cryptographic hardware has some
26 * special requirements which need to be handled by software, this
27 * function shall check for the precise requirement of the
28 * transformation and put any software fallbacks in place.
29 * @exit: Deinitialize the cryptographic transformation object. This is a
30 * counterpart to @init, used to remove various changes set in
33 * @reqsize: Context size for (de)compression requests
34 * @base: Common crypto API algorithm data structure
35 * @calg: Cmonn algorithm data structure shared with scomp
38 int (*compress
)(struct acomp_req
*req
);
39 int (*decompress
)(struct acomp_req
*req
);
40 void (*dst_free
)(struct scatterlist
*dst
);
41 int (*init
)(struct crypto_acomp
*tfm
);
42 void (*exit
)(struct crypto_acomp
*tfm
);
47 struct COMP_ALG_COMMON
;
48 struct comp_alg_common calg
;
53 * Transform internal helpers.
55 static inline void *acomp_request_ctx(struct acomp_req
*req
)
60 static inline void *acomp_tfm_ctx(struct crypto_acomp
*tfm
)
62 return tfm
->base
.__crt_ctx
;
65 static inline void acomp_request_complete(struct acomp_req
*req
,
68 crypto_request_complete(&req
->base
, err
);
71 static inline struct acomp_req
*__acomp_request_alloc_noprof(struct crypto_acomp
*tfm
)
73 struct acomp_req
*req
;
75 req
= kzalloc_noprof(sizeof(*req
) + crypto_acomp_reqsize(tfm
), GFP_KERNEL
);
77 acomp_request_set_tfm(req
, tfm
);
80 #define __acomp_request_alloc(...) alloc_hooks(__acomp_request_alloc_noprof(__VA_ARGS__))
82 static inline void __acomp_request_free(struct acomp_req
*req
)
88 * crypto_register_acomp() -- Register asynchronous compression algorithm
90 * Function registers an implementation of an asynchronous
91 * compression algorithm
93 * @alg: algorithm definition
95 * Return: zero on success; error code in case of error
97 int crypto_register_acomp(struct acomp_alg
*alg
);
100 * crypto_unregister_acomp() -- Unregister asynchronous compression algorithm
102 * Function unregisters an implementation of an asynchronous
103 * compression algorithm
105 * @alg: algorithm definition
107 void crypto_unregister_acomp(struct acomp_alg
*alg
);
109 int crypto_register_acomps(struct acomp_alg
*algs
, int count
);
110 void crypto_unregister_acomps(struct acomp_alg
*algs
, int count
);