diff options
Diffstat (limited to 'crypto/digest.c')
-rw-r--r-- | crypto/digest.c | 83 |
1 files changed, 82 insertions, 1 deletions
diff --git a/crypto/digest.c b/crypto/digest.c index b526cc348b79..ac0919460d14 100644 --- a/crypto/digest.c +++ b/crypto/digest.c | |||
@@ -12,6 +12,7 @@ | |||
12 | * | 12 | * |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include <crypto/internal/hash.h> | ||
15 | #include <crypto/scatterwalk.h> | 16 | #include <crypto/scatterwalk.h> |
16 | #include <linux/mm.h> | 17 | #include <linux/mm.h> |
17 | #include <linux/errno.h> | 18 | #include <linux/errno.h> |
@@ -141,7 +142,7 @@ int crypto_init_digest_ops(struct crypto_tfm *tfm) | |||
141 | struct hash_tfm *ops = &tfm->crt_hash; | 142 | struct hash_tfm *ops = &tfm->crt_hash; |
142 | struct digest_alg *dalg = &tfm->__crt_alg->cra_digest; | 143 | struct digest_alg *dalg = &tfm->__crt_alg->cra_digest; |
143 | 144 | ||
144 | if (dalg->dia_digestsize > crypto_tfm_alg_blocksize(tfm)) | 145 | if (dalg->dia_digestsize > PAGE_SIZE / 8) |
145 | return -EINVAL; | 146 | return -EINVAL; |
146 | 147 | ||
147 | ops->init = init; | 148 | ops->init = init; |
@@ -157,3 +158,83 @@ int crypto_init_digest_ops(struct crypto_tfm *tfm) | |||
157 | void crypto_exit_digest_ops(struct crypto_tfm *tfm) | 158 | void crypto_exit_digest_ops(struct crypto_tfm *tfm) |
158 | { | 159 | { |
159 | } | 160 | } |
161 | |||
162 | static int digest_async_nosetkey(struct crypto_ahash *tfm_async, const u8 *key, | ||
163 | unsigned int keylen) | ||
164 | { | ||
165 | crypto_ahash_clear_flags(tfm_async, CRYPTO_TFM_RES_MASK); | ||
166 | return -ENOSYS; | ||
167 | } | ||
168 | |||
169 | static int digest_async_setkey(struct crypto_ahash *tfm_async, const u8 *key, | ||
170 | unsigned int keylen) | ||
171 | { | ||
172 | struct crypto_tfm *tfm = crypto_ahash_tfm(tfm_async); | ||
173 | struct digest_alg *dalg = &tfm->__crt_alg->cra_digest; | ||
174 | |||
175 | crypto_ahash_clear_flags(tfm_async, CRYPTO_TFM_RES_MASK); | ||
176 | return dalg->dia_setkey(tfm, key, keylen); | ||
177 | } | ||
178 | |||
179 | static int digest_async_init(struct ahash_request *req) | ||
180 | { | ||
181 | struct crypto_tfm *tfm = req->base.tfm; | ||
182 | struct digest_alg *dalg = &tfm->__crt_alg->cra_digest; | ||
183 | |||
184 | dalg->dia_init(tfm); | ||
185 | return 0; | ||
186 | } | ||
187 | |||
188 | static int digest_async_update(struct ahash_request *req) | ||
189 | { | ||
190 | struct crypto_tfm *tfm = req->base.tfm; | ||
191 | struct hash_desc desc = { | ||
192 | .tfm = __crypto_hash_cast(tfm), | ||
193 | .flags = req->base.flags, | ||
194 | }; | ||
195 | |||
196 | update(&desc, req->src, req->nbytes); | ||
197 | return 0; | ||
198 | } | ||
199 | |||
200 | static int digest_async_final(struct ahash_request *req) | ||
201 | { | ||
202 | struct crypto_tfm *tfm = req->base.tfm; | ||
203 | struct hash_desc desc = { | ||
204 | .tfm = __crypto_hash_cast(tfm), | ||
205 | .flags = req->base.flags, | ||
206 | }; | ||
207 | |||
208 | final(&desc, req->result); | ||
209 | return 0; | ||
210 | } | ||
211 | |||
212 | static int digest_async_digest(struct ahash_request *req) | ||
213 | { | ||
214 | struct crypto_tfm *tfm = req->base.tfm; | ||
215 | struct hash_desc desc = { | ||
216 | .tfm = __crypto_hash_cast(tfm), | ||
217 | .flags = req->base.flags, | ||
218 | }; | ||
219 | |||
220 | return digest(&desc, req->src, req->nbytes, req->result); | ||
221 | } | ||
222 | |||
223 | int crypto_init_digest_ops_async(struct crypto_tfm *tfm) | ||
224 | { | ||
225 | struct ahash_tfm *crt = &tfm->crt_ahash; | ||
226 | struct digest_alg *dalg = &tfm->__crt_alg->cra_digest; | ||
227 | |||
228 | if (dalg->dia_digestsize > crypto_tfm_alg_blocksize(tfm)) | ||
229 | return -EINVAL; | ||
230 | |||
231 | crt->init = digest_async_init; | ||
232 | crt->update = digest_async_update; | ||
233 | crt->final = digest_async_final; | ||
234 | crt->digest = digest_async_digest; | ||
235 | crt->setkey = dalg->dia_setkey ? digest_async_setkey : | ||
236 | digest_async_nosetkey; | ||
237 | crt->digestsize = dalg->dia_digestsize; | ||
238 | |||
239 | return 0; | ||
240 | } | ||