Commit ab83407e9ee35a4972457aa487be6a7a21afd715
1 parent
7e3da6c4b9
Exists in
master
and in
4 other branches
crypto: don't pollute the global namespace with sg_next()
It's a subsystem function, prefix it as such. Acked-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Showing 3 changed files with 3 additions and 3 deletions Inline Diff
crypto/digest.c
1 | /* | 1 | /* |
2 | * Cryptographic API. | 2 | * Cryptographic API. |
3 | * | 3 | * |
4 | * Digest operations. | 4 | * Digest operations. |
5 | * | 5 | * |
6 | * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> | 6 | * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> |
7 | * | 7 | * |
8 | * This program is free software; you can redistribute it and/or modify it | 8 | * This program is free software; you can redistribute it and/or modify it |
9 | * under the terms of the GNU General Public License as published by the Free | 9 | * under the terms of the GNU General Public License as published by the Free |
10 | * Software Foundation; either version 2 of the License, or (at your option) | 10 | * Software Foundation; either version 2 of the License, or (at your option) |
11 | * any later version. | 11 | * any later version. |
12 | * | 12 | * |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include <linux/mm.h> | 15 | #include <linux/mm.h> |
16 | #include <linux/errno.h> | 16 | #include <linux/errno.h> |
17 | #include <linux/hardirq.h> | 17 | #include <linux/hardirq.h> |
18 | #include <linux/highmem.h> | 18 | #include <linux/highmem.h> |
19 | #include <linux/kernel.h> | 19 | #include <linux/kernel.h> |
20 | #include <linux/module.h> | 20 | #include <linux/module.h> |
21 | #include <linux/scatterlist.h> | 21 | #include <linux/scatterlist.h> |
22 | 22 | ||
23 | #include "internal.h" | 23 | #include "internal.h" |
24 | #include "scatterwalk.h" | 24 | #include "scatterwalk.h" |
25 | 25 | ||
26 | static int init(struct hash_desc *desc) | 26 | static int init(struct hash_desc *desc) |
27 | { | 27 | { |
28 | struct crypto_tfm *tfm = crypto_hash_tfm(desc->tfm); | 28 | struct crypto_tfm *tfm = crypto_hash_tfm(desc->tfm); |
29 | 29 | ||
30 | tfm->__crt_alg->cra_digest.dia_init(tfm); | 30 | tfm->__crt_alg->cra_digest.dia_init(tfm); |
31 | return 0; | 31 | return 0; |
32 | } | 32 | } |
33 | 33 | ||
34 | static int update2(struct hash_desc *desc, | 34 | static int update2(struct hash_desc *desc, |
35 | struct scatterlist *sg, unsigned int nbytes) | 35 | struct scatterlist *sg, unsigned int nbytes) |
36 | { | 36 | { |
37 | struct crypto_tfm *tfm = crypto_hash_tfm(desc->tfm); | 37 | struct crypto_tfm *tfm = crypto_hash_tfm(desc->tfm); |
38 | unsigned int alignmask = crypto_tfm_alg_alignmask(tfm); | 38 | unsigned int alignmask = crypto_tfm_alg_alignmask(tfm); |
39 | 39 | ||
40 | if (!nbytes) | 40 | if (!nbytes) |
41 | return 0; | 41 | return 0; |
42 | 42 | ||
43 | for (;;) { | 43 | for (;;) { |
44 | struct page *pg = sg->page; | 44 | struct page *pg = sg->page; |
45 | unsigned int offset = sg->offset; | 45 | unsigned int offset = sg->offset; |
46 | unsigned int l = sg->length; | 46 | unsigned int l = sg->length; |
47 | 47 | ||
48 | if (unlikely(l > nbytes)) | 48 | if (unlikely(l > nbytes)) |
49 | l = nbytes; | 49 | l = nbytes; |
50 | nbytes -= l; | 50 | nbytes -= l; |
51 | 51 | ||
52 | do { | 52 | do { |
53 | unsigned int bytes_from_page = min(l, ((unsigned int) | 53 | unsigned int bytes_from_page = min(l, ((unsigned int) |
54 | (PAGE_SIZE)) - | 54 | (PAGE_SIZE)) - |
55 | offset); | 55 | offset); |
56 | char *src = crypto_kmap(pg, 0); | 56 | char *src = crypto_kmap(pg, 0); |
57 | char *p = src + offset; | 57 | char *p = src + offset; |
58 | 58 | ||
59 | if (unlikely(offset & alignmask)) { | 59 | if (unlikely(offset & alignmask)) { |
60 | unsigned int bytes = | 60 | unsigned int bytes = |
61 | alignmask + 1 - (offset & alignmask); | 61 | alignmask + 1 - (offset & alignmask); |
62 | bytes = min(bytes, bytes_from_page); | 62 | bytes = min(bytes, bytes_from_page); |
63 | tfm->__crt_alg->cra_digest.dia_update(tfm, p, | 63 | tfm->__crt_alg->cra_digest.dia_update(tfm, p, |
64 | bytes); | 64 | bytes); |
65 | p += bytes; | 65 | p += bytes; |
66 | bytes_from_page -= bytes; | 66 | bytes_from_page -= bytes; |
67 | l -= bytes; | 67 | l -= bytes; |
68 | } | 68 | } |
69 | tfm->__crt_alg->cra_digest.dia_update(tfm, p, | 69 | tfm->__crt_alg->cra_digest.dia_update(tfm, p, |
70 | bytes_from_page); | 70 | bytes_from_page); |
71 | crypto_kunmap(src, 0); | 71 | crypto_kunmap(src, 0); |
72 | crypto_yield(desc->flags); | 72 | crypto_yield(desc->flags); |
73 | offset = 0; | 73 | offset = 0; |
74 | pg++; | 74 | pg++; |
75 | l -= bytes_from_page; | 75 | l -= bytes_from_page; |
76 | } while (l > 0); | 76 | } while (l > 0); |
77 | 77 | ||
78 | if (!nbytes) | 78 | if (!nbytes) |
79 | break; | 79 | break; |
80 | sg = sg_next(sg); | 80 | sg = scatterwalk_sg_next(sg); |
81 | } | 81 | } |
82 | 82 | ||
83 | return 0; | 83 | return 0; |
84 | } | 84 | } |
85 | 85 | ||
86 | static int update(struct hash_desc *desc, | 86 | static int update(struct hash_desc *desc, |
87 | struct scatterlist *sg, unsigned int nbytes) | 87 | struct scatterlist *sg, unsigned int nbytes) |
88 | { | 88 | { |
89 | if (WARN_ON_ONCE(in_irq())) | 89 | if (WARN_ON_ONCE(in_irq())) |
90 | return -EDEADLK; | 90 | return -EDEADLK; |
91 | return update2(desc, sg, nbytes); | 91 | return update2(desc, sg, nbytes); |
92 | } | 92 | } |
93 | 93 | ||
94 | static int final(struct hash_desc *desc, u8 *out) | 94 | static int final(struct hash_desc *desc, u8 *out) |
95 | { | 95 | { |
96 | struct crypto_tfm *tfm = crypto_hash_tfm(desc->tfm); | 96 | struct crypto_tfm *tfm = crypto_hash_tfm(desc->tfm); |
97 | unsigned long alignmask = crypto_tfm_alg_alignmask(tfm); | 97 | unsigned long alignmask = crypto_tfm_alg_alignmask(tfm); |
98 | struct digest_alg *digest = &tfm->__crt_alg->cra_digest; | 98 | struct digest_alg *digest = &tfm->__crt_alg->cra_digest; |
99 | 99 | ||
100 | if (unlikely((unsigned long)out & alignmask)) { | 100 | if (unlikely((unsigned long)out & alignmask)) { |
101 | unsigned long align = alignmask + 1; | 101 | unsigned long align = alignmask + 1; |
102 | unsigned long addr = (unsigned long)crypto_tfm_ctx(tfm); | 102 | unsigned long addr = (unsigned long)crypto_tfm_ctx(tfm); |
103 | u8 *dst = (u8 *)ALIGN(addr, align) + | 103 | u8 *dst = (u8 *)ALIGN(addr, align) + |
104 | ALIGN(tfm->__crt_alg->cra_ctxsize, align); | 104 | ALIGN(tfm->__crt_alg->cra_ctxsize, align); |
105 | 105 | ||
106 | digest->dia_final(tfm, dst); | 106 | digest->dia_final(tfm, dst); |
107 | memcpy(out, dst, digest->dia_digestsize); | 107 | memcpy(out, dst, digest->dia_digestsize); |
108 | } else | 108 | } else |
109 | digest->dia_final(tfm, out); | 109 | digest->dia_final(tfm, out); |
110 | 110 | ||
111 | return 0; | 111 | return 0; |
112 | } | 112 | } |
113 | 113 | ||
114 | static int nosetkey(struct crypto_hash *tfm, const u8 *key, unsigned int keylen) | 114 | static int nosetkey(struct crypto_hash *tfm, const u8 *key, unsigned int keylen) |
115 | { | 115 | { |
116 | crypto_hash_clear_flags(tfm, CRYPTO_TFM_RES_MASK); | 116 | crypto_hash_clear_flags(tfm, CRYPTO_TFM_RES_MASK); |
117 | return -ENOSYS; | 117 | return -ENOSYS; |
118 | } | 118 | } |
119 | 119 | ||
120 | static int setkey(struct crypto_hash *hash, const u8 *key, unsigned int keylen) | 120 | static int setkey(struct crypto_hash *hash, const u8 *key, unsigned int keylen) |
121 | { | 121 | { |
122 | struct crypto_tfm *tfm = crypto_hash_tfm(hash); | 122 | struct crypto_tfm *tfm = crypto_hash_tfm(hash); |
123 | 123 | ||
124 | crypto_hash_clear_flags(hash, CRYPTO_TFM_RES_MASK); | 124 | crypto_hash_clear_flags(hash, CRYPTO_TFM_RES_MASK); |
125 | return tfm->__crt_alg->cra_digest.dia_setkey(tfm, key, keylen); | 125 | return tfm->__crt_alg->cra_digest.dia_setkey(tfm, key, keylen); |
126 | } | 126 | } |
127 | 127 | ||
128 | static int digest(struct hash_desc *desc, | 128 | static int digest(struct hash_desc *desc, |
129 | struct scatterlist *sg, unsigned int nbytes, u8 *out) | 129 | struct scatterlist *sg, unsigned int nbytes, u8 *out) |
130 | { | 130 | { |
131 | if (WARN_ON_ONCE(in_irq())) | 131 | if (WARN_ON_ONCE(in_irq())) |
132 | return -EDEADLK; | 132 | return -EDEADLK; |
133 | 133 | ||
134 | init(desc); | 134 | init(desc); |
135 | update2(desc, sg, nbytes); | 135 | update2(desc, sg, nbytes); |
136 | return final(desc, out); | 136 | return final(desc, out); |
137 | } | 137 | } |
138 | 138 | ||
139 | int crypto_init_digest_ops(struct crypto_tfm *tfm) | 139 | int crypto_init_digest_ops(struct crypto_tfm *tfm) |
140 | { | 140 | { |
141 | struct hash_tfm *ops = &tfm->crt_hash; | 141 | struct hash_tfm *ops = &tfm->crt_hash; |
142 | struct digest_alg *dalg = &tfm->__crt_alg->cra_digest; | 142 | struct digest_alg *dalg = &tfm->__crt_alg->cra_digest; |
143 | 143 | ||
144 | if (dalg->dia_digestsize > crypto_tfm_alg_blocksize(tfm)) | 144 | if (dalg->dia_digestsize > crypto_tfm_alg_blocksize(tfm)) |
145 | return -EINVAL; | 145 | return -EINVAL; |
146 | 146 | ||
147 | ops->init = init; | 147 | ops->init = init; |
148 | ops->update = update; | 148 | ops->update = update; |
149 | ops->final = final; | 149 | ops->final = final; |
150 | ops->digest = digest; | 150 | ops->digest = digest; |
151 | ops->setkey = dalg->dia_setkey ? setkey : nosetkey; | 151 | ops->setkey = dalg->dia_setkey ? setkey : nosetkey; |
152 | ops->digestsize = dalg->dia_digestsize; | 152 | ops->digestsize = dalg->dia_digestsize; |
153 | 153 | ||
154 | return 0; | 154 | return 0; |
155 | } | 155 | } |
156 | 156 | ||
157 | void crypto_exit_digest_ops(struct crypto_tfm *tfm) | 157 | void crypto_exit_digest_ops(struct crypto_tfm *tfm) |
158 | { | 158 | { |
159 | } | 159 | } |
160 | 160 |
crypto/scatterwalk.c
1 | /* | 1 | /* |
2 | * Cryptographic API. | 2 | * Cryptographic API. |
3 | * | 3 | * |
4 | * Cipher operations. | 4 | * Cipher operations. |
5 | * | 5 | * |
6 | * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> | 6 | * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> |
7 | * 2002 Adam J. Richter <adam@yggdrasil.com> | 7 | * 2002 Adam J. Richter <adam@yggdrasil.com> |
8 | * 2004 Jean-Luc Cooke <jlcooke@certainkey.com> | 8 | * 2004 Jean-Luc Cooke <jlcooke@certainkey.com> |
9 | * | 9 | * |
10 | * This program is free software; you can redistribute it and/or modify it | 10 | * This program is free software; you can redistribute it and/or modify it |
11 | * under the terms of the GNU General Public License as published by the Free | 11 | * under the terms of the GNU General Public License as published by the Free |
12 | * Software Foundation; either version 2 of the License, or (at your option) | 12 | * Software Foundation; either version 2 of the License, or (at your option) |
13 | * any later version. | 13 | * any later version. |
14 | * | 14 | * |
15 | */ | 15 | */ |
16 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
17 | #include <linux/mm.h> | 17 | #include <linux/mm.h> |
18 | #include <linux/module.h> | 18 | #include <linux/module.h> |
19 | #include <linux/pagemap.h> | 19 | #include <linux/pagemap.h> |
20 | #include <linux/highmem.h> | 20 | #include <linux/highmem.h> |
21 | #include <linux/scatterlist.h> | 21 | #include <linux/scatterlist.h> |
22 | 22 | ||
23 | #include "internal.h" | 23 | #include "internal.h" |
24 | #include "scatterwalk.h" | 24 | #include "scatterwalk.h" |
25 | 25 | ||
26 | static inline void memcpy_dir(void *buf, void *sgdata, size_t nbytes, int out) | 26 | static inline void memcpy_dir(void *buf, void *sgdata, size_t nbytes, int out) |
27 | { | 27 | { |
28 | void *src = out ? buf : sgdata; | 28 | void *src = out ? buf : sgdata; |
29 | void *dst = out ? sgdata : buf; | 29 | void *dst = out ? sgdata : buf; |
30 | 30 | ||
31 | memcpy(dst, src, nbytes); | 31 | memcpy(dst, src, nbytes); |
32 | } | 32 | } |
33 | 33 | ||
34 | void scatterwalk_start(struct scatter_walk *walk, struct scatterlist *sg) | 34 | void scatterwalk_start(struct scatter_walk *walk, struct scatterlist *sg) |
35 | { | 35 | { |
36 | walk->sg = sg; | 36 | walk->sg = sg; |
37 | 37 | ||
38 | BUG_ON(!sg->length); | 38 | BUG_ON(!sg->length); |
39 | 39 | ||
40 | walk->offset = sg->offset; | 40 | walk->offset = sg->offset; |
41 | } | 41 | } |
42 | EXPORT_SYMBOL_GPL(scatterwalk_start); | 42 | EXPORT_SYMBOL_GPL(scatterwalk_start); |
43 | 43 | ||
44 | void *scatterwalk_map(struct scatter_walk *walk, int out) | 44 | void *scatterwalk_map(struct scatter_walk *walk, int out) |
45 | { | 45 | { |
46 | return crypto_kmap(scatterwalk_page(walk), out) + | 46 | return crypto_kmap(scatterwalk_page(walk), out) + |
47 | offset_in_page(walk->offset); | 47 | offset_in_page(walk->offset); |
48 | } | 48 | } |
49 | EXPORT_SYMBOL_GPL(scatterwalk_map); | 49 | EXPORT_SYMBOL_GPL(scatterwalk_map); |
50 | 50 | ||
51 | static void scatterwalk_pagedone(struct scatter_walk *walk, int out, | 51 | static void scatterwalk_pagedone(struct scatter_walk *walk, int out, |
52 | unsigned int more) | 52 | unsigned int more) |
53 | { | 53 | { |
54 | if (out) { | 54 | if (out) { |
55 | struct page *page; | 55 | struct page *page; |
56 | 56 | ||
57 | page = walk->sg->page + ((walk->offset - 1) >> PAGE_SHIFT); | 57 | page = walk->sg->page + ((walk->offset - 1) >> PAGE_SHIFT); |
58 | flush_dcache_page(page); | 58 | flush_dcache_page(page); |
59 | } | 59 | } |
60 | 60 | ||
61 | if (more) { | 61 | if (more) { |
62 | walk->offset += PAGE_SIZE - 1; | 62 | walk->offset += PAGE_SIZE - 1; |
63 | walk->offset &= PAGE_MASK; | 63 | walk->offset &= PAGE_MASK; |
64 | if (walk->offset >= walk->sg->offset + walk->sg->length) | 64 | if (walk->offset >= walk->sg->offset + walk->sg->length) |
65 | scatterwalk_start(walk, sg_next(walk->sg)); | 65 | scatterwalk_start(walk, scatterwalk_sg_next(walk->sg)); |
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
69 | void scatterwalk_done(struct scatter_walk *walk, int out, int more) | 69 | void scatterwalk_done(struct scatter_walk *walk, int out, int more) |
70 | { | 70 | { |
71 | if (!offset_in_page(walk->offset) || !more) | 71 | if (!offset_in_page(walk->offset) || !more) |
72 | scatterwalk_pagedone(walk, out, more); | 72 | scatterwalk_pagedone(walk, out, more); |
73 | } | 73 | } |
74 | EXPORT_SYMBOL_GPL(scatterwalk_done); | 74 | EXPORT_SYMBOL_GPL(scatterwalk_done); |
75 | 75 | ||
76 | void scatterwalk_copychunks(void *buf, struct scatter_walk *walk, | 76 | void scatterwalk_copychunks(void *buf, struct scatter_walk *walk, |
77 | size_t nbytes, int out) | 77 | size_t nbytes, int out) |
78 | { | 78 | { |
79 | for (;;) { | 79 | for (;;) { |
80 | unsigned int len_this_page = scatterwalk_pagelen(walk); | 80 | unsigned int len_this_page = scatterwalk_pagelen(walk); |
81 | u8 *vaddr; | 81 | u8 *vaddr; |
82 | 82 | ||
83 | if (len_this_page > nbytes) | 83 | if (len_this_page > nbytes) |
84 | len_this_page = nbytes; | 84 | len_this_page = nbytes; |
85 | 85 | ||
86 | vaddr = scatterwalk_map(walk, out); | 86 | vaddr = scatterwalk_map(walk, out); |
87 | memcpy_dir(buf, vaddr, len_this_page, out); | 87 | memcpy_dir(buf, vaddr, len_this_page, out); |
88 | scatterwalk_unmap(vaddr, out); | 88 | scatterwalk_unmap(vaddr, out); |
89 | 89 | ||
90 | scatterwalk_advance(walk, len_this_page); | 90 | scatterwalk_advance(walk, len_this_page); |
91 | 91 | ||
92 | if (nbytes == len_this_page) | 92 | if (nbytes == len_this_page) |
93 | break; | 93 | break; |
94 | 94 | ||
95 | buf += len_this_page; | 95 | buf += len_this_page; |
96 | nbytes -= len_this_page; | 96 | nbytes -= len_this_page; |
97 | 97 | ||
98 | scatterwalk_pagedone(walk, out, 1); | 98 | scatterwalk_pagedone(walk, out, 1); |
99 | } | 99 | } |
100 | } | 100 | } |
101 | EXPORT_SYMBOL_GPL(scatterwalk_copychunks); | 101 | EXPORT_SYMBOL_GPL(scatterwalk_copychunks); |
102 | 102 | ||
103 | void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg, | 103 | void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg, |
104 | unsigned int start, unsigned int nbytes, int out) | 104 | unsigned int start, unsigned int nbytes, int out) |
105 | { | 105 | { |
106 | struct scatter_walk walk; | 106 | struct scatter_walk walk; |
107 | unsigned int offset = 0; | 107 | unsigned int offset = 0; |
108 | 108 | ||
109 | for (;;) { | 109 | for (;;) { |
110 | scatterwalk_start(&walk, sg); | 110 | scatterwalk_start(&walk, sg); |
111 | 111 | ||
112 | if (start < offset + sg->length) | 112 | if (start < offset + sg->length) |
113 | break; | 113 | break; |
114 | 114 | ||
115 | offset += sg->length; | 115 | offset += sg->length; |
116 | sg = sg_next(sg); | 116 | sg = sg_next(sg); |
117 | } | 117 | } |
118 | 118 | ||
119 | scatterwalk_advance(&walk, start - offset); | 119 | scatterwalk_advance(&walk, start - offset); |
120 | scatterwalk_copychunks(buf, &walk, nbytes, out); | 120 | scatterwalk_copychunks(buf, &walk, nbytes, out); |
121 | scatterwalk_done(&walk, out, 0); | 121 | scatterwalk_done(&walk, out, 0); |
122 | } | 122 | } |
123 | EXPORT_SYMBOL_GPL(scatterwalk_map_and_copy); | 123 | EXPORT_SYMBOL_GPL(scatterwalk_map_and_copy); |
124 | 124 |
crypto/scatterwalk.h
1 | /* | 1 | /* |
2 | * Cryptographic API. | 2 | * Cryptographic API. |
3 | * | 3 | * |
4 | * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> | 4 | * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> |
5 | * Copyright (c) 2002 Adam J. Richter <adam@yggdrasil.com> | 5 | * Copyright (c) 2002 Adam J. Richter <adam@yggdrasil.com> |
6 | * Copyright (c) 2004 Jean-Luc Cooke <jlcooke@certainkey.com> | 6 | * Copyright (c) 2004 Jean-Luc Cooke <jlcooke@certainkey.com> |
7 | * | 7 | * |
8 | * This program is free software; you can redistribute it and/or modify it | 8 | * This program is free software; you can redistribute it and/or modify it |
9 | * under the terms of the GNU General Public License as published by the Free | 9 | * under the terms of the GNU General Public License as published by the Free |
10 | * Software Foundation; either version 2 of the License, or (at your option) | 10 | * Software Foundation; either version 2 of the License, or (at your option) |
11 | * any later version. | 11 | * any later version. |
12 | * | 12 | * |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #ifndef _CRYPTO_SCATTERWALK_H | 15 | #ifndef _CRYPTO_SCATTERWALK_H |
16 | #define _CRYPTO_SCATTERWALK_H | 16 | #define _CRYPTO_SCATTERWALK_H |
17 | 17 | ||
18 | #include <linux/mm.h> | 18 | #include <linux/mm.h> |
19 | #include <linux/scatterlist.h> | 19 | #include <linux/scatterlist.h> |
20 | 20 | ||
21 | #include "internal.h" | 21 | #include "internal.h" |
22 | 22 | ||
23 | static inline struct scatterlist *sg_next(struct scatterlist *sg) | 23 | static inline struct scatterlist *scatterwalk_sg_next(struct scatterlist *sg) |
24 | { | 24 | { |
25 | return (++sg)->length ? sg : (void *)sg->page; | 25 | return (++sg)->length ? sg : (void *)sg->page; |
26 | } | 26 | } |
27 | 27 | ||
28 | static inline unsigned long scatterwalk_samebuf(struct scatter_walk *walk_in, | 28 | static inline unsigned long scatterwalk_samebuf(struct scatter_walk *walk_in, |
29 | struct scatter_walk *walk_out) | 29 | struct scatter_walk *walk_out) |
30 | { | 30 | { |
31 | return !(((walk_in->sg->page - walk_out->sg->page) << PAGE_SHIFT) + | 31 | return !(((walk_in->sg->page - walk_out->sg->page) << PAGE_SHIFT) + |
32 | (int)(walk_in->offset - walk_out->offset)); | 32 | (int)(walk_in->offset - walk_out->offset)); |
33 | } | 33 | } |
34 | 34 | ||
35 | static inline unsigned int scatterwalk_pagelen(struct scatter_walk *walk) | 35 | static inline unsigned int scatterwalk_pagelen(struct scatter_walk *walk) |
36 | { | 36 | { |
37 | unsigned int len = walk->sg->offset + walk->sg->length - walk->offset; | 37 | unsigned int len = walk->sg->offset + walk->sg->length - walk->offset; |
38 | unsigned int len_this_page = offset_in_page(~walk->offset) + 1; | 38 | unsigned int len_this_page = offset_in_page(~walk->offset) + 1; |
39 | return len_this_page > len ? len : len_this_page; | 39 | return len_this_page > len ? len : len_this_page; |
40 | } | 40 | } |
41 | 41 | ||
42 | static inline unsigned int scatterwalk_clamp(struct scatter_walk *walk, | 42 | static inline unsigned int scatterwalk_clamp(struct scatter_walk *walk, |
43 | unsigned int nbytes) | 43 | unsigned int nbytes) |
44 | { | 44 | { |
45 | unsigned int len_this_page = scatterwalk_pagelen(walk); | 45 | unsigned int len_this_page = scatterwalk_pagelen(walk); |
46 | return nbytes > len_this_page ? len_this_page : nbytes; | 46 | return nbytes > len_this_page ? len_this_page : nbytes; |
47 | } | 47 | } |
48 | 48 | ||
49 | static inline void scatterwalk_advance(struct scatter_walk *walk, | 49 | static inline void scatterwalk_advance(struct scatter_walk *walk, |
50 | unsigned int nbytes) | 50 | unsigned int nbytes) |
51 | { | 51 | { |
52 | walk->offset += nbytes; | 52 | walk->offset += nbytes; |
53 | } | 53 | } |
54 | 54 | ||
55 | static inline unsigned int scatterwalk_aligned(struct scatter_walk *walk, | 55 | static inline unsigned int scatterwalk_aligned(struct scatter_walk *walk, |
56 | unsigned int alignmask) | 56 | unsigned int alignmask) |
57 | { | 57 | { |
58 | return !(walk->offset & alignmask); | 58 | return !(walk->offset & alignmask); |
59 | } | 59 | } |
60 | 60 | ||
61 | static inline struct page *scatterwalk_page(struct scatter_walk *walk) | 61 | static inline struct page *scatterwalk_page(struct scatter_walk *walk) |
62 | { | 62 | { |
63 | return walk->sg->page + (walk->offset >> PAGE_SHIFT); | 63 | return walk->sg->page + (walk->offset >> PAGE_SHIFT); |
64 | } | 64 | } |
65 | 65 | ||
66 | static inline void scatterwalk_unmap(void *vaddr, int out) | 66 | static inline void scatterwalk_unmap(void *vaddr, int out) |
67 | { | 67 | { |
68 | crypto_kunmap(vaddr, out); | 68 | crypto_kunmap(vaddr, out); |
69 | } | 69 | } |
70 | 70 | ||
71 | void scatterwalk_start(struct scatter_walk *walk, struct scatterlist *sg); | 71 | void scatterwalk_start(struct scatter_walk *walk, struct scatterlist *sg); |
72 | void scatterwalk_copychunks(void *buf, struct scatter_walk *walk, | 72 | void scatterwalk_copychunks(void *buf, struct scatter_walk *walk, |
73 | size_t nbytes, int out); | 73 | size_t nbytes, int out); |
74 | void *scatterwalk_map(struct scatter_walk *walk, int out); | 74 | void *scatterwalk_map(struct scatter_walk *walk, int out); |
75 | void scatterwalk_done(struct scatter_walk *walk, int out, int more); | 75 | void scatterwalk_done(struct scatter_walk *walk, int out, int more); |
76 | 76 | ||
77 | void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg, | 77 | void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg, |
78 | unsigned int start, unsigned int nbytes, int out); | 78 | unsigned int start, unsigned int nbytes, int out); |
79 | 79 | ||
80 | #endif /* _CRYPTO_SCATTERWALK_H */ | 80 | #endif /* _CRYPTO_SCATTERWALK_H */ |
81 | 81 |