From d47cb42f5a7887f07cedadcbb23c89bd58d993af Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Fri, 30 Oct 2015 21:32:19 +0100 Subject: [PATCH] Replace some memcpy() with a local loop --- .../crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c | 6 +++++- src/libsodium/crypto_secretbox/crypto_secretbox_easy.c | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c b/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c index 5ac1165b..b2ba5acf 100644 --- a/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c +++ b/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c @@ -214,8 +214,12 @@ addmul(unsigned char *c, const unsigned char *a, unsigned int xlen, const unsign A = _mm_loadu_si128((const __m128i *) a); } else { CRYPTO_ALIGN(16) unsigned char padded[16]; + unsigned int i; + memset(padded, 0, 16); - memcpy(padded, a, xlen); + for (i = 0; i < xlen; i++) { + padded[i] = a[i]; + } A = _mm_load_si128((const __m128i *) padded); } A = _mm_shuffle_epi8(A, rev); diff --git a/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c b/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c index e9b594c1..7802b003 100644 --- a/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c +++ b/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c @@ -52,7 +52,9 @@ crypto_secretbox_detached(unsigned char *c, unsigned char *mac, crypto_onetimeauth_poly1305_KEYBYTES ? 1 : -1]); crypto_onetimeauth_poly1305_init(&state, block0); - memcpy(c, block0 + crypto_secretbox_ZEROBYTES, mlen0); + for (i = 0U; i < mlen0; i++) { + c[i] = block0[crypto_secretbox_ZEROBYTES + i]; + } sodium_memzero(block0, sizeof block0); if (mlen > mlen0) { crypto_stream_salsa20_xor_ic(c + mlen0, m + mlen0, mlen - mlen0, @@ -109,7 +111,9 @@ crypto_secretbox_open_detached(unsigned char *m, const unsigned char *c, if (mlen0 > 64U - crypto_secretbox_ZEROBYTES) { mlen0 = 64U - crypto_secretbox_ZEROBYTES; } - memcpy(block0 + crypto_secretbox_ZEROBYTES, c, mlen0); + for (i = 0U; i < mlen0; i++) { + block0[crypto_secretbox_ZEROBYTES + i] = c[i]; + } crypto_stream_salsa20_xor(block0, block0, crypto_secretbox_ZEROBYTES + mlen0, n + 16, subkey);