Skip to content

Commit 7061378

Browse files
herbertxDavid S. Miller
authored andcommitted
[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 <[email protected]>
1 parent e4c5c6c commit 7061378

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

crypto/algapi.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ static int crypto_check_alg(struct crypto_alg *alg)
6363
if (alg->cra_alignmask & (alg->cra_alignmask + 1))
6464
return -EINVAL;
6565

66-
if (alg->cra_alignmask & alg->cra_blocksize)
67-
return -EINVAL;
68-
6966
if (alg->cra_blocksize > PAGE_SIZE / 8)
7067
return -EINVAL;
7168

crypto/blkcipher.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ static inline int blkcipher_next_slow(struct blkcipher_desc *desc,
149149
unsigned int alignmask)
150150
{
151151
unsigned int n;
152+
unsigned aligned_bsize = ALIGN(bsize, alignmask + 1);
152153

153154
if (walk->buffer)
154155
goto ok;
@@ -167,8 +168,8 @@ static inline int blkcipher_next_slow(struct blkcipher_desc *desc,
167168
walk->dst.virt.addr = (u8 *)ALIGN((unsigned long)walk->buffer,
168169
alignmask + 1);
169170
walk->dst.virt.addr = blkcipher_get_spot(walk->dst.virt.addr, bsize);
170-
walk->src.virt.addr = blkcipher_get_spot(walk->dst.virt.addr + bsize,
171-
bsize);
171+
walk->src.virt.addr = blkcipher_get_spot(walk->dst.virt.addr +
172+
aligned_bsize, bsize);
172173

173174
scatterwalk_copychunks(walk->src.virt.addr, &walk->in, bsize, 0);
174175

@@ -278,7 +279,9 @@ static inline int blkcipher_copy_iv(struct blkcipher_walk *walk,
278279
{
279280
unsigned bs = crypto_blkcipher_blocksize(tfm);
280281
unsigned int ivsize = crypto_blkcipher_ivsize(tfm);
281-
unsigned int size = bs * 2 + ivsize + max(bs, ivsize) - (alignmask + 1);
282+
unsigned aligned_bs = ALIGN(bs, alignmask + 1);
283+
unsigned int size = aligned_bs * 2 + ivsize + max(aligned_bs, ivsize) -
284+
(alignmask + 1);
282285
u8 *iv;
283286

284287
size += alignmask & ~(crypto_tfm_ctx_alignment() - 1);
@@ -287,8 +290,8 @@ static inline int blkcipher_copy_iv(struct blkcipher_walk *walk,
287290
return -ENOMEM;
288291

289292
iv = (u8 *)ALIGN((unsigned long)walk->buffer, alignmask + 1);
290-
iv = blkcipher_get_spot(iv, bs) + bs;
291-
iv = blkcipher_get_spot(iv, bs) + bs;
293+
iv = blkcipher_get_spot(iv, bs) + aligned_bs;
294+
iv = blkcipher_get_spot(iv, bs) + aligned_bs;
292295
iv = blkcipher_get_spot(iv, ivsize);
293296

294297
walk->iv = memcpy(iv, walk->iv, ivsize);

0 commit comments

Comments
 (0)