From 0987fb36329e44c03ac79f317a7dc56860423bb4 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Wed, 23 Sep 2015 13:28:23 +0800 Subject: [PATCH] fix an issue of endian --- src/encrypt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/encrypt.c b/src/encrypt.c index 8c8e9627..f9d692f2 100644 --- a/src/encrypt.c +++ b/src/encrypt.c @@ -1513,8 +1513,9 @@ int ss_check_hash(char **buf_ptr, ssize_t *buf_len, struct chunk *chunk, struct uint8_t hash[HASH_BYTES]; uint8_t key[MAX_IV_LENGTH + sizeof(uint32_t)]; + uint32_t c = htonl(chunk->counter); memcpy(key, ctx->evp.iv, enc_iv_len); - memcpy(key + enc_iv_len, &chunk->counter, sizeof(uint32_t)); + memcpy(key + enc_iv_len, &c, sizeof(uint32_t)); crypto_generichash(hash, HASH_BYTES, (uint8_t *)chunk->buf + AUTH_BYTES, chunk->len, key, enc_iv_len + sizeof(uint32_t)); @@ -1554,8 +1555,9 @@ char *ss_gen_hash(char *buf, ssize_t *buf_len, uint32_t *counter, struct enc_ctx uint8_t hash[HASH_BYTES]; uint8_t key[MAX_IV_LENGTH + sizeof(uint32_t)]; + uint32_t c = htonl(*counter); memcpy(key, ctx->evp.iv, enc_iv_len); - memcpy(key + enc_iv_len, counter, sizeof(uint32_t)); + memcpy(key + enc_iv_len, &c, sizeof(uint32_t)); crypto_generichash(hash, HASH_BYTES, (uint8_t *)buf, blen, key, enc_iv_len + sizeof(uint32_t)); memmove(buf + AUTH_BYTES, buf, blen);