From c84ba1d17a9c0ed91620a47add28ea61e257eb3c Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Thu, 17 Dec 2015 08:36:49 +0100 Subject: [PATCH] Aliasing --- .../chacha20/vec/stream_chacha20_vec.c | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/libsodium/crypto_stream/chacha20/vec/stream_chacha20_vec.c b/src/libsodium/crypto_stream/chacha20/vec/stream_chacha20_vec.c index 736f299e..f211b722 100644 --- a/src/libsodium/crypto_stream/chacha20/vec/stream_chacha20_vec.c +++ b/src/libsodium/crypto_stream/chacha20/vec/stream_chacha20_vec.c @@ -97,13 +97,20 @@ typedef struct chacha_ctx chacha_ctx; static void chacha_ivsetup(chacha_ctx *ctx, const uint8_t *iv, uint64_t ic) { - const vec s3 = { - (uint32_t) ic, - (uint32_t) (ic >> 32), - ((const uint32_t *) (const void *) iv)[0], - ((const uint32_t *) (const void *) iv)[1] - }; - ctx->s3 = s3; + uint32_t iv_low; + uint32_t iv_high; + + memcpy(&iv_low, iv, 4); + memcpy(&iv_high, iv + 4, 4); + { + const vec s3 = { + (uint32_t) ic, + (uint32_t) (ic >> 32), + iv_low, + iv_high + }; + ctx->s3 = s3; + } } static void