Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v6.16-rc7 99 lines 2.0 kB view raw
1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * Cryptographic API. 4 */ 5 6#include <crypto/internal/scompress.h> 7#include <linux/init.h> 8#include <linux/lzo.h> 9#include <linux/module.h> 10#include <linux/slab.h> 11 12static void *lzo_alloc_ctx(void) 13{ 14 void *ctx; 15 16 ctx = kvmalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL); 17 if (!ctx) 18 return ERR_PTR(-ENOMEM); 19 20 return ctx; 21} 22 23static void lzo_free_ctx(void *ctx) 24{ 25 kvfree(ctx); 26} 27 28static int __lzo_compress(const u8 *src, unsigned int slen, 29 u8 *dst, unsigned int *dlen, void *ctx) 30{ 31 size_t tmp_len = *dlen; /* size_t(ulong) <-> uint on 64 bit */ 32 int err; 33 34 err = lzo1x_1_compress_safe(src, slen, dst, &tmp_len, ctx); 35 36 if (err != LZO_E_OK) 37 return -EINVAL; 38 39 *dlen = tmp_len; 40 return 0; 41} 42 43static int lzo_scompress(struct crypto_scomp *tfm, const u8 *src, 44 unsigned int slen, u8 *dst, unsigned int *dlen, 45 void *ctx) 46{ 47 return __lzo_compress(src, slen, dst, dlen, ctx); 48} 49 50static int __lzo_decompress(const u8 *src, unsigned int slen, 51 u8 *dst, unsigned int *dlen) 52{ 53 int err; 54 size_t tmp_len = *dlen; /* size_t(ulong) <-> uint on 64 bit */ 55 56 err = lzo1x_decompress_safe(src, slen, dst, &tmp_len); 57 58 if (err != LZO_E_OK) 59 return -EINVAL; 60 61 *dlen = tmp_len; 62 return 0; 63} 64 65static int lzo_sdecompress(struct crypto_scomp *tfm, const u8 *src, 66 unsigned int slen, u8 *dst, unsigned int *dlen, 67 void *ctx) 68{ 69 return __lzo_decompress(src, slen, dst, dlen); 70} 71 72static struct scomp_alg scomp = { 73 .alloc_ctx = lzo_alloc_ctx, 74 .free_ctx = lzo_free_ctx, 75 .compress = lzo_scompress, 76 .decompress = lzo_sdecompress, 77 .base = { 78 .cra_name = "lzo", 79 .cra_driver_name = "lzo-scomp", 80 .cra_module = THIS_MODULE, 81 } 82}; 83 84static int __init lzo_mod_init(void) 85{ 86 return crypto_register_scomp(&scomp); 87} 88 89static void __exit lzo_mod_fini(void) 90{ 91 crypto_unregister_scomp(&scomp); 92} 93 94module_init(lzo_mod_init); 95module_exit(lzo_mod_fini); 96 97MODULE_LICENSE("GPL"); 98MODULE_DESCRIPTION("LZO Compression Algorithm"); 99MODULE_ALIAS_CRYPTO("lzo");