Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Cryptographic API.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2017-present, Facebook, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/crypto.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/zstd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <crypto/internal/scompress.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define ZSTD_DEF_LEVEL	3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) struct zstd_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	ZSTD_CCtx *cctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	ZSTD_DCtx *dctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	void *cwksp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	void *dwksp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static ZSTD_parameters zstd_params(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	return ZSTD_getParams(ZSTD_DEF_LEVEL, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static int zstd_comp_init(struct zstd_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	const ZSTD_parameters params = zstd_params();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	const size_t wksp_size = ZSTD_CCtxWorkspaceBound(params.cParams);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	ctx->cwksp = vzalloc(wksp_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	if (!ctx->cwksp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	ctx->cctx = ZSTD_initCCtx(ctx->cwksp, wksp_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	if (!ctx->cctx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	vfree(ctx->cwksp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) static int zstd_decomp_init(struct zstd_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	const size_t wksp_size = ZSTD_DCtxWorkspaceBound();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	ctx->dwksp = vzalloc(wksp_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	if (!ctx->dwksp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	ctx->dctx = ZSTD_initDCtx(ctx->dwksp, wksp_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	if (!ctx->dctx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	vfree(ctx->dwksp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) static void zstd_comp_exit(struct zstd_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	vfree(ctx->cwksp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	ctx->cwksp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	ctx->cctx = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static void zstd_decomp_exit(struct zstd_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	vfree(ctx->dwksp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	ctx->dwksp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	ctx->dctx = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) static int __zstd_init(void *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	ret = zstd_comp_init(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	ret = zstd_decomp_init(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		zstd_comp_exit(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static void *zstd_alloc_ctx(struct crypto_scomp *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	struct zstd_ctx *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	if (!ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	ret = __zstd_init(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		kfree(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	return ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static int zstd_init(struct crypto_tfm *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	struct zstd_ctx *ctx = crypto_tfm_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	return __zstd_init(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static void __zstd_exit(void *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	zstd_comp_exit(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	zstd_decomp_exit(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static void zstd_free_ctx(struct crypto_scomp *tfm, void *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	__zstd_exit(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	kfree_sensitive(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static void zstd_exit(struct crypto_tfm *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	struct zstd_ctx *ctx = crypto_tfm_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	__zstd_exit(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static int __zstd_compress(const u8 *src, unsigned int slen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			   u8 *dst, unsigned int *dlen, void *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	size_t out_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	struct zstd_ctx *zctx = ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	const ZSTD_parameters params = zstd_params();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	out_len = ZSTD_compressCCtx(zctx->cctx, dst, *dlen, src, slen, params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	if (ZSTD_isError(out_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	*dlen = out_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static int zstd_compress(struct crypto_tfm *tfm, const u8 *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			 unsigned int slen, u8 *dst, unsigned int *dlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	struct zstd_ctx *ctx = crypto_tfm_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	return __zstd_compress(src, slen, dst, dlen, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) static int zstd_scompress(struct crypto_scomp *tfm, const u8 *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			  unsigned int slen, u8 *dst, unsigned int *dlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 			  void *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	return __zstd_compress(src, slen, dst, dlen, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static int __zstd_decompress(const u8 *src, unsigned int slen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 			     u8 *dst, unsigned int *dlen, void *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	size_t out_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	struct zstd_ctx *zctx = ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	out_len = ZSTD_decompressDCtx(zctx->dctx, dst, *dlen, src, slen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	if (ZSTD_isError(out_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	*dlen = out_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static int zstd_decompress(struct crypto_tfm *tfm, const u8 *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			   unsigned int slen, u8 *dst, unsigned int *dlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	struct zstd_ctx *ctx = crypto_tfm_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	return __zstd_decompress(src, slen, dst, dlen, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static int zstd_sdecompress(struct crypto_scomp *tfm, const u8 *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 			    unsigned int slen, u8 *dst, unsigned int *dlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			    void *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	return __zstd_decompress(src, slen, dst, dlen, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static struct crypto_alg alg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	.cra_name		= "zstd",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	.cra_driver_name	= "zstd-generic",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	.cra_flags		= CRYPTO_ALG_TYPE_COMPRESS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	.cra_ctxsize		= sizeof(struct zstd_ctx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	.cra_module		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	.cra_init		= zstd_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	.cra_exit		= zstd_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	.cra_u			= { .compress = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	.coa_compress		= zstd_compress,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	.coa_decompress		= zstd_decompress } }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) static struct scomp_alg scomp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	.alloc_ctx		= zstd_alloc_ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	.free_ctx		= zstd_free_ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	.compress		= zstd_scompress,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	.decompress		= zstd_sdecompress,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	.base			= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		.cra_name	= "zstd",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		.cra_driver_name = "zstd-scomp",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		.cra_module	 = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static int __init zstd_mod_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	ret = crypto_register_alg(&alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	ret = crypto_register_scomp(&scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		crypto_unregister_alg(&alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static void __exit zstd_mod_fini(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	crypto_unregister_alg(&alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	crypto_unregister_scomp(&scomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) subsys_initcall(zstd_mod_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) module_exit(zstd_mod_fini);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) MODULE_DESCRIPTION("Zstd Compression Algorithm");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) MODULE_ALIAS_CRYPTO("zstd");