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

TOMOYO Linux Cross Reference
Linux/crypto/lzo.c

Version: ~ [ linux-5.15-rc5 ] ~ [ linux-5.14.11 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.72 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.152 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.210 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.250 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.286 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.288 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ 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.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Cryptographic API.
  3  *
  4  * This program is free software; you can redistribute it and/or modify it
  5  * under the terms of the GNU General Public License version 2 as published by
  6  * the Free Software Foundation.
  7  *
  8  * This program is distributed in the hope that it will be useful, but WITHOUT
  9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 11  * more details.
 12  *
 13  * You should have received a copy of the GNU General Public License along with
 14  * this program; if not, write to the Free Software Foundation, Inc., 51
 15  * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 16  *
 17  */
 18 
 19 #include <linux/init.h>
 20 #include <linux/module.h>
 21 #include <linux/crypto.h>
 22 #include <linux/vmalloc.h>
 23 #include <linux/mm.h>
 24 #include <linux/lzo.h>
 25 
 26 struct lzo_ctx {
 27         void *lzo_comp_mem;
 28 };
 29 
 30 static int lzo_init(struct crypto_tfm *tfm)
 31 {
 32         struct lzo_ctx *ctx = crypto_tfm_ctx(tfm);
 33 
 34         ctx->lzo_comp_mem = kmalloc(LZO1X_MEM_COMPRESS,
 35                                     GFP_KERNEL | __GFP_NOWARN | __GFP_REPEAT);
 36         if (!ctx->lzo_comp_mem)
 37                 ctx->lzo_comp_mem = vmalloc(LZO1X_MEM_COMPRESS);
 38         if (!ctx->lzo_comp_mem)
 39                 return -ENOMEM;
 40 
 41         return 0;
 42 }
 43 
 44 static void lzo_exit(struct crypto_tfm *tfm)
 45 {
 46         struct lzo_ctx *ctx = crypto_tfm_ctx(tfm);
 47 
 48         kvfree(ctx->lzo_comp_mem);
 49 }
 50 
 51 static int lzo_compress(struct crypto_tfm *tfm, const u8 *src,
 52                             unsigned int slen, u8 *dst, unsigned int *dlen)
 53 {
 54         struct lzo_ctx *ctx = crypto_tfm_ctx(tfm);
 55         size_t tmp_len = *dlen; /* size_t(ulong) <-> uint on 64 bit */
 56         int err;
 57 
 58         err = lzo1x_1_compress(src, slen, dst, &tmp_len, ctx->lzo_comp_mem);
 59 
 60         if (err != LZO_E_OK)
 61                 return -EINVAL;
 62 
 63         *dlen = tmp_len;
 64         return 0;
 65 }
 66 
 67 static int lzo_decompress(struct crypto_tfm *tfm, const u8 *src,
 68                               unsigned int slen, u8 *dst, unsigned int *dlen)
 69 {
 70         int err;
 71         size_t tmp_len = *dlen; /* size_t(ulong) <-> uint on 64 bit */
 72 
 73         err = lzo1x_decompress_safe(src, slen, dst, &tmp_len);
 74 
 75         if (err != LZO_E_OK)
 76                 return -EINVAL;
 77 
 78         *dlen = tmp_len;
 79         return 0;
 80 
 81 }
 82 
 83 static struct crypto_alg alg = {
 84         .cra_name               = "lzo",
 85         .cra_flags              = CRYPTO_ALG_TYPE_COMPRESS,
 86         .cra_ctxsize            = sizeof(struct lzo_ctx),
 87         .cra_module             = THIS_MODULE,
 88         .cra_init               = lzo_init,
 89         .cra_exit               = lzo_exit,
 90         .cra_u                  = { .compress = {
 91         .coa_compress           = lzo_compress,
 92         .coa_decompress         = lzo_decompress } }
 93 };
 94 
 95 static int __init lzo_mod_init(void)
 96 {
 97         return crypto_register_alg(&alg);
 98 }
 99 
100 static void __exit lzo_mod_fini(void)
101 {
102         crypto_unregister_alg(&alg);
103 }
104 
105 module_init(lzo_mod_init);
106 module_exit(lzo_mod_fini);
107 
108 MODULE_LICENSE("GPL");
109 MODULE_DESCRIPTION("LZO Compression Algorithm");
110 MODULE_ALIAS_CRYPTO("lzo");
111 

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp