Lines Matching refs:walk
40 static int skcipher_walk_next(struct skcipher_walk *walk);
42 static inline gfp_t skcipher_walk_gfp(struct skcipher_walk *walk) in skcipher_walk_gfp() argument
44 return walk->flags & SKCIPHER_WALK_SLEEP ? GFP_KERNEL : GFP_ATOMIC; in skcipher_walk_gfp()
71 int skcipher_walk_done(struct skcipher_walk *walk, int res) in skcipher_walk_done() argument
73 unsigned int n = walk->nbytes; /* num bytes processed this step */ in skcipher_walk_done()
81 total = walk->total - n; in skcipher_walk_done()
84 if (likely(!(walk->flags & (SKCIPHER_WALK_SLOW | in skcipher_walk_done()
87 scatterwalk_advance(&walk->in, n); in skcipher_walk_done()
88 } else if (walk->flags & SKCIPHER_WALK_DIFF) { in skcipher_walk_done()
89 scatterwalk_done_src(&walk->in, n); in skcipher_walk_done()
90 } else if (walk->flags & SKCIPHER_WALK_COPY) { in skcipher_walk_done()
91 scatterwalk_advance(&walk->in, n); in skcipher_walk_done()
92 scatterwalk_map(&walk->out); in skcipher_walk_done()
93 memcpy(walk->out.addr, walk->page, n); in skcipher_walk_done()
105 memcpy_to_scatterwalk(&walk->out, walk->out.addr, n); in skcipher_walk_done()
109 scatterwalk_done_dst(&walk->out, n); in skcipher_walk_done()
115 walk->total = total; in skcipher_walk_done()
116 walk->nbytes = 0; in skcipher_walk_done()
119 if (walk->flags & SKCIPHER_WALK_SLEEP) in skcipher_walk_done()
121 walk->flags &= ~(SKCIPHER_WALK_SLOW | SKCIPHER_WALK_COPY | in skcipher_walk_done()
123 return skcipher_walk_next(walk); in skcipher_walk_done()
128 if (!((unsigned long)walk->buffer | (unsigned long)walk->page)) in skcipher_walk_done()
131 if (walk->iv != walk->oiv) in skcipher_walk_done()
132 memcpy(walk->oiv, walk->iv, walk->ivsize); in skcipher_walk_done()
133 if (walk->buffer != walk->page) in skcipher_walk_done()
134 kfree(walk->buffer); in skcipher_walk_done()
135 if (walk->page) in skcipher_walk_done()
136 free_page((unsigned long)walk->page); in skcipher_walk_done()
143 static int skcipher_next_slow(struct skcipher_walk *walk, unsigned int bsize) in skcipher_next_slow() argument
145 unsigned alignmask = walk->alignmask; in skcipher_next_slow()
149 if (!walk->buffer) in skcipher_next_slow()
150 walk->buffer = walk->page; in skcipher_next_slow()
151 buffer = walk->buffer; in skcipher_next_slow()
156 buffer = kzalloc(n, skcipher_walk_gfp(walk)); in skcipher_next_slow()
158 return skcipher_walk_done(walk, -ENOMEM); in skcipher_next_slow()
159 walk->buffer = buffer; in skcipher_next_slow()
163 memcpy_from_scatterwalk(buffer, &walk->in, bsize); in skcipher_next_slow()
164 walk->out.__addr = buffer; in skcipher_next_slow()
165 walk->in.__addr = walk->out.addr; in skcipher_next_slow()
167 walk->nbytes = bsize; in skcipher_next_slow()
168 walk->flags |= SKCIPHER_WALK_SLOW; in skcipher_next_slow()
173 static int skcipher_next_copy(struct skcipher_walk *walk) in skcipher_next_copy() argument
175 void *tmp = walk->page; in skcipher_next_copy()
177 scatterwalk_map(&walk->in); in skcipher_next_copy()
178 memcpy(tmp, walk->in.addr, walk->nbytes); in skcipher_next_copy()
179 scatterwalk_unmap(&walk->in); in skcipher_next_copy()
185 walk->in.__addr = tmp; in skcipher_next_copy()
186 walk->out.__addr = tmp; in skcipher_next_copy()
190 static int skcipher_next_fast(struct skcipher_walk *walk) in skcipher_next_fast() argument
194 diff = offset_in_page(walk->in.offset) - in skcipher_next_fast()
195 offset_in_page(walk->out.offset); in skcipher_next_fast()
196 diff |= (u8 *)(sg_page(walk->in.sg) + (walk->in.offset >> PAGE_SHIFT)) - in skcipher_next_fast()
197 (u8 *)(sg_page(walk->out.sg) + (walk->out.offset >> PAGE_SHIFT)); in skcipher_next_fast()
199 scatterwalk_map(&walk->out); in skcipher_next_fast()
200 walk->in.__addr = walk->out.__addr; in skcipher_next_fast()
203 walk->flags |= SKCIPHER_WALK_DIFF; in skcipher_next_fast()
204 scatterwalk_map(&walk->in); in skcipher_next_fast()
210 static int skcipher_walk_next(struct skcipher_walk *walk) in skcipher_walk_next() argument
215 n = walk->total; in skcipher_walk_next()
216 bsize = min(walk->stride, max(n, walk->blocksize)); in skcipher_walk_next()
217 n = scatterwalk_clamp(&walk->in, n); in skcipher_walk_next()
218 n = scatterwalk_clamp(&walk->out, n); in skcipher_walk_next()
221 if (unlikely(walk->total < walk->blocksize)) in skcipher_walk_next()
222 return skcipher_walk_done(walk, -EINVAL); in skcipher_walk_next()
225 return skcipher_next_slow(walk, bsize); in skcipher_walk_next()
227 walk->nbytes = n; in skcipher_walk_next()
229 if (unlikely((walk->in.offset | walk->out.offset) & walk->alignmask)) { in skcipher_walk_next()
230 if (!walk->page) { in skcipher_walk_next()
231 gfp_t gfp = skcipher_walk_gfp(walk); in skcipher_walk_next()
233 walk->page = (void *)__get_free_page(gfp); in skcipher_walk_next()
234 if (!walk->page) in skcipher_walk_next()
237 walk->flags |= SKCIPHER_WALK_COPY; in skcipher_walk_next()
238 return skcipher_next_copy(walk); in skcipher_walk_next()
241 return skcipher_next_fast(walk); in skcipher_walk_next()
244 static int skcipher_copy_iv(struct skcipher_walk *walk) in skcipher_copy_iv() argument
246 unsigned alignmask = walk->alignmask; in skcipher_copy_iv()
247 unsigned ivsize = walk->ivsize; in skcipher_copy_iv()
248 unsigned aligned_stride = ALIGN(walk->stride, alignmask + 1); in skcipher_copy_iv()
256 walk->buffer = kmalloc(size, skcipher_walk_gfp(walk)); in skcipher_copy_iv()
257 if (!walk->buffer) in skcipher_copy_iv()
260 iv = PTR_ALIGN(walk->buffer, alignmask + 1) + aligned_stride; in skcipher_copy_iv()
262 walk->iv = memcpy(iv, walk->iv, walk->ivsize); in skcipher_copy_iv()
266 static int skcipher_walk_first(struct skcipher_walk *walk) in skcipher_walk_first() argument
271 walk->buffer = NULL; in skcipher_walk_first()
272 if (unlikely(((unsigned long)walk->iv & walk->alignmask))) { in skcipher_walk_first()
273 int err = skcipher_copy_iv(walk); in skcipher_walk_first()
278 walk->page = NULL; in skcipher_walk_first()
280 return skcipher_walk_next(walk); in skcipher_walk_first()
283 int skcipher_walk_virt(struct skcipher_walk *__restrict walk, in skcipher_walk_virt() argument
293 walk->total = req->cryptlen; in skcipher_walk_virt()
294 walk->nbytes = 0; in skcipher_walk_virt()
295 walk->iv = req->iv; in skcipher_walk_virt()
296 walk->oiv = req->iv; in skcipher_walk_virt()
298 walk->flags = SKCIPHER_WALK_SLEEP; in skcipher_walk_virt()
300 walk->flags = 0; in skcipher_walk_virt()
302 if (unlikely(!walk->total)) in skcipher_walk_virt()
305 scatterwalk_start(&walk->in, req->src); in skcipher_walk_virt()
306 scatterwalk_start(&walk->out, req->dst); in skcipher_walk_virt()
308 walk->blocksize = crypto_skcipher_blocksize(tfm); in skcipher_walk_virt()
309 walk->ivsize = crypto_skcipher_ivsize(tfm); in skcipher_walk_virt()
310 walk->alignmask = crypto_skcipher_alignmask(tfm); in skcipher_walk_virt()
313 walk->stride = alg->co.chunksize; in skcipher_walk_virt()
315 walk->stride = alg->walksize; in skcipher_walk_virt()
317 return skcipher_walk_first(walk); in skcipher_walk_virt()
321 static int skcipher_walk_aead_common(struct skcipher_walk *__restrict walk, in skcipher_walk_aead_common() argument
327 walk->nbytes = 0; in skcipher_walk_aead_common()
328 walk->iv = req->iv; in skcipher_walk_aead_common()
329 walk->oiv = req->iv; in skcipher_walk_aead_common()
331 walk->flags = SKCIPHER_WALK_SLEEP; in skcipher_walk_aead_common()
333 walk->flags = 0; in skcipher_walk_aead_common()
335 if (unlikely(!walk->total)) in skcipher_walk_aead_common()
338 scatterwalk_start_at_pos(&walk->in, req->src, req->assoclen); in skcipher_walk_aead_common()
339 scatterwalk_start_at_pos(&walk->out, req->dst, req->assoclen); in skcipher_walk_aead_common()
341 walk->blocksize = crypto_aead_blocksize(tfm); in skcipher_walk_aead_common()
342 walk->stride = crypto_aead_chunksize(tfm); in skcipher_walk_aead_common()
343 walk->ivsize = crypto_aead_ivsize(tfm); in skcipher_walk_aead_common()
344 walk->alignmask = crypto_aead_alignmask(tfm); in skcipher_walk_aead_common()
346 return skcipher_walk_first(walk); in skcipher_walk_aead_common()
349 int skcipher_walk_aead_encrypt(struct skcipher_walk *__restrict walk, in skcipher_walk_aead_encrypt() argument
353 walk->total = req->cryptlen; in skcipher_walk_aead_encrypt()
355 return skcipher_walk_aead_common(walk, req, atomic); in skcipher_walk_aead_encrypt()
359 int skcipher_walk_aead_decrypt(struct skcipher_walk *__restrict walk, in skcipher_walk_aead_decrypt() argument
365 walk->total = req->cryptlen - crypto_aead_authsize(tfm); in skcipher_walk_aead_decrypt()
367 return skcipher_walk_aead_common(walk, req, atomic); in skcipher_walk_aead_decrypt()