Loading...
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 */
18static inline void *acomp_request_ctx(struct acomp_req *req)
19{
20 return req->__ctx;
21}
22
23static inline void *acomp_tfm_ctx(struct crypto_acomp *tfm)
24{
25 return tfm->base.__crt_ctx;
26}
27
28static inline void acomp_request_complete(struct acomp_req *req,
29 int err)
30{
31 req->base.complete(&req->base, err);
32}
33
34static inline const char *acomp_alg_name(struct crypto_acomp *tfm)
35{
36 return crypto_acomp_tfm(tfm)->__crt_alg->cra_name;
37}
38
39static 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
49static 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 */
64int 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 */
74void crypto_unregister_acomp(struct acomp_alg *alg);
75
76int crypto_register_acomps(struct acomp_alg *algs, int count);
77void crypto_unregister_acomps(struct acomp_alg *algs, int count);
78
79#endif
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 * 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
34 * @base: Common crypto API algorithm data structure
35 * @calg: Cmonn algorithm data structure shared with scomp
36 */
37struct 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
52/*
53 * Transform internal helpers.
54 */
55static inline void *acomp_request_ctx(struct acomp_req *req)
56{
57 return req->__ctx;
58}
59
60static inline void *acomp_tfm_ctx(struct crypto_acomp *tfm)
61{
62 return tfm->base.__crt_ctx;
63}
64
65static inline void acomp_request_complete(struct acomp_req *req,
66 int err)
67{
68 crypto_request_complete(&req->base, err);
69}
70
71static inline struct acomp_req *__acomp_request_alloc_noprof(struct crypto_acomp *tfm)
72{
73 struct acomp_req *req;
74
75 req = kzalloc_noprof(sizeof(*req) + crypto_acomp_reqsize(tfm), GFP_KERNEL);
76 if (likely(req))
77 acomp_request_set_tfm(req, tfm);
78 return req;
79}
80#define __acomp_request_alloc(...) alloc_hooks(__acomp_request_alloc_noprof(__VA_ARGS__))
81
82static inline void __acomp_request_free(struct acomp_req *req)
83{
84 kfree_sensitive(req);
85}
86
87/**
88 * crypto_register_acomp() -- Register asynchronous compression algorithm
89 *
90 * Function registers an implementation of an asynchronous
91 * compression algorithm
92 *
93 * @alg: algorithm definition
94 *
95 * Return: zero on success; error code in case of error
96 */
97int crypto_register_acomp(struct acomp_alg *alg);
98
99/**
100 * crypto_unregister_acomp() -- Unregister asynchronous compression algorithm
101 *
102 * Function unregisters an implementation of an asynchronous
103 * compression algorithm
104 *
105 * @alg: algorithm definition
106 */
107void crypto_unregister_acomp(struct acomp_alg *alg);
108
109int crypto_register_acomps(struct acomp_alg *algs, int count);
110void crypto_unregister_acomps(struct acomp_alg *algs, int count);
111
112#endif