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 */ 36 struct acomp_alg { 37 int (*compress)(struct acomp_req *req); 38 int (*decompress)(struct acomp_req *req); 39 void (*dst_free)(struct scatterlist *dst); 40 int (*init)(struct crypto_acomp *tfm); 41 void (*exit)(struct crypto_acomp *tfm); 42 43 unsigned int reqsize; 44 45 struct crypto_alg base; 46 }; 47 48 /* 49 * Transform internal helpers. 50 */ 51 static inline void *acomp_request_ctx(struct acomp_req *req) 52 { 53 return req->__ctx; 54 } 55 56 static inline void *acomp_tfm_ctx(struct crypto_acomp *tfm) 57 { 58 return tfm->base.__crt_ctx; 59 } 60 61 static inline void acomp_request_complete(struct acomp_req *req, 62 int err) 63 { 64 crypto_request_complete(&req->base, err); 65 } 66 67 static inline struct acomp_req *__acomp_request_alloc(struct crypto_acomp *tfm) 68 { 69 struct acomp_req *req; 70 71 req = kzalloc(sizeof(*req) + crypto_acomp_reqsize(tfm), GFP_KERNEL); 72 if (likely(req)) 73 acomp_request_set_tfm(req, tfm); 74 return req; 75 } 76 77 static inline void __acomp_request_free(struct acomp_req *req) 78 { 79 kfree_sensitive(req); 80 } 81 82 /** 83 * crypto_register_acomp() -- Register asynchronous compression algorithm 84 * 85 * Function registers an implementation of an asynchronous 86 * compression algorithm 87 * 88 * @alg: algorithm definition 89 * 90 * Return: zero on success; error code in case of error 91 */ 92 int crypto_register_acomp(struct acomp_alg *alg); 93 94 /** 95 * crypto_unregister_acomp() -- Unregister asynchronous compression algorithm 96 * 97 * Function unregisters an implementation of an asynchronous 98 * compression algorithm 99 * 100 * @alg: algorithm definition 101 */ 102 void crypto_unregister_acomp(struct acomp_alg *alg); 103 104 int crypto_register_acomps(struct acomp_alg *algs, int count); 105 void crypto_unregister_acomps(struct acomp_alg *algs, int count); 106 107 #endif 108