diff options
author | Giovanni Cabiddu <giovanni.cabiddu@intel.com> | 2016-10-21 08:19:52 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2016-10-24 23:08:33 -0400 |
commit | 6a8de3aefb0a6890c8276a5b247831518814a0c4 (patch) | |
tree | 55787d307e8e59defd3110b2e47a7998d5048c41 /crypto/842.c | |
parent | 91d53d96e27018d4f49b9e5994cc1e74a4fc5d92 (diff) |
crypto: acomp - add support for 842 via scomp
Add scomp backend for 842 compression algorithm.
Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/842.c')
-rw-r--r-- | crypto/842.c | 81 |
1 files changed, 79 insertions, 2 deletions
diff --git a/crypto/842.c b/crypto/842.c index 98e387efb8c8..bc26dc942821 100644 --- a/crypto/842.c +++ b/crypto/842.c | |||
@@ -31,11 +31,46 @@ | |||
31 | #include <linux/module.h> | 31 | #include <linux/module.h> |
32 | #include <linux/crypto.h> | 32 | #include <linux/crypto.h> |
33 | #include <linux/sw842.h> | 33 | #include <linux/sw842.h> |
34 | #include <crypto/internal/scompress.h> | ||
34 | 35 | ||
35 | struct crypto842_ctx { | 36 | struct crypto842_ctx { |
36 | char wmem[SW842_MEM_COMPRESS]; /* working memory for compress */ | 37 | void *wmem; /* working memory for compress */ |
37 | }; | 38 | }; |
38 | 39 | ||
40 | static void *crypto842_alloc_ctx(struct crypto_scomp *tfm) | ||
41 | { | ||
42 | void *ctx; | ||
43 | |||
44 | ctx = kmalloc(SW842_MEM_COMPRESS, GFP_KERNEL); | ||
45 | if (!ctx) | ||
46 | return ERR_PTR(-ENOMEM); | ||
47 | |||
48 | return ctx; | ||
49 | } | ||
50 | |||
51 | static int crypto842_init(struct crypto_tfm *tfm) | ||
52 | { | ||
53 | struct crypto842_ctx *ctx = crypto_tfm_ctx(tfm); | ||
54 | |||
55 | ctx->wmem = crypto842_alloc_ctx(NULL); | ||
56 | if (IS_ERR(ctx->wmem)) | ||
57 | return -ENOMEM; | ||
58 | |||
59 | return 0; | ||
60 | } | ||
61 | |||
62 | static void crypto842_free_ctx(struct crypto_scomp *tfm, void *ctx) | ||
63 | { | ||
64 | kfree(ctx); | ||
65 | } | ||
66 | |||
67 | static void crypto842_exit(struct crypto_tfm *tfm) | ||
68 | { | ||
69 | struct crypto842_ctx *ctx = crypto_tfm_ctx(tfm); | ||
70 | |||
71 | crypto842_free_ctx(NULL, ctx->wmem); | ||
72 | } | ||
73 | |||
39 | static int crypto842_compress(struct crypto_tfm *tfm, | 74 | static int crypto842_compress(struct crypto_tfm *tfm, |
40 | const u8 *src, unsigned int slen, | 75 | const u8 *src, unsigned int slen, |
41 | u8 *dst, unsigned int *dlen) | 76 | u8 *dst, unsigned int *dlen) |
@@ -45,6 +80,13 @@ static int crypto842_compress(struct crypto_tfm *tfm, | |||
45 | return sw842_compress(src, slen, dst, dlen, ctx->wmem); | 80 | return sw842_compress(src, slen, dst, dlen, ctx->wmem); |
46 | } | 81 | } |
47 | 82 | ||
83 | static int crypto842_scompress(struct crypto_scomp *tfm, | ||
84 | const u8 *src, unsigned int slen, | ||
85 | u8 *dst, unsigned int *dlen, void *ctx) | ||
86 | { | ||
87 | return sw842_compress(src, slen, dst, dlen, ctx); | ||
88 | } | ||
89 | |||
48 | static int crypto842_decompress(struct crypto_tfm *tfm, | 90 | static int crypto842_decompress(struct crypto_tfm *tfm, |
49 | const u8 *src, unsigned int slen, | 91 | const u8 *src, unsigned int slen, |
50 | u8 *dst, unsigned int *dlen) | 92 | u8 *dst, unsigned int *dlen) |
@@ -52,6 +94,13 @@ static int crypto842_decompress(struct crypto_tfm *tfm, | |||
52 | return sw842_decompress(src, slen, dst, dlen); | 94 | return sw842_decompress(src, slen, dst, dlen); |
53 | } | 95 | } |
54 | 96 | ||
97 | static int crypto842_sdecompress(struct crypto_scomp *tfm, | ||
98 | const u8 *src, unsigned int slen, | ||
99 | u8 *dst, unsigned int *dlen, void *ctx) | ||
100 | { | ||
101 | return sw842_decompress(src, slen, dst, dlen); | ||
102 | } | ||
103 | |||
55 | static struct crypto_alg alg = { | 104 | static struct crypto_alg alg = { |
56 | .cra_name = "842", | 105 | .cra_name = "842", |
57 | .cra_driver_name = "842-generic", | 106 | .cra_driver_name = "842-generic", |
@@ -59,20 +108,48 @@ static struct crypto_alg alg = { | |||
59 | .cra_flags = CRYPTO_ALG_TYPE_COMPRESS, | 108 | .cra_flags = CRYPTO_ALG_TYPE_COMPRESS, |
60 | .cra_ctxsize = sizeof(struct crypto842_ctx), | 109 | .cra_ctxsize = sizeof(struct crypto842_ctx), |
61 | .cra_module = THIS_MODULE, | 110 | .cra_module = THIS_MODULE, |
111 | .cra_init = crypto842_init, | ||
112 | .cra_exit = crypto842_exit, | ||
62 | .cra_u = { .compress = { | 113 | .cra_u = { .compress = { |
63 | .coa_compress = crypto842_compress, | 114 | .coa_compress = crypto842_compress, |
64 | .coa_decompress = crypto842_decompress } } | 115 | .coa_decompress = crypto842_decompress } } |
65 | }; | 116 | }; |
66 | 117 | ||
118 | static struct scomp_alg scomp = { | ||
119 | .alloc_ctx = crypto842_alloc_ctx, | ||
120 | .free_ctx = crypto842_free_ctx, | ||
121 | .compress = crypto842_scompress, | ||
122 | .decompress = crypto842_sdecompress, | ||
123 | .base = { | ||
124 | .cra_name = "842", | ||
125 | .cra_driver_name = "842-scomp", | ||
126 | .cra_priority = 100, | ||
127 | .cra_module = THIS_MODULE, | ||
128 | } | ||
129 | }; | ||
130 | |||
67 | static int __init crypto842_mod_init(void) | 131 | static int __init crypto842_mod_init(void) |
68 | { | 132 | { |
69 | return crypto_register_alg(&alg); | 133 | int ret; |
134 | |||
135 | ret = crypto_register_alg(&alg); | ||
136 | if (ret) | ||
137 | return ret; | ||
138 | |||
139 | ret = crypto_register_scomp(&scomp); | ||
140 | if (ret) { | ||
141 | crypto_unregister_alg(&alg); | ||
142 | return ret; | ||
143 | } | ||
144 | |||
145 | return ret; | ||
70 | } | 146 | } |
71 | module_init(crypto842_mod_init); | 147 | module_init(crypto842_mod_init); |
72 | 148 | ||
73 | static void __exit crypto842_mod_exit(void) | 149 | static void __exit crypto842_mod_exit(void) |
74 | { | 150 | { |
75 | crypto_unregister_alg(&alg); | 151 | crypto_unregister_alg(&alg); |
152 | crypto_unregister_scomp(&scomp); | ||
76 | } | 153 | } |
77 | module_exit(crypto842_mod_exit); | 154 | module_exit(crypto842_mod_exit); |
78 | 155 | ||