1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Asynchronous Compression operations
4  *
5  * Copyright (c) 2016, Intel Corporation
6  * Authors: Weigang Li <weigang.li@intel.com>
7  *          Giovanni Cabiddu <giovanni.cabiddu@intel.com>
8  */
9 #ifndef _CRYPTO_ACOMP_INT_H
10 #define _CRYPTO_ACOMP_INT_H
11 
12 #include <crypto/acompress.h>
13 #include <crypto/algapi.h>
14 
15 /*
16  * Transform internal helpers.
17  */
acomp_request_ctx(struct acomp_req * req)18 static inline void *acomp_request_ctx(struct acomp_req *req)
19 {
20 	return req->__ctx;
21 }
22 
acomp_tfm_ctx(struct crypto_acomp * tfm)23 static inline void *acomp_tfm_ctx(struct crypto_acomp *tfm)
24 {
25 	return tfm->base.__crt_ctx;
26 }
27 
acomp_request_complete(struct acomp_req * req,int err)28 static inline void acomp_request_complete(struct acomp_req *req,
29 					  int err)
30 {
31 	crypto_request_complete(&req->base, err);
32 }
33 
acomp_alg_name(struct crypto_acomp * tfm)34 static inline const char *acomp_alg_name(struct crypto_acomp *tfm)
35 {
36 	return crypto_acomp_tfm(tfm)->__crt_alg->cra_name;
37 }
38 
__acomp_request_alloc(struct crypto_acomp * tfm)39 static inline struct acomp_req *__acomp_request_alloc(struct crypto_acomp *tfm)
40 {
41 	struct acomp_req *req;
42 
43 	req = kzalloc(sizeof(*req) + crypto_acomp_reqsize(tfm), GFP_KERNEL);
44 	if (likely(req))
45 		acomp_request_set_tfm(req, tfm);
46 	return req;
47 }
48 
__acomp_request_free(struct acomp_req * req)49 static inline void __acomp_request_free(struct acomp_req *req)
50 {
51 	kfree_sensitive(req);
52 }
53 
54 /**
55  * crypto_register_acomp() -- Register asynchronous compression algorithm
56  *
57  * Function registers an implementation of an asynchronous
58  * compression algorithm
59  *
60  * @alg:	algorithm definition
61  *
62  * Return:	zero on success; error code in case of error
63  */
64 int crypto_register_acomp(struct acomp_alg *alg);
65 
66 /**
67  * crypto_unregister_acomp() -- Unregister asynchronous compression algorithm
68  *
69  * Function unregisters an implementation of an asynchronous
70  * compression algorithm
71  *
72  * @alg:	algorithm definition
73  */
74 void crypto_unregister_acomp(struct acomp_alg *alg);
75 
76 int crypto_register_acomps(struct acomp_alg *algs, int count);
77 void crypto_unregister_acomps(struct acomp_alg *algs, int count);
78 
79 #endif
80