Commit | Line | Data |
---|---|---|
2874c5fd | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
2ebda74f GC |
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> | |
2ebda74f GC |
8 | */ |
9 | #ifndef _CRYPTO_ACOMP_INT_H | |
10 | #define _CRYPTO_ACOMP_INT_H | |
14386d47 | 11 | |
2ebda74f | 12 | #include <crypto/acompress.h> |
14386d47 | 13 | #include <crypto/algapi.h> |
2ebda74f | 14 | |
0a742389 HX |
15 | /** |
16 | * struct acomp_alg - asynchronous compression algorithm | |
17 | * | |
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 | |
31 | * @init. | |
32 | * | |
33 | * @reqsize: Context size for (de)compression requests | |
0a742389 HX |
34 | * @base: Common crypto API algorithm data structure |
35 | * @calg: Cmonn algorithm data structure shared with scomp | |
36 | */ | |
37 | struct acomp_alg { | |
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); | |
43 | ||
44 | unsigned int reqsize; | |
45 | ||
46 | union { | |
47 | struct COMP_ALG_COMMON; | |
48 | struct comp_alg_common calg; | |
49 | }; | |
50 | }; | |
51 | ||
2ebda74f GC |
52 | /* |
53 | * Transform internal helpers. | |
54 | */ | |
55 | static inline void *acomp_request_ctx(struct acomp_req *req) | |
56 | { | |
57 | return req->__ctx; | |
58 | } | |
59 | ||
60 | static inline void *acomp_tfm_ctx(struct crypto_acomp *tfm) | |
61 | { | |
62 | return tfm->base.__crt_ctx; | |
63 | } | |
64 | ||
65 | static inline void acomp_request_complete(struct acomp_req *req, | |
66 | int err) | |
67 | { | |
4cc01c7f | 68 | crypto_request_complete(&req->base, err); |
2ebda74f GC |
69 | } |
70 | ||
1ab53a77 GC |
71 | static inline struct acomp_req *__acomp_request_alloc(struct crypto_acomp *tfm) |
72 | { | |
73 | struct acomp_req *req; | |
74 | ||
75 | req = kzalloc(sizeof(*req) + crypto_acomp_reqsize(tfm), GFP_KERNEL); | |
76 | if (likely(req)) | |
77 | acomp_request_set_tfm(req, tfm); | |
78 | return req; | |
79 | } | |
80 | ||
81 | static inline void __acomp_request_free(struct acomp_req *req) | |
82 | { | |
453431a5 | 83 | kfree_sensitive(req); |
1ab53a77 GC |
84 | } |
85 | ||
2ebda74f GC |
86 | /** |
87 | * crypto_register_acomp() -- Register asynchronous compression algorithm | |
88 | * | |
89 | * Function registers an implementation of an asynchronous | |
90 | * compression algorithm | |
91 | * | |
92 | * @alg: algorithm definition | |
93 | * | |
94 | * Return: zero on success; error code in case of error | |
95 | */ | |
96 | int crypto_register_acomp(struct acomp_alg *alg); | |
97 | ||
98 | /** | |
99 | * crypto_unregister_acomp() -- Unregister asynchronous compression algorithm | |
100 | * | |
101 | * Function unregisters an implementation of an asynchronous | |
102 | * compression algorithm | |
103 | * | |
104 | * @alg: algorithm definition | |
2ebda74f | 105 | */ |
c6d633a9 | 106 | void crypto_unregister_acomp(struct acomp_alg *alg); |
2ebda74f | 107 | |
3ce5bc72 GC |
108 | int crypto_register_acomps(struct acomp_alg *algs, int count); |
109 | void crypto_unregister_acomps(struct acomp_alg *algs, int count); | |
110 | ||
2ebda74f | 111 | #endif |