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