at master 108 lines 2.9 kB view raw
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 14struct 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 */ 26struct scomp_alg { 27 int (*compress)(struct crypto_scomp *tfm, const u8 *src, 28 unsigned int slen, u8 *dst, unsigned int *dlen, 29 void *ctx); 30 int (*decompress)(struct crypto_scomp *tfm, const u8 *src, 31 unsigned int slen, u8 *dst, unsigned int *dlen, 32 void *ctx); 33 34 struct crypto_acomp_streams streams; 35 36 union { 37 struct COMP_ALG_COMMON; 38 struct comp_alg_common calg; 39 }; 40}; 41 42static inline struct scomp_alg *__crypto_scomp_alg(struct crypto_alg *alg) 43{ 44 return container_of(alg, struct scomp_alg, base); 45} 46 47static inline struct crypto_scomp *__crypto_scomp_tfm(struct crypto_tfm *tfm) 48{ 49 return container_of(tfm, struct crypto_scomp, base); 50} 51 52static inline struct crypto_tfm *crypto_scomp_tfm(struct crypto_scomp *tfm) 53{ 54 return &tfm->base; 55} 56 57static inline void crypto_free_scomp(struct crypto_scomp *tfm) 58{ 59 crypto_destroy_tfm(tfm, crypto_scomp_tfm(tfm)); 60} 61 62static inline struct scomp_alg *crypto_scomp_alg(struct crypto_scomp *tfm) 63{ 64 return __crypto_scomp_alg(crypto_scomp_tfm(tfm)->__crt_alg); 65} 66 67static inline int crypto_scomp_compress(struct crypto_scomp *tfm, 68 const u8 *src, unsigned int slen, 69 u8 *dst, unsigned int *dlen, void *ctx) 70{ 71 return crypto_scomp_alg(tfm)->compress(tfm, src, slen, dst, dlen, ctx); 72} 73 74static inline int crypto_scomp_decompress(struct crypto_scomp *tfm, 75 const u8 *src, unsigned int slen, 76 u8 *dst, unsigned int *dlen, 77 void *ctx) 78{ 79 return crypto_scomp_alg(tfm)->decompress(tfm, src, slen, dst, dlen, 80 ctx); 81} 82 83/** 84 * crypto_register_scomp() -- Register synchronous compression algorithm 85 * 86 * Function registers an implementation of a synchronous 87 * compression algorithm 88 * 89 * @alg: algorithm definition 90 * 91 * Return: zero on success; error code in case of error 92 */ 93int crypto_register_scomp(struct scomp_alg *alg); 94 95/** 96 * crypto_unregister_scomp() -- Unregister synchronous compression algorithm 97 * 98 * Function unregisters an implementation of a synchronous 99 * compression algorithm 100 * 101 * @alg: algorithm definition 102 */ 103void crypto_unregister_scomp(struct scomp_alg *alg); 104 105int crypto_register_scomps(struct scomp_alg *algs, int count); 106void crypto_unregister_scomps(struct scomp_alg *algs, int count); 107 108#endif