Skip to content

Commit 2d506d4

Browse files
sebastianasherbertx
authored andcommitted
[CRYPTO] geode: use consistent IV copy
It is enough if the IV is copied before and after the while loop. With DM-Crypt is seems not be required to save the IV after encrytion because a new one is used in the request (dunno about other users). It is not save to load the IV within while loop and not save afterwards because we mill end up with the wrong IV if the request goes consists of more than one page. Signed-off-by: Sebastian Siewior <sebastian@breakpoint.cc> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 89e1265 commit 2d506d4

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

‎drivers/crypto/geode-aes.c‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ geode_cbc_decrypt(struct blkcipher_desc *desc,
226226

227227
blkcipher_walk_init(&walk, dst, src, nbytes);
228228
err = blkcipher_walk_virt(desc, &walk);
229+
memcpy(op->iv, walk.iv, AES_IV_LENGTH);
229230

230231
while((nbytes = walk.nbytes)) {
231232
op->src = walk.src.virt.addr,
@@ -234,16 +235,13 @@ geode_cbc_decrypt(struct blkcipher_desc *desc,
234235
op->len = nbytes - (nbytes % AES_MIN_BLOCK_SIZE);
235236
op->dir = AES_DIR_DECRYPT;
236237

237-
memcpy(op->iv, walk.iv, AES_IV_LENGTH);
238-
239238
ret = geode_aes_crypt(op);
240239

241-
memcpy(walk.iv, op->iv, AES_IV_LENGTH);
242240
nbytes -= ret;
243-
244241
err = blkcipher_walk_done(desc, &walk, nbytes);
245242
}
246243

244+
memcpy(walk.iv, op->iv, AES_IV_LENGTH);
247245
return err;
248246
}
249247

@@ -258,6 +256,7 @@ geode_cbc_encrypt(struct blkcipher_desc *desc,
258256

259257
blkcipher_walk_init(&walk, dst, src, nbytes);
260258
err = blkcipher_walk_virt(desc, &walk);
259+
memcpy(op->iv, walk.iv, AES_IV_LENGTH);
261260

262261
while((nbytes = walk.nbytes)) {
263262
op->src = walk.src.virt.addr,
@@ -266,13 +265,12 @@ geode_cbc_encrypt(struct blkcipher_desc *desc,
266265
op->len = nbytes - (nbytes % AES_MIN_BLOCK_SIZE);
267266
op->dir = AES_DIR_ENCRYPT;
268267

269-
memcpy(op->iv, walk.iv, AES_IV_LENGTH);
270-
271268
ret = geode_aes_crypt(op);
272269
nbytes -= ret;
273270
err = blkcipher_walk_done(desc, &walk, nbytes);
274271
}
275272

273+
memcpy(walk.iv, op->iv, AES_IV_LENGTH);
276274
return err;
277275
}
278276

0 commit comments

Comments
 (0)