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/acompress.h> 13 #include <crypto/algapi.h> 14 15 struct acomp_req; 16 17 struct crypto_scomp { 18 struct crypto_tfm base; 19 }; 20 21 /** 22 * struct scomp_alg - synchronous compression algorithm 23 * 24 * @alloc_ctx: Function allocates algorithm specific context 25 * @free_ctx: Function frees context allocated with alloc_ctx 26 * @compress: Function performs a compress operation 27 * @decompress: Function performs a de-compress operation 28 * @base: Common crypto API algorithm data structure 29 * @stream: Per-cpu memory for algorithm 30 * @calg: Cmonn algorithm data structure shared with acomp 31 */ 32 struct scomp_alg { 33 void *(*alloc_ctx)(void); 34 void (*free_ctx)(void *ctx); 35 int (*compress)(struct crypto_scomp *tfm, const u8 *src, 36 unsigned int slen, u8 *dst, unsigned int *dlen, 37 void *ctx); 38 int (*decompress)(struct crypto_scomp *tfm, const u8 *src, 39 unsigned int slen, u8 *dst, unsigned int *dlen, 40 void *ctx); 41 42 union { 43 struct COMP_ALG_COMMON; 44 struct comp_alg_common calg; 45 }; 46 }; 47 48 static inline struct scomp_alg *__crypto_scomp_alg(struct crypto_alg *alg) 49 { 50 return container_of(alg, struct scomp_alg, base); 51 } 52 53 static inline struct crypto_scomp *__crypto_scomp_tfm(struct crypto_tfm *tfm) 54 { 55 return container_of(tfm, struct crypto_scomp, base); 56 } 57 58 static inline struct crypto_tfm *crypto_scomp_tfm(struct crypto_scomp *tfm) 59 { 60 return &tfm->base; 61 } 62 63 static inline void crypto_free_scomp(struct crypto_scomp *tfm) 64 { 65 crypto_destroy_tfm(tfm, crypto_scomp_tfm(tfm)); 66 } 67 68 static inline struct scomp_alg *crypto_scomp_alg(struct crypto_scomp *tfm) 69 { 70 return __crypto_scomp_alg(crypto_scomp_tfm(tfm)->__crt_alg); 71 } 72 73 static inline int crypto_scomp_compress(struct crypto_scomp *tfm, 74 const u8 *src, unsigned int slen, 75 u8 *dst, unsigned int *dlen, void *ctx) 76 { 77 return crypto_scomp_alg(tfm)->compress(tfm, src, slen, dst, dlen, ctx); 78 } 79 80 static inline int crypto_scomp_decompress(struct crypto_scomp *tfm, 81 const u8 *src, unsigned int slen, 82 u8 *dst, unsigned int *dlen, 83 void *ctx) 84 { 85 return crypto_scomp_alg(tfm)->decompress(tfm, src, slen, dst, dlen, 86 ctx); 87 } 88 89 /** 90 * crypto_register_scomp() -- Register synchronous compression algorithm 91 * 92 * Function registers an implementation of a synchronous 93 * compression algorithm 94 * 95 * @alg: algorithm definition 96 * 97 * Return: zero on success; error code in case of error 98 */ 99 int crypto_register_scomp(struct scomp_alg *alg); 100 101 /** 102 * crypto_unregister_scomp() -- Unregister synchronous compression algorithm 103 * 104 * Function unregisters an implementation of a synchronous 105 * compression algorithm 106 * 107 * @alg: algorithm definition 108 */ 109 void crypto_unregister_scomp(struct scomp_alg *alg); 110 111 int crypto_register_scomps(struct scomp_alg *algs, int count); 112 void crypto_unregister_scomps(struct scomp_alg *algs, int count); 113 114 #endif 115