19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/sched.h>
22 #include <linux/slab.h>
52 if (offset & alignmask) {
53 unsigned int unaligned = alignmask + 1 - (offset & alignmask);
54 if (nbytes > unaligned)
67 walk->
pg = sg_page(sg);
75 return hash_walk_next(walk);
81 unsigned int nbytes = walk->
entrylen;
85 if (nbytes && walk->
offset & alignmask && !err) {
97 crypto_yield(walk->
flags);
105 return hash_walk_next(walk);
111 walk->
sg = scatterwalk_sg_next(walk->
sg);
113 return hash_walk_new_entry(walk);
125 walk->
alignmask = crypto_ahash_alignmask(crypto_ahash_reqtfm(req));
129 return hash_walk_new_entry(walk);
146 return hash_walk_new_entry(walk);
152 unsigned long alignmask = crypto_ahash_alignmask(tfm);
155 unsigned long absize;
157 absize = keylen + alignmask;
162 alignbuffer = (
u8 *)
ALIGN((
unsigned long)
buffer, alignmask + 1);
163 memcpy(alignbuffer, key, keylen);
164 ret = tfm->
setkey(tfm, alignbuffer, keylen);
172 unsigned long alignmask = crypto_ahash_alignmask(tfm);
174 if ((
unsigned long)key & alignmask)
175 return ahash_setkey_unaligned(tfm, key, keylen);
177 return tfm->
setkey(tfm, key, keylen);
181 static int ahash_nosetkey(
struct crypto_ahash *tfm,
const u8 *key,
187 static inline unsigned int ahash_align_buffer_size(
unsigned len,
190 return len + (mask & ~(crypto_tfm_ctx_alignment() - 1));
202 crypto_ahash_digestsize(crypto_ahash_reqtfm(req)));
214 ahash_op_unaligned_finish(areq, err);
223 unsigned long alignmask = crypto_ahash_alignmask(tfm);
224 unsigned int ds = crypto_ahash_digestsize(tfm);
228 priv =
kmalloc(
sizeof(*priv) + ahash_align_buffer_size(ds, alignmask),
239 req->
base.complete = ahash_op_unaligned_done;
244 ahash_op_unaligned_finish(req, err);
253 unsigned long alignmask = crypto_ahash_alignmask(tfm);
255 if ((
unsigned long)req->
result & alignmask)
256 return ahash_op_unaligned(req,
op);
263 return crypto_ahash_op(req, crypto_ahash_reqtfm(req)->
final);
269 return crypto_ahash_op(req, crypto_ahash_reqtfm(req)->
finup);
275 return crypto_ahash_op(req, crypto_ahash_reqtfm(req)->
digest);
279 static void ahash_def_finup_finish2(
struct ahash_request *req,
int err)
288 crypto_ahash_digestsize(crypto_ahash_reqtfm(req)));
300 ahash_def_finup_finish2(areq, err);
305 static int ahash_def_finup_finish1(
struct ahash_request *req,
int err)
310 req->
base.complete = ahash_def_finup_done2;
312 err = crypto_ahash_reqtfm(req)->final(req);
315 ahash_def_finup_finish2(req, err);
326 err = ahash_def_finup_finish1(areq, err);
334 unsigned long alignmask = crypto_ahash_alignmask(tfm);
335 unsigned int ds = crypto_ahash_digestsize(tfm);
338 priv =
kmalloc(
sizeof(*priv) + ahash_align_buffer_size(ds, alignmask),
349 req->
base.complete = ahash_def_finup_done1;
353 return ahash_def_finup_finish1(req, tfm->
update(req));
366 static int crypto_ahash_init_tfm(
struct crypto_tfm *tfm)
369 struct ahash_alg *alg = crypto_ahash_alg(hash);
371 hash->
setkey = ahash_nosetkey;
372 hash->
export = ahash_no_export;
373 hash->
import = ahash_no_import;
394 static unsigned int crypto_ahash_extsize(
struct crypto_alg *alg)
410 rhash.digestsize = __crypto_hash_alg_common(alg)->digestsize;
414 goto nla_put_failure;
440 .extsize = crypto_ahash_extsize,
441 .init_tfm = crypto_ahash_init_tfm,
442 #ifdef CONFIG_PROC_FS
443 .show = crypto_ahash_show,
445 .report = crypto_ahash_report,
460 static int ahash_prepare_alg(
struct ahash_alg *alg)
480 err = ahash_prepare_alg(alg);
499 err = ahash_prepare_alg(&inst->
alg);
528 return IS_ERR(alg) ? ERR_CAST(alg) : __crypto_hash_alg_common(alg);