Signed-off-by: Sebastian Siewior <sebastian@xxxxxxxxxxxxx> --- crypto/cbc.c | 22 +++++++++++++--------- crypto/ecb.c | 7 ++++--- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/crypto/cbc.c b/crypto/cbc.c index a525dcc..15c8095 100644 --- a/crypto/cbc.c +++ b/crypto/cbc.c @@ -50,17 +50,18 @@ static int crypto_cbc_encrypt_segment(struct blkcipher_desc *desc, u8 *src = walk->src.virt.addr; u8 *dst = walk->dst.virt.addr; u8 *iv = walk->iv; + int ret; do { crypto_xor(iv, src, bsize); - fn(crypto_cipher_tfm(tfm), dst, iv); + ret = fn(crypto_cipher_tfm(tfm), dst, iv); memcpy(iv, dst, bsize); src += bsize; dst += bsize; - } while ((nbytes -= bsize) >= bsize); + } while (!ret && (nbytes -= bsize) >= bsize); - return nbytes; + return nbytes ? nbytes : ret; } static int crypto_cbc_encrypt_inplace(struct blkcipher_desc *desc, @@ -73,14 +74,15 @@ static int crypto_cbc_encrypt_inplace(struct blkcipher_desc *desc, unsigned int nbytes = walk->nbytes; u8 *src = walk->src.virt.addr; u8 *iv = walk->iv; + int ret; do { crypto_xor(src, iv, bsize); - fn(crypto_cipher_tfm(tfm), src, src); + ret = fn(crypto_cipher_tfm(tfm), src, src); iv = src; src += bsize; - } while ((nbytes -= bsize) >= bsize); + } while (!ret && (nbytes -= bsize) >= bsize); memcpy(walk->iv, iv, bsize); @@ -122,15 +124,16 @@ static int crypto_cbc_decrypt_segment(struct blkcipher_desc *desc, u8 *src = walk->src.virt.addr; u8 *dst = walk->dst.virt.addr; u8 *iv = walk->iv; + int ret; do { - fn(crypto_cipher_tfm(tfm), dst, src); + ret = fn(crypto_cipher_tfm(tfm), dst, src); crypto_xor(dst, iv, bsize); iv = src; src += bsize; dst += bsize; - } while ((nbytes -= bsize) >= bsize); + } while (!ret && (nbytes -= bsize) >= bsize); memcpy(walk->iv, iv, bsize); @@ -147,14 +150,15 @@ static int crypto_cbc_decrypt_inplace(struct blkcipher_desc *desc, unsigned int nbytes = walk->nbytes; u8 *src = walk->src.virt.addr; u8 last_iv[bsize]; + int ret; /* Start of the last block. */ src += nbytes - (nbytes & (bsize - 1)) - bsize; memcpy(last_iv, src, bsize); for (;;) { - fn(crypto_cipher_tfm(tfm), src, src); - if ((nbytes -= bsize) < bsize) + ret = fn(crypto_cipher_tfm(tfm), src, src); + if (ret || (nbytes -= bsize) < bsize) break; crypto_xor(src, src - bsize, bsize); src -= bsize; diff --git a/crypto/ecb.c b/crypto/ecb.c index 1edb94f..04a5083 100644 --- a/crypto/ecb.c +++ b/crypto/ecb.c @@ -46,6 +46,7 @@ static int crypto_ecb_crypt(struct blkcipher_desc *desc, int bsize = crypto_cipher_blocksize(tfm); unsigned int nbytes; int err; + int ret = 0; err = blkcipher_walk_virt(desc, walk); @@ -54,16 +55,16 @@ static int crypto_ecb_crypt(struct blkcipher_desc *desc, u8 *wdst = walk->dst.virt.addr; do { - fn(crypto_cipher_tfm(tfm), wdst, wsrc); + ret = fn(crypto_cipher_tfm(tfm), wdst, wsrc); wsrc += bsize; wdst += bsize; - } while ((nbytes -= bsize) >= bsize); + } while ((nbytes -= bsize) >= bsize && !ret); err = blkcipher_walk_done(desc, walk, nbytes); } - return err; + return err ? err : ret; } static int crypto_ecb_encrypt(struct blkcipher_desc *desc, -- 1.5.3.6 - To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html