X-Git-Url: https://git.karo-electronics.de/?a=blobdiff_plain;f=crypto%2Fblkcipher.c;h=d8f8ec320213a4fc4656ad9340b30ddc904328a0;hb=b2315372eac9cd9f622c32a93e323cf6f0f03462;hp=40a3dcff15bb89a95ffc4377eb22dc1e24f46e6c;hpb=2e85622042cb5fd56a606e884651ffde52f21028;p=karo-tx-linux.git diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c index 40a3dcff15bb..d8f8ec320213 100644 --- a/crypto/blkcipher.c +++ b/crypto/blkcipher.c @@ -59,11 +59,13 @@ static inline void blkcipher_unmap_dst(struct blkcipher_walk *walk) scatterwalk_unmap(walk->dst.virt.addr, 1); } +/* Get a spot of the specified length that does not straddle a page. + * The caller needs to ensure that there is enough space for this operation. + */ static inline u8 *blkcipher_get_spot(u8 *start, unsigned int len) { - if (offset_in_page(start + len) < len) - return (u8 *)((unsigned long)(start + len) & PAGE_MASK); - return start; + u8 *end_page = (u8 *)(((unsigned long)(start + len - 1)) & PAGE_MASK); + return start > end_page ? start : end_page; } static inline unsigned int blkcipher_done_slow(struct crypto_blkcipher *tfm, @@ -155,7 +157,8 @@ static inline int blkcipher_next_slow(struct blkcipher_desc *desc, if (walk->buffer) goto ok; - n = bsize * 2 + (alignmask & ~(crypto_tfm_ctx_alignment() - 1)); + n = bsize * 3 - (alignmask + 1) + + (alignmask & ~(crypto_tfm_ctx_alignment() - 1)); walk->buffer = kmalloc(n, GFP_ATOMIC); if (!walk->buffer) return blkcipher_walk_done(desc, walk, -ENOMEM); @@ -352,7 +355,7 @@ static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key, unsigned int alignbuffer = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1); memcpy(alignbuffer, key, keylen); ret = cipher->setkey(tfm, alignbuffer, keylen); - memset(alignbuffer, 0, absize); + memset(alignbuffer, 0, keylen); kfree(buffer); return ret; }