summaryrefslogtreecommitdiffstats
path: root/crypto/blkcipher.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2007-09-29 21:24:23 +0800
committerDavid S. Miller <davem@sunset.davemloft.net>2007-10-10 16:55:46 -0700
commit70613783fc0f6e37b442d79e8417f71a2b71ed93 (patch)
tree94cf5beb318c16e608fb7e03d4eed7decaaeefc1 /crypto/blkcipher.c
parente4c5c6c9b0d04a7dac19027260f7421305a34856 (diff)
downloadlinux-stable-70613783fc0f6e37b442d79e8417f71a2b71ed93.tar.gz
linux-stable-70613783fc0f6e37b442d79e8417f71a2b71ed93.tar.bz2
linux-stable-70613783fc0f6e37b442d79e8417f71a2b71ed93.zip
[CRYPTO] blkcipher: Remove alignment restriction on block size
Previously we assumed for convenience that the block size is a multiple of the algorithm's required alignment. With the pending addition of CTR this will no longer be the case as the block size will be 1 due to it being a stream cipher. However, the alignment requirement will be that of the underlying implementation which will most likely be greater than 1. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/blkcipher.c')
-rw-r--r--crypto/blkcipher.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c
index 9c49770837c2..a3c87da23f1e 100644
--- a/crypto/blkcipher.c
+++ b/crypto/blkcipher.c
@@ -149,6 +149,7 @@ static inline int blkcipher_next_slow(struct blkcipher_desc *desc,
unsigned int alignmask)
{
unsigned int n;
+ unsigned aligned_bsize = ALIGN(bsize, alignmask + 1);
if (walk->buffer)
goto ok;
@@ -167,8 +168,8 @@ ok:
walk->dst.virt.addr = (u8 *)ALIGN((unsigned long)walk->buffer,
alignmask + 1);
walk->dst.virt.addr = blkcipher_get_spot(walk->dst.virt.addr, bsize);
- walk->src.virt.addr = blkcipher_get_spot(walk->dst.virt.addr + bsize,
- bsize);
+ walk->src.virt.addr = blkcipher_get_spot(walk->dst.virt.addr +
+ aligned_bsize, bsize);
scatterwalk_copychunks(walk->src.virt.addr, &walk->in, bsize, 0);
@@ -278,7 +279,9 @@ static inline int blkcipher_copy_iv(struct blkcipher_walk *walk,
{
unsigned bs = crypto_blkcipher_blocksize(tfm);
unsigned int ivsize = crypto_blkcipher_ivsize(tfm);
- unsigned int size = bs * 2 + ivsize + max(bs, ivsize) - (alignmask + 1);
+ unsigned aligned_bs = ALIGN(bs, alignmask + 1);
+ unsigned int size = aligned_bs * 2 + ivsize + max(aligned_bs, ivsize) -
+ (alignmask + 1);
u8 *iv;
size += alignmask & ~(crypto_tfm_ctx_alignment() - 1);
@@ -287,8 +290,8 @@ static inline int blkcipher_copy_iv(struct blkcipher_walk *walk,
return -ENOMEM;
iv = (u8 *)ALIGN((unsigned long)walk->buffer, alignmask + 1);
- iv = blkcipher_get_spot(iv, bs) + bs;
- iv = blkcipher_get_spot(iv, bs) + bs;
+ iv = blkcipher_get_spot(iv, bs) + aligned_bs;
+ iv = blkcipher_get_spot(iv, bs) + aligned_bs;
iv = blkcipher_get_spot(iv, ivsize);
walk->iv = memcpy(iv, walk->iv, ivsize);