1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Synchronous Compression operations
5 * Copyright 2015 LG Electronics Inc.
6 * Copyright (c) 2016, Intel Corporation
7 * Author: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
9 #ifndef _CRYPTO_SCOMP_INT_H
10 #define _CRYPTO_SCOMP_INT_H
12 #include <crypto/acompress.h>
13 #include <crypto/algapi.h>
15 #define SCOMP_SCRATCH_SIZE 131072
20 struct crypto_tfm base;
24 * struct scomp_alg - synchronous compression algorithm
26 * @alloc_ctx: Function allocates algorithm specific context
27 * @free_ctx: Function frees context allocated with alloc_ctx
28 * @compress: Function performs a compress operation
29 * @decompress: Function performs a de-compress operation
30 * @stat: Statistics for compress algorithm
31 * @base: Common crypto API algorithm data structure
32 * @calg: Cmonn algorithm data structure shared with acomp
35 void *(*alloc_ctx)(struct crypto_scomp *tfm);
36 void (*free_ctx)(struct crypto_scomp *tfm, void *ctx);
37 int (*compress)(struct crypto_scomp *tfm, const u8 *src,
38 unsigned int slen, u8 *dst, unsigned int *dlen,
40 int (*decompress)(struct crypto_scomp *tfm, const u8 *src,
41 unsigned int slen, u8 *dst, unsigned int *dlen,
45 struct COMP_ALG_COMMON;
46 struct comp_alg_common calg;
50 static inline struct scomp_alg *__crypto_scomp_alg(struct crypto_alg *alg)
52 return container_of(alg, struct scomp_alg, base);
55 static inline struct crypto_scomp *__crypto_scomp_tfm(struct crypto_tfm *tfm)
57 return container_of(tfm, struct crypto_scomp, base);
60 static inline struct crypto_tfm *crypto_scomp_tfm(struct crypto_scomp *tfm)
65 static inline void crypto_free_scomp(struct crypto_scomp *tfm)
67 crypto_destroy_tfm(tfm, crypto_scomp_tfm(tfm));
70 static inline struct scomp_alg *crypto_scomp_alg(struct crypto_scomp *tfm)
72 return __crypto_scomp_alg(crypto_scomp_tfm(tfm)->__crt_alg);
75 static inline void *crypto_scomp_alloc_ctx(struct crypto_scomp *tfm)
77 return crypto_scomp_alg(tfm)->alloc_ctx(tfm);
80 static inline void crypto_scomp_free_ctx(struct crypto_scomp *tfm,
83 return crypto_scomp_alg(tfm)->free_ctx(tfm, ctx);
86 static inline int crypto_scomp_compress(struct crypto_scomp *tfm,
87 const u8 *src, unsigned int slen,
88 u8 *dst, unsigned int *dlen, void *ctx)
90 return crypto_scomp_alg(tfm)->compress(tfm, src, slen, dst, dlen, ctx);
93 static inline int crypto_scomp_decompress(struct crypto_scomp *tfm,
94 const u8 *src, unsigned int slen,
95 u8 *dst, unsigned int *dlen,
98 return crypto_scomp_alg(tfm)->decompress(tfm, src, slen, dst, dlen,
103 * crypto_register_scomp() -- Register synchronous compression algorithm
105 * Function registers an implementation of a synchronous
106 * compression algorithm
108 * @alg: algorithm definition
110 * Return: zero on success; error code in case of error
112 int crypto_register_scomp(struct scomp_alg *alg);
115 * crypto_unregister_scomp() -- Unregister synchronous compression algorithm
117 * Function unregisters an implementation of a synchronous
118 * compression algorithm
120 * @alg: algorithm definition
122 void crypto_unregister_scomp(struct scomp_alg *alg);
124 int crypto_register_scomps(struct scomp_alg *algs, int count);
125 void crypto_unregister_scomps(struct scomp_alg *algs, int count);