0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include <linux/init.h>
0022 #include <linux/module.h>
0023 #include <linux/crypto.h>
0024 #include <linux/sw842.h>
0025 #include <crypto/internal/scompress.h>
0026
0027 struct crypto842_ctx {
0028 void *wmem;
0029 };
0030
0031 static void *crypto842_alloc_ctx(struct crypto_scomp *tfm)
0032 {
0033 void *ctx;
0034
0035 ctx = kmalloc(SW842_MEM_COMPRESS, GFP_KERNEL);
0036 if (!ctx)
0037 return ERR_PTR(-ENOMEM);
0038
0039 return ctx;
0040 }
0041
0042 static int crypto842_init(struct crypto_tfm *tfm)
0043 {
0044 struct crypto842_ctx *ctx = crypto_tfm_ctx(tfm);
0045
0046 ctx->wmem = crypto842_alloc_ctx(NULL);
0047 if (IS_ERR(ctx->wmem))
0048 return -ENOMEM;
0049
0050 return 0;
0051 }
0052
0053 static void crypto842_free_ctx(struct crypto_scomp *tfm, void *ctx)
0054 {
0055 kfree(ctx);
0056 }
0057
0058 static void crypto842_exit(struct crypto_tfm *tfm)
0059 {
0060 struct crypto842_ctx *ctx = crypto_tfm_ctx(tfm);
0061
0062 crypto842_free_ctx(NULL, ctx->wmem);
0063 }
0064
0065 static int crypto842_compress(struct crypto_tfm *tfm,
0066 const u8 *src, unsigned int slen,
0067 u8 *dst, unsigned int *dlen)
0068 {
0069 struct crypto842_ctx *ctx = crypto_tfm_ctx(tfm);
0070
0071 return sw842_compress(src, slen, dst, dlen, ctx->wmem);
0072 }
0073
0074 static int crypto842_scompress(struct crypto_scomp *tfm,
0075 const u8 *src, unsigned int slen,
0076 u8 *dst, unsigned int *dlen, void *ctx)
0077 {
0078 return sw842_compress(src, slen, dst, dlen, ctx);
0079 }
0080
0081 static int crypto842_decompress(struct crypto_tfm *tfm,
0082 const u8 *src, unsigned int slen,
0083 u8 *dst, unsigned int *dlen)
0084 {
0085 return sw842_decompress(src, slen, dst, dlen);
0086 }
0087
0088 static int crypto842_sdecompress(struct crypto_scomp *tfm,
0089 const u8 *src, unsigned int slen,
0090 u8 *dst, unsigned int *dlen, void *ctx)
0091 {
0092 return sw842_decompress(src, slen, dst, dlen);
0093 }
0094
0095 static struct crypto_alg alg = {
0096 .cra_name = "842",
0097 .cra_driver_name = "842-generic",
0098 .cra_priority = 100,
0099 .cra_flags = CRYPTO_ALG_TYPE_COMPRESS,
0100 .cra_ctxsize = sizeof(struct crypto842_ctx),
0101 .cra_module = THIS_MODULE,
0102 .cra_init = crypto842_init,
0103 .cra_exit = crypto842_exit,
0104 .cra_u = { .compress = {
0105 .coa_compress = crypto842_compress,
0106 .coa_decompress = crypto842_decompress } }
0107 };
0108
0109 static struct scomp_alg scomp = {
0110 .alloc_ctx = crypto842_alloc_ctx,
0111 .free_ctx = crypto842_free_ctx,
0112 .compress = crypto842_scompress,
0113 .decompress = crypto842_sdecompress,
0114 .base = {
0115 .cra_name = "842",
0116 .cra_driver_name = "842-scomp",
0117 .cra_priority = 100,
0118 .cra_module = THIS_MODULE,
0119 }
0120 };
0121
0122 static int __init crypto842_mod_init(void)
0123 {
0124 int ret;
0125
0126 ret = crypto_register_alg(&alg);
0127 if (ret)
0128 return ret;
0129
0130 ret = crypto_register_scomp(&scomp);
0131 if (ret) {
0132 crypto_unregister_alg(&alg);
0133 return ret;
0134 }
0135
0136 return ret;
0137 }
0138 subsys_initcall(crypto842_mod_init);
0139
0140 static void __exit crypto842_mod_exit(void)
0141 {
0142 crypto_unregister_alg(&alg);
0143 crypto_unregister_scomp(&scomp);
0144 }
0145 module_exit(crypto842_mod_exit);
0146
0147 MODULE_LICENSE("GPL");
0148 MODULE_DESCRIPTION("842 Software Compression Algorithm");
0149 MODULE_ALIAS_CRYPTO("842");
0150 MODULE_ALIAS_CRYPTO("842-generic");
0151 MODULE_AUTHOR("Dan Streetman <ddstreet@ieee.org>");