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 | |
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.
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | cbc.c | 15 | ||||
-rw-r--r-- | cfb.c | 5 | ||||
-rw-r--r-- | gcm.c | 2 |
4 files changed, 17 insertions, 12 deletions
@@ -1,3 +1,10 @@ +2018-01-08 Niels Möller <nisse@lysator.liu.se> + + * 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. + 2018-01-03 Niels Möller <nisse@lysator.liu.se> * x86_64/aesni/aes-encrypt-internal.asm: Read subkeys into xmm @@ -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); @@ -147,12 +147,11 @@ cfb_decrypt(const void *ctx, nettle_cipher_func *f, * not less than block_size. So does part */ f(ctx, block_size, buffer, iv); - f(ctx, part - block_size, buffer + block_size, src); - memcpy(iv, src + part - block_size, block_size); + f(ctx, part - block_size, buffer + block_size, dst); + memcpy(iv, dst + part - block_size, block_size); memxor(dst, buffer, part); length -= part; - src += part; dst += part; } @@ -458,7 +458,7 @@ gcm_crypt(struct gcm_ctx *ctx, const void *cipher, nettle_cipher_func *f, src += GCM_BLOCK_SIZE, dst += GCM_BLOCK_SIZE)) { f (cipher, GCM_BLOCK_SIZE, buffer, ctx->ctr.b); - memxor3 (dst, src, buffer, GCM_BLOCK_SIZE); + memxor (dst, buffer, GCM_BLOCK_SIZE); INC32 (ctx->ctr); } } |