X-Git-Url: https://git.openpandora.org/cgi-bin/gitweb.cgi?p=pandora-kernel.git;a=blobdiff_plain;f=crypto%2Fcipher.c;h=65bcea0cd17c867ae88dde90aefc9e137ebd3259;hp=3df47f93c9db01e0a19da8af237ab800ae9d34b1;hb=ba47f66bd9fc451e9ce88f291e057b2f4910d01c;hpb=64baf3cfea974d2b9e671ccfdbc03e030ea5ebc6 diff --git a/crypto/cipher.c b/crypto/cipher.c index 3df47f93c9db..65bcea0cd17c 100644 --- a/crypto/cipher.c +++ b/crypto/cipher.c @@ -191,6 +191,8 @@ static unsigned int cbc_process_encrypt(const struct cipher_desc *desc, u8 *iv = desc->info; unsigned int done = 0; + nbytes -= bsize; + do { xor(iv, src); fn(crypto_tfm_ctx(tfm), dst, iv); @@ -198,7 +200,7 @@ static unsigned int cbc_process_encrypt(const struct cipher_desc *desc, src += bsize; dst += bsize; - } while ((done += bsize) < nbytes); + } while ((done += bsize) <= nbytes); return done; } @@ -210,15 +212,18 @@ static unsigned int cbc_process_decrypt(const struct cipher_desc *desc, struct crypto_tfm *tfm = desc->tfm; void (*xor)(u8 *, const u8 *) = tfm->crt_u.cipher.cit_xor_block; int bsize = crypto_tfm_alg_blocksize(tfm); + unsigned long alignmask = crypto_tfm_alg_alignmask(desc->tfm); - u8 stack[src == dst ? bsize : 0]; - u8 *buf = stack; + u8 stack[src == dst ? bsize + alignmask : 0]; + u8 *buf = (u8 *)ALIGN((unsigned long)stack, alignmask + 1); u8 **dst_p = src == dst ? &buf : &dst; void (*fn)(void *, u8 *, const u8 *) = desc->crfn; u8 *iv = desc->info; unsigned int done = 0; + nbytes -= bsize; + do { u8 *tmp_dst = *dst_p; @@ -230,7 +235,7 @@ static unsigned int cbc_process_decrypt(const struct cipher_desc *desc, src += bsize; dst += bsize; - } while ((done += bsize) < nbytes); + } while ((done += bsize) <= nbytes); return done; } @@ -243,12 +248,14 @@ static unsigned int ecb_process(const struct cipher_desc *desc, u8 *dst, void (*fn)(void *, u8 *, const u8 *) = desc->crfn; unsigned int done = 0; + nbytes -= bsize; + do { fn(crypto_tfm_ctx(tfm), dst, src); src += bsize; dst += bsize; - } while ((done += bsize) < nbytes); + } while ((done += bsize) <= nbytes); return done; }