~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/crypto/lz4.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /crypto/lz4.c (Version linux-6.11.5) and /crypto/lz4.c (Version linux-4.20.17)


  1 // SPDX-License-Identifier: GPL-2.0-only       << 
  2 /*                                                  1 /*
  3  * Cryptographic API.                               2  * Cryptographic API.
  4  *                                                  3  *
  5  * Copyright (c) 2013 Chanho Min <chanho.min@l      4  * Copyright (c) 2013 Chanho Min <chanho.min@lge.com>
                                                   >>   5  *
                                                   >>   6  * This program is free software; you can redistribute it and/or modify it
                                                   >>   7  * under the terms of the GNU General Public License version 2 as published by
                                                   >>   8  * the Free Software Foundation.
                                                   >>   9  *
                                                   >>  10  * This program is distributed in the hope that it will be useful, but WITHOUT
                                                   >>  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
                                                   >>  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
                                                   >>  13  * more details.
                                                   >>  14  *
                                                   >>  15  * You should have received a copy of the GNU General Public License along with
                                                   >>  16  * this program; if not, write to the Free Software Foundation, Inc., 51
                                                   >>  17  * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
                                                   >>  18  *
  6  */                                                19  */
  7                                                    20 
  8 #include <linux/init.h>                            21 #include <linux/init.h>
  9 #include <linux/module.h>                          22 #include <linux/module.h>
 10 #include <linux/crypto.h>                          23 #include <linux/crypto.h>
 11 #include <linux/vmalloc.h>                         24 #include <linux/vmalloc.h>
 12 #include <linux/lz4.h>                             25 #include <linux/lz4.h>
 13 #include <crypto/internal/scompress.h>             26 #include <crypto/internal/scompress.h>
 14                                                    27 
 15 struct lz4_ctx {                                   28 struct lz4_ctx {
 16         void *lz4_comp_mem;                        29         void *lz4_comp_mem;
 17 };                                                 30 };
 18                                                    31 
 19 static void *lz4_alloc_ctx(struct crypto_scomp     32 static void *lz4_alloc_ctx(struct crypto_scomp *tfm)
 20 {                                                  33 {
 21         void *ctx;                                 34         void *ctx;
 22                                                    35 
 23         ctx = vmalloc(LZ4_MEM_COMPRESS);           36         ctx = vmalloc(LZ4_MEM_COMPRESS);
 24         if (!ctx)                                  37         if (!ctx)
 25                 return ERR_PTR(-ENOMEM);           38                 return ERR_PTR(-ENOMEM);
 26                                                    39 
 27         return ctx;                                40         return ctx;
 28 }                                                  41 }
 29                                                    42 
 30 static int lz4_init(struct crypto_tfm *tfm)        43 static int lz4_init(struct crypto_tfm *tfm)
 31 {                                                  44 {
 32         struct lz4_ctx *ctx = crypto_tfm_ctx(t     45         struct lz4_ctx *ctx = crypto_tfm_ctx(tfm);
 33                                                    46 
 34         ctx->lz4_comp_mem = lz4_alloc_ctx(NULL     47         ctx->lz4_comp_mem = lz4_alloc_ctx(NULL);
 35         if (IS_ERR(ctx->lz4_comp_mem))             48         if (IS_ERR(ctx->lz4_comp_mem))
 36                 return -ENOMEM;                    49                 return -ENOMEM;
 37                                                    50 
 38         return 0;                                  51         return 0;
 39 }                                                  52 }
 40                                                    53 
 41 static void lz4_free_ctx(struct crypto_scomp *     54 static void lz4_free_ctx(struct crypto_scomp *tfm, void *ctx)
 42 {                                                  55 {
 43         vfree(ctx);                                56         vfree(ctx);
 44 }                                                  57 }
 45                                                    58 
 46 static void lz4_exit(struct crypto_tfm *tfm)       59 static void lz4_exit(struct crypto_tfm *tfm)
 47 {                                                  60 {
 48         struct lz4_ctx *ctx = crypto_tfm_ctx(t     61         struct lz4_ctx *ctx = crypto_tfm_ctx(tfm);
 49                                                    62 
 50         lz4_free_ctx(NULL, ctx->lz4_comp_mem);     63         lz4_free_ctx(NULL, ctx->lz4_comp_mem);
 51 }                                                  64 }
 52                                                    65 
 53 static int __lz4_compress_crypto(const u8 *src     66 static int __lz4_compress_crypto(const u8 *src, unsigned int slen,
 54                                  u8 *dst, unsi     67                                  u8 *dst, unsigned int *dlen, void *ctx)
 55 {                                                  68 {
 56         int out_len = LZ4_compress_default(src     69         int out_len = LZ4_compress_default(src, dst,
 57                 slen, *dlen, ctx);                 70                 slen, *dlen, ctx);
 58                                                    71 
 59         if (!out_len)                              72         if (!out_len)
 60                 return -EINVAL;                    73                 return -EINVAL;
 61                                                    74 
 62         *dlen = out_len;                           75         *dlen = out_len;
 63         return 0;                                  76         return 0;
 64 }                                                  77 }
 65                                                    78 
 66 static int lz4_scompress(struct crypto_scomp *     79 static int lz4_scompress(struct crypto_scomp *tfm, const u8 *src,
 67                          unsigned int slen, u8     80                          unsigned int slen, u8 *dst, unsigned int *dlen,
 68                          void *ctx)                81                          void *ctx)
 69 {                                                  82 {
 70         return __lz4_compress_crypto(src, slen     83         return __lz4_compress_crypto(src, slen, dst, dlen, ctx);
 71 }                                                  84 }
 72                                                    85 
 73 static int lz4_compress_crypto(struct crypto_t     86 static int lz4_compress_crypto(struct crypto_tfm *tfm, const u8 *src,
 74                                unsigned int sl     87                                unsigned int slen, u8 *dst, unsigned int *dlen)
 75 {                                                  88 {
 76         struct lz4_ctx *ctx = crypto_tfm_ctx(t     89         struct lz4_ctx *ctx = crypto_tfm_ctx(tfm);
 77                                                    90 
 78         return __lz4_compress_crypto(src, slen     91         return __lz4_compress_crypto(src, slen, dst, dlen, ctx->lz4_comp_mem);
 79 }                                                  92 }
 80                                                    93 
 81 static int __lz4_decompress_crypto(const u8 *s     94 static int __lz4_decompress_crypto(const u8 *src, unsigned int slen,
 82                                    u8 *dst, un     95                                    u8 *dst, unsigned int *dlen, void *ctx)
 83 {                                                  96 {
 84         int out_len = LZ4_decompress_safe(src,     97         int out_len = LZ4_decompress_safe(src, dst, slen, *dlen);
 85                                                    98 
 86         if (out_len < 0)                           99         if (out_len < 0)
 87                 return -EINVAL;                   100                 return -EINVAL;
 88                                                   101 
 89         *dlen = out_len;                          102         *dlen = out_len;
 90         return 0;                                 103         return 0;
 91 }                                                 104 }
 92                                                   105 
 93 static int lz4_sdecompress(struct crypto_scomp    106 static int lz4_sdecompress(struct crypto_scomp *tfm, const u8 *src,
 94                            unsigned int slen,     107                            unsigned int slen, u8 *dst, unsigned int *dlen,
 95                            void *ctx)             108                            void *ctx)
 96 {                                                 109 {
 97         return __lz4_decompress_crypto(src, sl    110         return __lz4_decompress_crypto(src, slen, dst, dlen, NULL);
 98 }                                                 111 }
 99                                                   112 
100 static int lz4_decompress_crypto(struct crypto    113 static int lz4_decompress_crypto(struct crypto_tfm *tfm, const u8 *src,
101                                  unsigned int     114                                  unsigned int slen, u8 *dst,
102                                  unsigned int     115                                  unsigned int *dlen)
103 {                                                 116 {
104         return __lz4_decompress_crypto(src, sl    117         return __lz4_decompress_crypto(src, slen, dst, dlen, NULL);
105 }                                                 118 }
106                                                   119 
107 static struct crypto_alg alg_lz4 = {              120 static struct crypto_alg alg_lz4 = {
108         .cra_name               = "lz4",          121         .cra_name               = "lz4",
109         .cra_driver_name        = "lz4-generic << 
110         .cra_flags              = CRYPTO_ALG_T    122         .cra_flags              = CRYPTO_ALG_TYPE_COMPRESS,
111         .cra_ctxsize            = sizeof(struc    123         .cra_ctxsize            = sizeof(struct lz4_ctx),
112         .cra_module             = THIS_MODULE,    124         .cra_module             = THIS_MODULE,
                                                   >> 125         .cra_list               = LIST_HEAD_INIT(alg_lz4.cra_list),
113         .cra_init               = lz4_init,       126         .cra_init               = lz4_init,
114         .cra_exit               = lz4_exit,       127         .cra_exit               = lz4_exit,
115         .cra_u                  = { .compress     128         .cra_u                  = { .compress = {
116         .coa_compress           = lz4_compress    129         .coa_compress           = lz4_compress_crypto,
117         .coa_decompress         = lz4_decompre    130         .coa_decompress         = lz4_decompress_crypto } }
118 };                                                131 };
119                                                   132 
120 static struct scomp_alg scomp = {                 133 static struct scomp_alg scomp = {
121         .alloc_ctx              = lz4_alloc_ct    134         .alloc_ctx              = lz4_alloc_ctx,
122         .free_ctx               = lz4_free_ctx    135         .free_ctx               = lz4_free_ctx,
123         .compress               = lz4_scompres    136         .compress               = lz4_scompress,
124         .decompress             = lz4_sdecompr    137         .decompress             = lz4_sdecompress,
125         .base                   = {               138         .base                   = {
126                 .cra_name       = "lz4",          139                 .cra_name       = "lz4",
127                 .cra_driver_name = "lz4-scomp"    140                 .cra_driver_name = "lz4-scomp",
128                 .cra_module      = THIS_MODULE    141                 .cra_module      = THIS_MODULE,
129         }                                         142         }
130 };                                                143 };
131                                                   144 
132 static int __init lz4_mod_init(void)              145 static int __init lz4_mod_init(void)
133 {                                                 146 {
134         int ret;                                  147         int ret;
135                                                   148 
136         ret = crypto_register_alg(&alg_lz4);      149         ret = crypto_register_alg(&alg_lz4);
137         if (ret)                                  150         if (ret)
138                 return ret;                       151                 return ret;
139                                                   152 
140         ret = crypto_register_scomp(&scomp);      153         ret = crypto_register_scomp(&scomp);
141         if (ret) {                                154         if (ret) {
142                 crypto_unregister_alg(&alg_lz4    155                 crypto_unregister_alg(&alg_lz4);
143                 return ret;                       156                 return ret;
144         }                                         157         }
145                                                   158 
146         return ret;                               159         return ret;
147 }                                                 160 }
148                                                   161 
149 static void __exit lz4_mod_fini(void)             162 static void __exit lz4_mod_fini(void)
150 {                                                 163 {
151         crypto_unregister_alg(&alg_lz4);          164         crypto_unregister_alg(&alg_lz4);
152         crypto_unregister_scomp(&scomp);          165         crypto_unregister_scomp(&scomp);
153 }                                                 166 }
154                                                   167 
155 subsys_initcall(lz4_mod_init);                 !! 168 module_init(lz4_mod_init);
156 module_exit(lz4_mod_fini);                        169 module_exit(lz4_mod_fini);
157                                                   170 
158 MODULE_LICENSE("GPL");                            171 MODULE_LICENSE("GPL");
159 MODULE_DESCRIPTION("LZ4 Compression Algorithm"    172 MODULE_DESCRIPTION("LZ4 Compression Algorithm");
160 MODULE_ALIAS_CRYPTO("lz4");                       173 MODULE_ALIAS_CRYPTO("lz4");
161                                                   174 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php