Commit 70613783fc0f6e37b442d79e8417f71a2b71ed93

Authored by Herbert Xu
Committed by David S. Miller
1 parent e4c5c6c9b0

[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>

Showing 2 changed files with 8 additions and 8 deletions Side-by-side Diff

... ... @@ -63,9 +63,6 @@
63 63 if (alg->cra_alignmask & (alg->cra_alignmask + 1))
64 64 return -EINVAL;
65 65  
66   - if (alg->cra_alignmask & alg->cra_blocksize)
67   - return -EINVAL;
68   -
69 66 if (alg->cra_blocksize > PAGE_SIZE / 8)
70 67 return -EINVAL;
71 68  
... ... @@ -149,6 +149,7 @@
149 149 unsigned int alignmask)
150 150 {
151 151 unsigned int n;
  152 + unsigned aligned_bsize = ALIGN(bsize, alignmask + 1);
152 153  
153 154 if (walk->buffer)
154 155 goto ok;
... ... @@ -167,8 +168,8 @@
167 168 walk->dst.virt.addr = (u8 *)ALIGN((unsigned long)walk->buffer,
168 169 alignmask + 1);
169 170 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);
172 173  
173 174 scatterwalk_copychunks(walk->src.virt.addr, &walk->in, bsize, 0);
174 175  
... ... @@ -278,7 +279,9 @@
278 279 {
279 280 unsigned bs = crypto_blkcipher_blocksize(tfm);
280 281 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);
282 285 u8 *iv;
283 286  
284 287 size += alignmask & ~(crypto_tfm_ctx_alignment() - 1);
... ... @@ -287,8 +290,8 @@
287 290 return -ENOMEM;
288 291  
289 292 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;
292 295 iv = blkcipher_get_spot(iv, ivsize);
293 296  
294 297 walk->iv = memcpy(iv, walk->iv, ivsize);