diff options
author | Niels Möller <nisse@lysator.liu.se> | 2018-01-08 08:06:18 +0100 |
---|---|---|
committer | Niels Möller <nisse@lysator.liu.se> | 2018-01-08 08:06:50 +0100 |
commit | 140156d1e44867212f4ebd691db2dc5efe41a15c (patch) | |
tree | 7defa7a4d8ecd220a668189f7f3d5158bf3cfdda /cbc.c | |
parent | db9b8594e4caa5459483359567fd077025a0cb65 (diff) | |
download | nettle-140156d1e44867212f4ebd691db2dc5efe41a15c.tar.gz |
Tweaks for in-place cbc, cfb and gcm.
* cbc.c (cbc_decrypt): For in-place operation (src == dst case),
eliminate use of src variable.
* cfb.c (cfb_decrypt): Likewise.
* gcm.c (gcm_crypt): Likewise, and replace one memxor3 by memxor.
Diffstat (limited to 'cbc.c')
-rw-r--r-- | cbc.c | 15 |
1 files changed, 7 insertions, 8 deletions
@@ -109,23 +109,22 @@ cbc_decrypt(const void *ctx, nettle_cipher_func *f, TMP_ALLOC(buffer, buffer_size); TMP_ALLOC(initial_iv, block_size); - for ( ; length > buffer_size; - length -= buffer_size, src += buffer_size, dst += buffer_size) + for ( ; length > buffer_size; length -= buffer_size, dst += buffer_size) { - f(ctx, buffer_size, buffer, src); + f(ctx, buffer_size, buffer, dst); memcpy(initial_iv, iv, block_size); - memcpy(iv, src + buffer_size - block_size, block_size); - memxor3(dst + block_size, buffer + block_size, src, + memcpy(iv, dst + buffer_size - block_size, block_size); + memxor3(dst + block_size, buffer + block_size, dst, buffer_size - block_size); memxor3(dst, buffer, initial_iv, block_size); } - f(ctx, length, buffer, src); + f(ctx, length, buffer, dst); memcpy(initial_iv, iv, block_size); /* Copies last block */ - memcpy(iv, src + length - block_size, block_size); + memcpy(iv, dst + length - block_size, block_size); /* Writes all but first block, reads all but last block. */ - memxor3(dst + block_size, buffer + block_size, src, + memxor3(dst + block_size, buffer + block_size, dst, length - block_size); /* Writes first block. */ memxor3(dst, buffer, initial_iv, block_size); |