Replace some memcpy() with a local loop

This commit is contained in:
Frank Denis 2015-10-30 21:32:19 +01:00
parent 8deb15bd85
commit d47cb42f5a
2 changed files with 11 additions and 3 deletions

View File

@ -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);

View File

@ -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);