Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * Synchronous Compression operations
0004  *
0005  * Copyright 2015 LG Electronics Inc.
0006  * Copyright (c) 2016, Intel Corporation
0007  * Author: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
0008  */
0009 #ifndef _CRYPTO_SCOMP_INT_H
0010 #define _CRYPTO_SCOMP_INT_H
0011 #include <linux/crypto.h>
0012 
0013 #define SCOMP_SCRATCH_SIZE  131072
0014 
0015 struct crypto_scomp {
0016     struct crypto_tfm base;
0017 };
0018 
0019 /**
0020  * struct scomp_alg - synchronous compression algorithm
0021  *
0022  * @alloc_ctx:  Function allocates algorithm specific context
0023  * @free_ctx:   Function frees context allocated with alloc_ctx
0024  * @compress:   Function performs a compress operation
0025  * @decompress: Function performs a de-compress operation
0026  * @base:   Common crypto API algorithm data structure
0027  */
0028 struct scomp_alg {
0029     void *(*alloc_ctx)(struct crypto_scomp *tfm);
0030     void (*free_ctx)(struct crypto_scomp *tfm, void *ctx);
0031     int (*compress)(struct crypto_scomp *tfm, const u8 *src,
0032             unsigned int slen, u8 *dst, unsigned int *dlen,
0033             void *ctx);
0034     int (*decompress)(struct crypto_scomp *tfm, const u8 *src,
0035               unsigned int slen, u8 *dst, unsigned int *dlen,
0036               void *ctx);
0037     struct crypto_alg base;
0038 };
0039 
0040 static inline struct scomp_alg *__crypto_scomp_alg(struct crypto_alg *alg)
0041 {
0042     return container_of(alg, struct scomp_alg, base);
0043 }
0044 
0045 static inline struct crypto_scomp *__crypto_scomp_tfm(struct crypto_tfm *tfm)
0046 {
0047     return container_of(tfm, struct crypto_scomp, base);
0048 }
0049 
0050 static inline struct crypto_tfm *crypto_scomp_tfm(struct crypto_scomp *tfm)
0051 {
0052     return &tfm->base;
0053 }
0054 
0055 static inline void crypto_free_scomp(struct crypto_scomp *tfm)
0056 {
0057     crypto_destroy_tfm(tfm, crypto_scomp_tfm(tfm));
0058 }
0059 
0060 static inline struct scomp_alg *crypto_scomp_alg(struct crypto_scomp *tfm)
0061 {
0062     return __crypto_scomp_alg(crypto_scomp_tfm(tfm)->__crt_alg);
0063 }
0064 
0065 static inline void *crypto_scomp_alloc_ctx(struct crypto_scomp *tfm)
0066 {
0067     return crypto_scomp_alg(tfm)->alloc_ctx(tfm);
0068 }
0069 
0070 static inline void crypto_scomp_free_ctx(struct crypto_scomp *tfm,
0071                      void *ctx)
0072 {
0073     return crypto_scomp_alg(tfm)->free_ctx(tfm, ctx);
0074 }
0075 
0076 static inline int crypto_scomp_compress(struct crypto_scomp *tfm,
0077                     const u8 *src, unsigned int slen,
0078                     u8 *dst, unsigned int *dlen, void *ctx)
0079 {
0080     return crypto_scomp_alg(tfm)->compress(tfm, src, slen, dst, dlen, ctx);
0081 }
0082 
0083 static inline int crypto_scomp_decompress(struct crypto_scomp *tfm,
0084                       const u8 *src, unsigned int slen,
0085                       u8 *dst, unsigned int *dlen,
0086                       void *ctx)
0087 {
0088     return crypto_scomp_alg(tfm)->decompress(tfm, src, slen, dst, dlen,
0089                          ctx);
0090 }
0091 
0092 int crypto_init_scomp_ops_async(struct crypto_tfm *tfm);
0093 struct acomp_req *crypto_acomp_scomp_alloc_ctx(struct acomp_req *req);
0094 void crypto_acomp_scomp_free_ctx(struct acomp_req *req);
0095 
0096 /**
0097  * crypto_register_scomp() -- Register synchronous compression algorithm
0098  *
0099  * Function registers an implementation of a synchronous
0100  * compression algorithm
0101  *
0102  * @alg:    algorithm definition
0103  *
0104  * Return: zero on success; error code in case of error
0105  */
0106 int crypto_register_scomp(struct scomp_alg *alg);
0107 
0108 /**
0109  * crypto_unregister_scomp() -- Unregister synchronous compression algorithm
0110  *
0111  * Function unregisters an implementation of a synchronous
0112  * compression algorithm
0113  *
0114  * @alg:    algorithm definition
0115  */
0116 void crypto_unregister_scomp(struct scomp_alg *alg);
0117 
0118 int crypto_register_scomps(struct scomp_alg *algs, int count);
0119 void crypto_unregister_scomps(struct scomp_alg *algs, int count);
0120 
0121 #endif