diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2006-08-12 07:56:17 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2006-09-20 21:41:52 -0400 |
commit | 5c64097aa0f6dc4f27718ef47ca9a12538d62860 (patch) | |
tree | d8c0cd3358464f589c9f2778b7be348f73db6950 /crypto/scatterwalk.h | |
parent | f28776a369b12f9a03a822a8e1090ed670a41f4f (diff) |
[CRYPTO] scatterwalk: Prepare for block ciphers
This patch prepares the scatterwalk code for use by the new block cipher
type.
Firstly it halves the size of scatter_walk on 32-bit platforms. This
is important as we allocate at least two of these objects on the stack
for each block cipher operation.
It also exports the symbols since the block cipher code can be built as
a module.
Finally there is a hack in scatterwalk_unmap that relies on progress
being made. Unfortunately, for hardware crypto we can't guarantee
progress to be made since the hardware can fail.
So this also gets rid of the hack by not advancing the address returned
by scatterwalk_map.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/scatterwalk.h')
-rw-r--r-- | crypto/scatterwalk.h | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/crypto/scatterwalk.h b/crypto/scatterwalk.h index e79925c474a3..ace595a2e119 100644 --- a/crypto/scatterwalk.h +++ b/crypto/scatterwalk.h | |||
@@ -14,17 +14,11 @@ | |||
14 | 14 | ||
15 | #ifndef _CRYPTO_SCATTERWALK_H | 15 | #ifndef _CRYPTO_SCATTERWALK_H |
16 | #define _CRYPTO_SCATTERWALK_H | 16 | #define _CRYPTO_SCATTERWALK_H |
17 | |||
17 | #include <linux/mm.h> | 18 | #include <linux/mm.h> |
18 | #include <asm/scatterlist.h> | 19 | #include <linux/scatterlist.h> |
19 | 20 | ||
20 | struct scatter_walk { | 21 | #include "internal.h" |
21 | struct scatterlist *sg; | ||
22 | struct page *page; | ||
23 | void *data; | ||
24 | unsigned int len_this_page; | ||
25 | unsigned int len_this_segment; | ||
26 | unsigned int offset; | ||
27 | }; | ||
28 | 22 | ||
29 | /* Define sg_next is an inline routine now in case we want to change | 23 | /* Define sg_next is an inline routine now in case we want to change |
30 | scatterlist to a linked list later. */ | 24 | scatterlist to a linked list later. */ |
@@ -33,26 +27,31 @@ static inline struct scatterlist *sg_next(struct scatterlist *sg) | |||
33 | return sg + 1; | 27 | return sg + 1; |
34 | } | 28 | } |
35 | 29 | ||
36 | static inline int scatterwalk_samebuf(struct scatter_walk *walk_in, | 30 | static inline unsigned long scatterwalk_samebuf(struct scatter_walk *walk_in, |
37 | struct scatter_walk *walk_out) | 31 | struct scatter_walk *walk_out) |
38 | { | 32 | { |
39 | return walk_in->page == walk_out->page && | 33 | return !(((walk_in->sg->page - walk_out->sg->page) << PAGE_SHIFT) + |
40 | walk_in->offset == walk_out->offset; | 34 | (int)(walk_in->offset - walk_out->offset)); |
35 | } | ||
36 | |||
37 | static inline unsigned int scatterwalk_pagelen(struct scatter_walk *walk) | ||
38 | { | ||
39 | unsigned int len = walk->sg->offset + walk->sg->length - walk->offset; | ||
40 | unsigned int len_this_page = offset_in_page(~walk->offset) + 1; | ||
41 | return len_this_page > len ? len : len_this_page; | ||
41 | } | 42 | } |
42 | 43 | ||
43 | static inline unsigned int scatterwalk_clamp(struct scatter_walk *walk, | 44 | static inline unsigned int scatterwalk_clamp(struct scatter_walk *walk, |
44 | unsigned int nbytes) | 45 | unsigned int nbytes) |
45 | { | 46 | { |
46 | return nbytes > walk->len_this_page ? walk->len_this_page : nbytes; | 47 | unsigned int len_this_page = scatterwalk_pagelen(walk); |
48 | return nbytes > len_this_page ? len_this_page : nbytes; | ||
47 | } | 49 | } |
48 | 50 | ||
49 | static inline void scatterwalk_advance(struct scatter_walk *walk, | 51 | static inline void scatterwalk_advance(struct scatter_walk *walk, |
50 | unsigned int nbytes) | 52 | unsigned int nbytes) |
51 | { | 53 | { |
52 | walk->data += nbytes; | ||
53 | walk->offset += nbytes; | 54 | walk->offset += nbytes; |
54 | walk->len_this_page -= nbytes; | ||
55 | walk->len_this_segment -= nbytes; | ||
56 | } | 55 | } |
57 | 56 | ||
58 | static inline unsigned int scatterwalk_aligned(struct scatter_walk *walk, | 57 | static inline unsigned int scatterwalk_aligned(struct scatter_walk *walk, |
@@ -61,9 +60,20 @@ static inline unsigned int scatterwalk_aligned(struct scatter_walk *walk, | |||
61 | return !(walk->offset & alignmask); | 60 | return !(walk->offset & alignmask); |
62 | } | 61 | } |
63 | 62 | ||
63 | static inline struct page *scatterwalk_page(struct scatter_walk *walk) | ||
64 | { | ||
65 | return walk->sg->page + (walk->offset >> PAGE_SHIFT); | ||
66 | } | ||
67 | |||
68 | static inline void scatterwalk_unmap(void *vaddr, int out) | ||
69 | { | ||
70 | crypto_kunmap(vaddr, out); | ||
71 | } | ||
72 | |||
64 | void scatterwalk_start(struct scatter_walk *walk, struct scatterlist *sg); | 73 | void scatterwalk_start(struct scatter_walk *walk, struct scatterlist *sg); |
65 | int scatterwalk_copychunks(void *buf, struct scatter_walk *walk, size_t nbytes, int out); | 74 | void scatterwalk_copychunks(void *buf, struct scatter_walk *walk, |
66 | void scatterwalk_map(struct scatter_walk *walk, int out); | 75 | size_t nbytes, int out); |
76 | void *scatterwalk_map(struct scatter_walk *walk, int out); | ||
67 | void scatterwalk_done(struct scatter_walk *walk, int out, int more); | 77 | void scatterwalk_done(struct scatter_walk *walk, int out, int more); |
68 | 78 | ||
69 | #endif /* _CRYPTO_SCATTERWALK_H */ | 79 | #endif /* _CRYPTO_SCATTERWALK_H */ |