1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* 3 * Synchronous Compression operations 4 * 5 * Copyright 2015 LG Electronics Inc. 6 * Copyright (c) 2016, Intel Corporation 7 * Author: Giovanni Cabiddu <giovanni.cabiddu@intel.com> 8 */ 9 #ifndef _CRYPTO_SCOMP_INT_H 10 #define _CRYPTO_SCOMP_INT_H 11 12 #include <crypto/internal/acompress.h> 13 14 struct crypto_scomp { 15 struct crypto_tfm base; 16 }; 17 18 /** 19 * struct scomp_alg - synchronous compression algorithm 20 * 21 * @compress: Function performs a compress operation 22 * @decompress: Function performs a de-compress operation 23 * @streams: Per-cpu memory for algorithm 24 * @calg: Cmonn algorithm data structure shared with acomp 25 * @COMP_ALG_COMMON: see struct comp_alg_common 26 */ 27 struct scomp_alg { 28 int (*compress)(struct crypto_scomp *tfm, const u8 *src, 29 unsigned int slen, u8 *dst, unsigned int *dlen, 30 void *ctx); 31 int (*decompress)(struct crypto_scomp *tfm, const u8 *src, 32 unsigned int slen, u8 *dst, unsigned int *dlen, 33 void *ctx); 34 35 struct crypto_acomp_streams streams; 36 37 union { 38 struct COMP_ALG_COMMON; 39 struct comp_alg_common calg; 40 }; 41 }; 42 43 static inline struct scomp_alg *__crypto_scomp_alg(struct crypto_alg *alg) 44 { 45 return container_of(alg, struct scomp_alg, base); 46 } 47 48 static inline struct crypto_scomp *__crypto_scomp_tfm(struct crypto_tfm *tfm) 49 { 50 return container_of(tfm, struct crypto_scomp, base); 51 } 52 53 static inline struct crypto_tfm *crypto_scomp_tfm(struct crypto_scomp *tfm) 54 { 55 return &tfm->base; 56 } 57 58 static inline void crypto_free_scomp(struct crypto_scomp *tfm) 59 { 60 crypto_destroy_tfm(tfm, crypto_scomp_tfm(tfm)); 61 } 62 63 static inline struct scomp_alg *crypto_scomp_alg(struct crypto_scomp *tfm) 64 { 65 return __crypto_scomp_alg(crypto_scomp_tfm(tfm)->__crt_alg); 66 } 67 68 static inline int crypto_scomp_compress(struct crypto_scomp *tfm, 69 const u8 *src, unsigned int slen, 70 u8 *dst, unsigned int *dlen, void *ctx) 71 { 72 return crypto_scomp_alg(tfm)->compress(tfm, src, slen, dst, dlen, ctx); 73 } 74 75 static inline int crypto_scomp_decompress(struct crypto_scomp *tfm, 76 const u8 *src, unsigned int slen, 77 u8 *dst, unsigned int *dlen, 78 void *ctx) 79 { 80 return crypto_scomp_alg(tfm)->decompress(tfm, src, slen, dst, dlen, 81 ctx); 82 } 83 84 /** 85 * crypto_register_scomp() -- Register synchronous compression algorithm 86 * 87 * Function registers an implementation of a synchronous 88 * compression algorithm 89 * 90 * @alg: algorithm definition 91 * 92 * Return: zero on success; error code in case of error 93 */ 94 int crypto_register_scomp(struct scomp_alg *alg); 95 96 /** 97 * crypto_unregister_scomp() -- Unregister synchronous compression algorithm 98 * 99 * Function unregisters an implementation of a synchronous 100 * compression algorithm 101 * 102 * @alg: algorithm definition 103 */ 104 void crypto_unregister_scomp(struct scomp_alg *alg); 105 106 int crypto_register_scomps(struct scomp_alg *algs, int count); 107 void crypto_unregister_scomps(struct scomp_alg *algs, int count); 108 109 #endif 110