Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: scatterwalk - Move skcipher walk and use it for memcpy_sglist

Move the generic part of skcipher walk into scatterwalk, and use
it to implement memcpy_sglist.

This makes memcpy_sglist do the right thing when two distinct SG
lists contain identical subsets (e.g., the AD part of AEAD).

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

+329 -331
+259 -15
crypto/scatterwalk.c
··· 10 10 */ 11 11 12 12 #include <crypto/scatterwalk.h> 13 + #include <linux/crypto.h> 14 + #include <linux/errno.h> 13 15 #include <linux/kernel.h> 14 16 #include <linux/mm.h> 15 17 #include <linux/module.h> 16 18 #include <linux/scatterlist.h> 19 + #include <linux/slab.h> 20 + 21 + enum { 22 + SKCIPHER_WALK_SLOW = 1 << 0, 23 + SKCIPHER_WALK_COPY = 1 << 1, 24 + SKCIPHER_WALK_DIFF = 1 << 2, 25 + SKCIPHER_WALK_SLEEP = 1 << 3, 26 + }; 27 + 28 + static inline gfp_t skcipher_walk_gfp(struct skcipher_walk *walk) 29 + { 30 + return walk->flags & SKCIPHER_WALK_SLEEP ? GFP_KERNEL : GFP_ATOMIC; 31 + } 17 32 18 33 void scatterwalk_skip(struct scatter_walk *walk, unsigned int nbytes) 19 34 { ··· 104 89 void memcpy_sglist(struct scatterlist *dst, struct scatterlist *src, 105 90 unsigned int nbytes) 106 91 { 107 - struct scatter_walk swalk; 108 - struct scatter_walk dwalk; 92 + struct skcipher_walk walk = {}; 109 93 110 94 if (unlikely(nbytes == 0)) /* in case sg == NULL */ 111 95 return; 112 96 113 - scatterwalk_start(&swalk, src); 114 - scatterwalk_start(&dwalk, dst); 97 + walk.total = nbytes; 115 98 99 + scatterwalk_start(&walk.in, src); 100 + scatterwalk_start(&walk.out, dst); 101 + 102 + skcipher_walk_first(&walk, true); 116 103 do { 117 - unsigned int slen, dlen; 118 - unsigned int len; 119 - 120 - slen = scatterwalk_next(&swalk, nbytes); 121 - dlen = scatterwalk_next(&dwalk, nbytes); 122 - len = min(slen, dlen); 123 - memcpy(dwalk.addr, swalk.addr, len); 124 - scatterwalk_done_dst(&dwalk, len); 125 - scatterwalk_done_src(&swalk, len); 126 - nbytes -= len; 127 - } while (nbytes); 104 + if (walk.src.virt.addr != walk.dst.virt.addr) 105 + memcpy(walk.dst.virt.addr, walk.src.virt.addr, 106 + walk.nbytes); 107 + skcipher_walk_done(&walk, 0); 108 + } while (walk.nbytes); 128 109 } 129 110 EXPORT_SYMBOL_GPL(memcpy_sglist); 130 111 ··· 146 135 return dst; 147 136 } 148 137 EXPORT_SYMBOL_GPL(scatterwalk_ffwd); 138 + 139 + static int skcipher_next_slow(struct skcipher_walk *walk, unsigned int bsize) 140 + { 141 + unsigned alignmask = walk->alignmask; 142 + unsigned n; 143 + void *buffer; 144 + 145 + if (!walk->buffer) 146 + walk->buffer = walk->page; 147 + buffer = walk->buffer; 148 + if (!buffer) { 149 + /* Min size for a buffer of bsize bytes aligned to alignmask */ 150 + n = bsize + (alignmask & ~(crypto_tfm_ctx_alignment() - 1)); 151 + 152 + buffer = kzalloc(n, skcipher_walk_gfp(walk)); 153 + if (!buffer) 154 + return skcipher_walk_done(walk, -ENOMEM); 155 + walk->buffer = buffer; 156 + } 157 + 158 + buffer = PTR_ALIGN(buffer, alignmask + 1); 159 + memcpy_from_scatterwalk(buffer, &walk->in, bsize); 160 + walk->out.__addr = buffer; 161 + walk->in.__addr = walk->out.addr; 162 + 163 + walk->nbytes = bsize; 164 + walk->flags |= SKCIPHER_WALK_SLOW; 165 + 166 + return 0; 167 + } 168 + 169 + static int skcipher_next_copy(struct skcipher_walk *walk) 170 + { 171 + void *tmp = walk->page; 172 + 173 + scatterwalk_map(&walk->in); 174 + memcpy(tmp, walk->in.addr, walk->nbytes); 175 + scatterwalk_unmap(&walk->in); 176 + /* 177 + * walk->in is advanced later when the number of bytes actually 178 + * processed (which might be less than walk->nbytes) is known. 179 + */ 180 + 181 + walk->in.__addr = tmp; 182 + walk->out.__addr = tmp; 183 + return 0; 184 + } 185 + 186 + static int skcipher_next_fast(struct skcipher_walk *walk) 187 + { 188 + unsigned long diff; 189 + 190 + diff = offset_in_page(walk->in.offset) - 191 + offset_in_page(walk->out.offset); 192 + diff |= (u8 *)(sg_page(walk->in.sg) + (walk->in.offset >> PAGE_SHIFT)) - 193 + (u8 *)(sg_page(walk->out.sg) + (walk->out.offset >> PAGE_SHIFT)); 194 + 195 + scatterwalk_map(&walk->out); 196 + walk->in.__addr = walk->out.__addr; 197 + 198 + if (diff) { 199 + walk->flags |= SKCIPHER_WALK_DIFF; 200 + scatterwalk_map(&walk->in); 201 + } 202 + 203 + return 0; 204 + } 205 + 206 + static int skcipher_walk_next(struct skcipher_walk *walk) 207 + { 208 + unsigned int bsize; 209 + unsigned int n; 210 + 211 + n = walk->total; 212 + bsize = min(walk->stride, max(n, walk->blocksize)); 213 + n = scatterwalk_clamp(&walk->in, n); 214 + n = scatterwalk_clamp(&walk->out, n); 215 + 216 + if (unlikely(n < bsize)) { 217 + if (unlikely(walk->total < walk->blocksize)) 218 + return skcipher_walk_done(walk, -EINVAL); 219 + 220 + slow_path: 221 + return skcipher_next_slow(walk, bsize); 222 + } 223 + walk->nbytes = n; 224 + 225 + if (unlikely((walk->in.offset | walk->out.offset) & walk->alignmask)) { 226 + if (!walk->page) { 227 + gfp_t gfp = skcipher_walk_gfp(walk); 228 + 229 + walk->page = (void *)__get_free_page(gfp); 230 + if (!walk->page) 231 + goto slow_path; 232 + } 233 + walk->flags |= SKCIPHER_WALK_COPY; 234 + return skcipher_next_copy(walk); 235 + } 236 + 237 + return skcipher_next_fast(walk); 238 + } 239 + 240 + static int skcipher_copy_iv(struct skcipher_walk *walk) 241 + { 242 + unsigned alignmask = walk->alignmask; 243 + unsigned ivsize = walk->ivsize; 244 + unsigned aligned_stride = ALIGN(walk->stride, alignmask + 1); 245 + unsigned size; 246 + u8 *iv; 247 + 248 + /* Min size for a buffer of stride + ivsize, aligned to alignmask */ 249 + size = aligned_stride + ivsize + 250 + (alignmask & ~(crypto_tfm_ctx_alignment() - 1)); 251 + 252 + walk->buffer = kmalloc(size, skcipher_walk_gfp(walk)); 253 + if (!walk->buffer) 254 + return -ENOMEM; 255 + 256 + iv = PTR_ALIGN(walk->buffer, alignmask + 1) + aligned_stride; 257 + 258 + walk->iv = memcpy(iv, walk->iv, walk->ivsize); 259 + return 0; 260 + } 261 + 262 + int skcipher_walk_first(struct skcipher_walk *walk, bool atomic) 263 + { 264 + if (WARN_ON_ONCE(in_hardirq())) 265 + return -EDEADLK; 266 + 267 + walk->flags = atomic ? 0 : SKCIPHER_WALK_SLEEP; 268 + 269 + walk->buffer = NULL; 270 + if (unlikely(((unsigned long)walk->iv & walk->alignmask))) { 271 + int err = skcipher_copy_iv(walk); 272 + if (err) 273 + return err; 274 + } 275 + 276 + walk->page = NULL; 277 + 278 + return skcipher_walk_next(walk); 279 + } 280 + EXPORT_SYMBOL_GPL(skcipher_walk_first); 281 + 282 + /** 283 + * skcipher_walk_done() - finish one step of a skcipher_walk 284 + * @walk: the skcipher_walk 285 + * @res: number of bytes *not* processed (>= 0) from walk->nbytes, 286 + * or a -errno value to terminate the walk due to an error 287 + * 288 + * This function cleans up after one step of walking through the source and 289 + * destination scatterlists, and advances to the next step if applicable. 290 + * walk->nbytes is set to the number of bytes available in the next step, 291 + * walk->total is set to the new total number of bytes remaining, and 292 + * walk->{src,dst}.virt.addr is set to the next pair of data pointers. If there 293 + * is no more data, or if an error occurred (i.e. -errno return), then 294 + * walk->nbytes and walk->total are set to 0 and all resources owned by the 295 + * skcipher_walk are freed. 296 + * 297 + * Return: 0 or a -errno value. If @res was a -errno value then it will be 298 + * returned, but other errors may occur too. 299 + */ 300 + int skcipher_walk_done(struct skcipher_walk *walk, int res) 301 + { 302 + unsigned int n = walk->nbytes; /* num bytes processed this step */ 303 + unsigned int total = 0; /* new total remaining */ 304 + 305 + if (!n) 306 + goto finish; 307 + 308 + if (likely(res >= 0)) { 309 + n -= res; /* subtract num bytes *not* processed */ 310 + total = walk->total - n; 311 + } 312 + 313 + if (likely(!(walk->flags & (SKCIPHER_WALK_SLOW | 314 + SKCIPHER_WALK_COPY | 315 + SKCIPHER_WALK_DIFF)))) { 316 + scatterwalk_advance(&walk->in, n); 317 + } else if (walk->flags & SKCIPHER_WALK_DIFF) { 318 + scatterwalk_done_src(&walk->in, n); 319 + } else if (walk->flags & SKCIPHER_WALK_COPY) { 320 + scatterwalk_advance(&walk->in, n); 321 + scatterwalk_map(&walk->out); 322 + memcpy(walk->out.addr, walk->page, n); 323 + } else { /* SKCIPHER_WALK_SLOW */ 324 + if (res > 0) { 325 + /* 326 + * Didn't process all bytes. Either the algorithm is 327 + * broken, or this was the last step and it turned out 328 + * the message wasn't evenly divisible into blocks but 329 + * the algorithm requires it. 330 + */ 331 + res = -EINVAL; 332 + total = 0; 333 + } else 334 + memcpy_to_scatterwalk(&walk->out, walk->out.addr, n); 335 + goto dst_done; 336 + } 337 + 338 + scatterwalk_done_dst(&walk->out, n); 339 + dst_done: 340 + 341 + if (res > 0) 342 + res = 0; 343 + 344 + walk->total = total; 345 + walk->nbytes = 0; 346 + 347 + if (total) { 348 + if (walk->flags & SKCIPHER_WALK_SLEEP) 349 + cond_resched(); 350 + walk->flags &= ~(SKCIPHER_WALK_SLOW | SKCIPHER_WALK_COPY | 351 + SKCIPHER_WALK_DIFF); 352 + return skcipher_walk_next(walk); 353 + } 354 + 355 + finish: 356 + /* Short-circuit for the common/fast path. */ 357 + if (!((unsigned long)walk->buffer | (unsigned long)walk->page)) 358 + goto out; 359 + 360 + if (walk->iv != walk->oiv) 361 + memcpy(walk->oiv, walk->iv, walk->ivsize); 362 + if (walk->buffer != walk->page) 363 + kfree(walk->buffer); 364 + if (walk->page) 365 + free_page((unsigned long)walk->page); 366 + 367 + out: 368 + return res; 369 + } 370 + EXPORT_SYMBOL_GPL(skcipher_walk_done);
+6 -255
crypto/skcipher.c
··· 17 17 #include <linux/cryptouser.h> 18 18 #include <linux/err.h> 19 19 #include <linux/kernel.h> 20 - #include <linux/mm.h> 21 20 #include <linux/module.h> 22 21 #include <linux/seq_file.h> 23 22 #include <linux/slab.h> ··· 27 28 28 29 #define CRYPTO_ALG_TYPE_SKCIPHER_MASK 0x0000000e 29 30 30 - enum { 31 - SKCIPHER_WALK_SLOW = 1 << 0, 32 - SKCIPHER_WALK_COPY = 1 << 1, 33 - SKCIPHER_WALK_DIFF = 1 << 2, 34 - SKCIPHER_WALK_SLEEP = 1 << 3, 35 - }; 36 - 37 31 static const struct crypto_type crypto_skcipher_type; 38 - 39 - static int skcipher_walk_next(struct skcipher_walk *walk); 40 - 41 - static inline gfp_t skcipher_walk_gfp(struct skcipher_walk *walk) 42 - { 43 - return walk->flags & SKCIPHER_WALK_SLEEP ? GFP_KERNEL : GFP_ATOMIC; 44 - } 45 32 46 33 static inline struct skcipher_alg *__crypto_skcipher_alg( 47 34 struct crypto_alg *alg) 48 35 { 49 36 return container_of(alg, struct skcipher_alg, base); 50 - } 51 - 52 - /** 53 - * skcipher_walk_done() - finish one step of a skcipher_walk 54 - * @walk: the skcipher_walk 55 - * @res: number of bytes *not* processed (>= 0) from walk->nbytes, 56 - * or a -errno value to terminate the walk due to an error 57 - * 58 - * This function cleans up after one step of walking through the source and 59 - * destination scatterlists, and advances to the next step if applicable. 60 - * walk->nbytes is set to the number of bytes available in the next step, 61 - * walk->total is set to the new total number of bytes remaining, and 62 - * walk->{src,dst}.virt.addr is set to the next pair of data pointers. If there 63 - * is no more data, or if an error occurred (i.e. -errno return), then 64 - * walk->nbytes and walk->total are set to 0 and all resources owned by the 65 - * skcipher_walk are freed. 66 - * 67 - * Return: 0 or a -errno value. If @res was a -errno value then it will be 68 - * returned, but other errors may occur too. 69 - */ 70 - int skcipher_walk_done(struct skcipher_walk *walk, int res) 71 - { 72 - unsigned int n = walk->nbytes; /* num bytes processed this step */ 73 - unsigned int total = 0; /* new total remaining */ 74 - 75 - if (!n) 76 - goto finish; 77 - 78 - if (likely(res >= 0)) { 79 - n -= res; /* subtract num bytes *not* processed */ 80 - total = walk->total - n; 81 - } 82 - 83 - if (likely(!(walk->flags & (SKCIPHER_WALK_SLOW | 84 - SKCIPHER_WALK_COPY | 85 - SKCIPHER_WALK_DIFF)))) { 86 - scatterwalk_advance(&walk->in, n); 87 - } else if (walk->flags & SKCIPHER_WALK_DIFF) { 88 - scatterwalk_done_src(&walk->in, n); 89 - } else if (walk->flags & SKCIPHER_WALK_COPY) { 90 - scatterwalk_advance(&walk->in, n); 91 - scatterwalk_map(&walk->out); 92 - memcpy(walk->out.addr, walk->page, n); 93 - } else { /* SKCIPHER_WALK_SLOW */ 94 - if (res > 0) { 95 - /* 96 - * Didn't process all bytes. Either the algorithm is 97 - * broken, or this was the last step and it turned out 98 - * the message wasn't evenly divisible into blocks but 99 - * the algorithm requires it. 100 - */ 101 - res = -EINVAL; 102 - total = 0; 103 - } else 104 - memcpy_to_scatterwalk(&walk->out, walk->out.addr, n); 105 - goto dst_done; 106 - } 107 - 108 - scatterwalk_done_dst(&walk->out, n); 109 - dst_done: 110 - 111 - if (res > 0) 112 - res = 0; 113 - 114 - walk->total = total; 115 - walk->nbytes = 0; 116 - 117 - if (total) { 118 - if (walk->flags & SKCIPHER_WALK_SLEEP) 119 - cond_resched(); 120 - walk->flags &= ~(SKCIPHER_WALK_SLOW | SKCIPHER_WALK_COPY | 121 - SKCIPHER_WALK_DIFF); 122 - return skcipher_walk_next(walk); 123 - } 124 - 125 - finish: 126 - /* Short-circuit for the common/fast path. */ 127 - if (!((unsigned long)walk->buffer | (unsigned long)walk->page)) 128 - goto out; 129 - 130 - if (walk->iv != walk->oiv) 131 - memcpy(walk->oiv, walk->iv, walk->ivsize); 132 - if (walk->buffer != walk->page) 133 - kfree(walk->buffer); 134 - if (walk->page) 135 - free_page((unsigned long)walk->page); 136 - 137 - out: 138 - return res; 139 - } 140 - EXPORT_SYMBOL_GPL(skcipher_walk_done); 141 - 142 - static int skcipher_next_slow(struct skcipher_walk *walk, unsigned int bsize) 143 - { 144 - unsigned alignmask = walk->alignmask; 145 - unsigned n; 146 - void *buffer; 147 - 148 - if (!walk->buffer) 149 - walk->buffer = walk->page; 150 - buffer = walk->buffer; 151 - if (!buffer) { 152 - /* Min size for a buffer of bsize bytes aligned to alignmask */ 153 - n = bsize + (alignmask & ~(crypto_tfm_ctx_alignment() - 1)); 154 - 155 - buffer = kzalloc(n, skcipher_walk_gfp(walk)); 156 - if (!buffer) 157 - return skcipher_walk_done(walk, -ENOMEM); 158 - walk->buffer = buffer; 159 - } 160 - 161 - buffer = PTR_ALIGN(buffer, alignmask + 1); 162 - memcpy_from_scatterwalk(buffer, &walk->in, bsize); 163 - walk->out.__addr = buffer; 164 - walk->in.__addr = walk->out.addr; 165 - 166 - walk->nbytes = bsize; 167 - walk->flags |= SKCIPHER_WALK_SLOW; 168 - 169 - return 0; 170 - } 171 - 172 - static int skcipher_next_copy(struct skcipher_walk *walk) 173 - { 174 - void *tmp = walk->page; 175 - 176 - scatterwalk_map(&walk->in); 177 - memcpy(tmp, walk->in.addr, walk->nbytes); 178 - scatterwalk_unmap(&walk->in); 179 - /* 180 - * walk->in is advanced later when the number of bytes actually 181 - * processed (which might be less than walk->nbytes) is known. 182 - */ 183 - 184 - walk->in.__addr = tmp; 185 - walk->out.__addr = tmp; 186 - return 0; 187 - } 188 - 189 - static int skcipher_next_fast(struct skcipher_walk *walk) 190 - { 191 - unsigned long diff; 192 - 193 - diff = offset_in_page(walk->in.offset) - 194 - offset_in_page(walk->out.offset); 195 - diff |= (u8 *)(sg_page(walk->in.sg) + (walk->in.offset >> PAGE_SHIFT)) - 196 - (u8 *)(sg_page(walk->out.sg) + (walk->out.offset >> PAGE_SHIFT)); 197 - 198 - scatterwalk_map(&walk->out); 199 - walk->in.__addr = walk->out.__addr; 200 - 201 - if (diff) { 202 - walk->flags |= SKCIPHER_WALK_DIFF; 203 - scatterwalk_map(&walk->in); 204 - } 205 - 206 - return 0; 207 - } 208 - 209 - static int skcipher_walk_next(struct skcipher_walk *walk) 210 - { 211 - unsigned int bsize; 212 - unsigned int n; 213 - 214 - n = walk->total; 215 - bsize = min(walk->stride, max(n, walk->blocksize)); 216 - n = scatterwalk_clamp(&walk->in, n); 217 - n = scatterwalk_clamp(&walk->out, n); 218 - 219 - if (unlikely(n < bsize)) { 220 - if (unlikely(walk->total < walk->blocksize)) 221 - return skcipher_walk_done(walk, -EINVAL); 222 - 223 - slow_path: 224 - return skcipher_next_slow(walk, bsize); 225 - } 226 - walk->nbytes = n; 227 - 228 - if (unlikely((walk->in.offset | walk->out.offset) & walk->alignmask)) { 229 - if (!walk->page) { 230 - gfp_t gfp = skcipher_walk_gfp(walk); 231 - 232 - walk->page = (void *)__get_free_page(gfp); 233 - if (!walk->page) 234 - goto slow_path; 235 - } 236 - walk->flags |= SKCIPHER_WALK_COPY; 237 - return skcipher_next_copy(walk); 238 - } 239 - 240 - return skcipher_next_fast(walk); 241 - } 242 - 243 - static int skcipher_copy_iv(struct skcipher_walk *walk) 244 - { 245 - unsigned alignmask = walk->alignmask; 246 - unsigned ivsize = walk->ivsize; 247 - unsigned aligned_stride = ALIGN(walk->stride, alignmask + 1); 248 - unsigned size; 249 - u8 *iv; 250 - 251 - /* Min size for a buffer of stride + ivsize, aligned to alignmask */ 252 - size = aligned_stride + ivsize + 253 - (alignmask & ~(crypto_tfm_ctx_alignment() - 1)); 254 - 255 - walk->buffer = kmalloc(size, skcipher_walk_gfp(walk)); 256 - if (!walk->buffer) 257 - return -ENOMEM; 258 - 259 - iv = PTR_ALIGN(walk->buffer, alignmask + 1) + aligned_stride; 260 - 261 - walk->iv = memcpy(iv, walk->iv, walk->ivsize); 262 - return 0; 263 - } 264 - 265 - static int skcipher_walk_first(struct skcipher_walk *walk) 266 - { 267 - if (WARN_ON_ONCE(in_hardirq())) 268 - return -EDEADLK; 269 - 270 - walk->buffer = NULL; 271 - if (unlikely(((unsigned long)walk->iv & walk->alignmask))) { 272 - int err = skcipher_copy_iv(walk); 273 - if (err) 274 - return err; 275 - } 276 - 277 - walk->page = NULL; 278 - 279 - return skcipher_walk_next(walk); 280 37 } 281 38 282 39 int skcipher_walk_virt(struct skcipher_walk *__restrict walk, ··· 49 294 walk->nbytes = 0; 50 295 walk->iv = req->iv; 51 296 walk->oiv = req->iv; 52 - if ((req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) && !atomic) 53 - walk->flags = SKCIPHER_WALK_SLEEP; 54 - else 55 - walk->flags = 0; 297 + if (!(req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP)) 298 + atomic = true; 56 299 57 300 if (unlikely(!walk->total)) 58 301 return 0; ··· 67 314 else 68 315 walk->stride = alg->walksize; 69 316 70 - return skcipher_walk_first(walk); 317 + return skcipher_walk_first(walk, atomic); 71 318 } 72 319 EXPORT_SYMBOL_GPL(skcipher_walk_virt); 73 320 ··· 80 327 walk->nbytes = 0; 81 328 walk->iv = req->iv; 82 329 walk->oiv = req->iv; 83 - if ((req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) && !atomic) 84 - walk->flags = SKCIPHER_WALK_SLEEP; 85 - else 86 - walk->flags = 0; 330 + if (!(req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP)) 331 + atomic = true; 87 332 88 333 if (unlikely(!walk->total)) 89 334 return 0; ··· 94 343 walk->ivsize = crypto_aead_ivsize(tfm); 95 344 walk->alignmask = crypto_aead_alignmask(tfm); 96 345 97 - return skcipher_walk_first(walk); 346 + return skcipher_walk_first(walk, atomic); 98 347 } 99 348 100 349 int skcipher_walk_aead_encrypt(struct skcipher_walk *__restrict walk,
-12
include/crypto/algapi.h
··· 107 107 unsigned int max_qlen; 108 108 }; 109 109 110 - struct scatter_walk { 111 - /* Must be the first member, see struct skcipher_walk. */ 112 - union { 113 - void *const addr; 114 - 115 - /* Private API field, do not touch. */ 116 - union crypto_no_such_thing *__addr; 117 - }; 118 - struct scatterlist *sg; 119 - unsigned int offset; 120 - }; 121 - 122 110 struct crypto_attr_alg { 123 111 char name[CRYPTO_MAX_ALG_NAME]; 124 112 };
+1 -47
include/crypto/internal/skcipher.h
··· 10 10 11 11 #include <crypto/algapi.h> 12 12 #include <crypto/internal/cipher.h> 13 + #include <crypto/scatterwalk.h> 13 14 #include <crypto/skcipher.h> 14 15 #include <linux/types.h> 15 16 ··· 53 52 54 53 struct crypto_lskcipher_spawn { 55 54 struct crypto_spawn base; 56 - }; 57 - 58 - struct skcipher_walk { 59 - union { 60 - /* Virtual address of the source. */ 61 - struct { 62 - struct { 63 - const void *const addr; 64 - } virt; 65 - } src; 66 - 67 - /* Private field for the API, do not use. */ 68 - struct scatter_walk in; 69 - }; 70 - 71 - union { 72 - /* Virtual address of the destination. */ 73 - struct { 74 - struct { 75 - void *const addr; 76 - } virt; 77 - } dst; 78 - 79 - /* Private field for the API, do not use. */ 80 - struct scatter_walk out; 81 - }; 82 - 83 - unsigned int nbytes; 84 - unsigned int total; 85 - 86 - u8 *page; 87 - u8 *buffer; 88 - u8 *oiv; 89 - void *iv; 90 - 91 - unsigned int ivsize; 92 - 93 - int flags; 94 - unsigned int blocksize; 95 - unsigned int stride; 96 - unsigned int alignmask; 97 55 }; 98 56 99 57 static inline struct crypto_instance *skcipher_crypto_instance( ··· 171 211 int lskcipher_register_instance(struct crypto_template *tmpl, 172 212 struct lskcipher_instance *inst); 173 213 174 - int skcipher_walk_done(struct skcipher_walk *walk, int res); 175 214 int skcipher_walk_virt(struct skcipher_walk *__restrict walk, 176 215 struct skcipher_request *__restrict req, 177 216 bool atomic); ··· 180 221 int skcipher_walk_aead_decrypt(struct skcipher_walk *__restrict walk, 181 222 struct aead_request *__restrict req, 182 223 bool atomic); 183 - 184 - static inline void skcipher_walk_abort(struct skcipher_walk *walk) 185 - { 186 - skcipher_walk_done(walk, -ECANCELED); 187 - } 188 224 189 225 static inline void *crypto_skcipher_ctx(struct crypto_skcipher *tfm) 190 226 {
+63 -2
include/crypto/scatterwalk.h
··· 11 11 #ifndef _CRYPTO_SCATTERWALK_H 12 12 #define _CRYPTO_SCATTERWALK_H 13 13 14 - #include <crypto/algapi.h> 15 - 14 + #include <linux/errno.h> 16 15 #include <linux/highmem.h> 17 16 #include <linux/mm.h> 18 17 #include <linux/scatterlist.h> 18 + #include <linux/types.h> 19 + 20 + struct scatter_walk { 21 + /* Must be the first member, see struct skcipher_walk. */ 22 + union { 23 + void *const addr; 24 + 25 + /* Private API field, do not touch. */ 26 + union crypto_no_such_thing *__addr; 27 + }; 28 + struct scatterlist *sg; 29 + unsigned int offset; 30 + }; 31 + 32 + struct skcipher_walk { 33 + union { 34 + /* Virtual address of the source. */ 35 + struct { 36 + struct { 37 + const void *const addr; 38 + } virt; 39 + } src; 40 + 41 + /* Private field for the API, do not use. */ 42 + struct scatter_walk in; 43 + }; 44 + 45 + union { 46 + /* Virtual address of the destination. */ 47 + struct { 48 + struct { 49 + void *const addr; 50 + } virt; 51 + } dst; 52 + 53 + /* Private field for the API, do not use. */ 54 + struct scatter_walk out; 55 + }; 56 + 57 + unsigned int nbytes; 58 + unsigned int total; 59 + 60 + u8 *page; 61 + u8 *buffer; 62 + u8 *oiv; 63 + void *iv; 64 + 65 + unsigned int ivsize; 66 + 67 + int flags; 68 + unsigned int blocksize; 69 + unsigned int stride; 70 + unsigned int alignmask; 71 + }; 19 72 20 73 static inline void scatterwalk_crypto_chain(struct scatterlist *head, 21 74 struct scatterlist *sg, int num) ··· 295 242 struct scatterlist *scatterwalk_ffwd(struct scatterlist dst[2], 296 243 struct scatterlist *src, 297 244 unsigned int len); 245 + 246 + int skcipher_walk_first(struct skcipher_walk *walk, bool atomic); 247 + int skcipher_walk_done(struct skcipher_walk *walk, int res); 248 + 249 + static inline void skcipher_walk_abort(struct skcipher_walk *walk) 250 + { 251 + skcipher_walk_done(walk, -ECANCELED); 252 + } 298 253 299 254 #endif /* _CRYPTO_SCATTERWALK_H */