diff options
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/cipher.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/crypto/cipher.c b/crypto/cipher.c index 3df47f93c9db..dfd4bcfc5975 100644 --- a/crypto/cipher.c +++ b/crypto/cipher.c | |||
@@ -191,6 +191,8 @@ static unsigned int cbc_process_encrypt(const struct cipher_desc *desc, | |||
191 | u8 *iv = desc->info; | 191 | u8 *iv = desc->info; |
192 | unsigned int done = 0; | 192 | unsigned int done = 0; |
193 | 193 | ||
194 | nbytes -= bsize; | ||
195 | |||
194 | do { | 196 | do { |
195 | xor(iv, src); | 197 | xor(iv, src); |
196 | fn(crypto_tfm_ctx(tfm), dst, iv); | 198 | fn(crypto_tfm_ctx(tfm), dst, iv); |
@@ -198,7 +200,7 @@ static unsigned int cbc_process_encrypt(const struct cipher_desc *desc, | |||
198 | 200 | ||
199 | src += bsize; | 201 | src += bsize; |
200 | dst += bsize; | 202 | dst += bsize; |
201 | } while ((done += bsize) < nbytes); | 203 | } while ((done += bsize) <= nbytes); |
202 | 204 | ||
203 | return done; | 205 | return done; |
204 | } | 206 | } |
@@ -219,6 +221,8 @@ static unsigned int cbc_process_decrypt(const struct cipher_desc *desc, | |||
219 | u8 *iv = desc->info; | 221 | u8 *iv = desc->info; |
220 | unsigned int done = 0; | 222 | unsigned int done = 0; |
221 | 223 | ||
224 | nbytes -= bsize; | ||
225 | |||
222 | do { | 226 | do { |
223 | u8 *tmp_dst = *dst_p; | 227 | u8 *tmp_dst = *dst_p; |
224 | 228 | ||
@@ -230,7 +234,7 @@ static unsigned int cbc_process_decrypt(const struct cipher_desc *desc, | |||
230 | 234 | ||
231 | src += bsize; | 235 | src += bsize; |
232 | dst += bsize; | 236 | dst += bsize; |
233 | } while ((done += bsize) < nbytes); | 237 | } while ((done += bsize) <= nbytes); |
234 | 238 | ||
235 | return done; | 239 | return done; |
236 | } | 240 | } |
@@ -243,12 +247,14 @@ static unsigned int ecb_process(const struct cipher_desc *desc, u8 *dst, | |||
243 | void (*fn)(void *, u8 *, const u8 *) = desc->crfn; | 247 | void (*fn)(void *, u8 *, const u8 *) = desc->crfn; |
244 | unsigned int done = 0; | 248 | unsigned int done = 0; |
245 | 249 | ||
250 | nbytes -= bsize; | ||
251 | |||
246 | do { | 252 | do { |
247 | fn(crypto_tfm_ctx(tfm), dst, src); | 253 | fn(crypto_tfm_ctx(tfm), dst, src); |
248 | 254 | ||
249 | src += bsize; | 255 | src += bsize; |
250 | dst += bsize; | 256 | dst += bsize; |
251 | } while ((done += bsize) < nbytes); | 257 | } while ((done += bsize) <= nbytes); |
252 | 258 | ||
253 | return done; | 259 | return done; |
254 | } | 260 | } |