From 34aeee6ba5d090c0309a9483067e8bea14db898e Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Tue, 12 Apr 2016 07:30:54 +0200 Subject: [PATCH] Replace two more memcpy() with a local loop --- src/libsodium/crypto_hash/sha256/cp/hash_sha256.c | 8 ++++++-- src/libsodium/crypto_hash/sha512/cp/hash_sha512.c | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/libsodium/crypto_hash/sha256/cp/hash_sha256.c b/src/libsodium/crypto_hash/sha256/cp/hash_sha256.c index e99d4e93..a7662971 100644 --- a/src/libsodium/crypto_hash/sha256/cp/hash_sha256.c +++ b/src/libsodium/crypto_hash/sha256/cp/hash_sha256.c @@ -220,10 +220,14 @@ crypto_hash_sha256_update(crypto_hash_sha256_state *state, state->count += (uint64_t)(inlen) << 3; if (inlen < 64 - r) { - memcpy(&state->buf[r], in, inlen); + for (i = 0; i < inlen; i++) { + state->buf[r + i] = in[i]; + } return 0; } - memcpy(&state->buf[r], in, 64 - r); + for (i = 0; i < 64 - r; i++) { + state->buf[r + i] = in[i]; + } SHA256_Transform(state->state, state->buf); in += 64 - r; inlen -= 64 - r; diff --git a/src/libsodium/crypto_hash/sha512/cp/hash_sha512.c b/src/libsodium/crypto_hash/sha512/cp/hash_sha512.c index a04a0384..2cc7a4dd 100644 --- a/src/libsodium/crypto_hash/sha512/cp/hash_sha512.c +++ b/src/libsodium/crypto_hash/sha512/cp/hash_sha512.c @@ -249,10 +249,14 @@ crypto_hash_sha512_update(crypto_hash_sha512_state *state, state->count[0] += bitlen[0]; if (inlen < 128 - r) { - memcpy(&state->buf[r], in, inlen); + for (i = 0; i < inlen; i++) { + state->buf[r + i] = in[i]; + } return 0; } - memcpy(&state->buf[r], in, 128 - r); + for (i = 0; i < 128 - r; i++) { + state->buf[r + i] = in[i]; + } SHA512_Transform(state->state, state->buf); in += 128 - r; inlen -= 128 - r;