From 3ac1c01172c980d8306f95e750b2b343f4a058cf Mon Sep 17 00:00:00 2001 From: Pantelis Antoniou Date: Sat, 9 Sep 2023 21:44:52 +0300 Subject: [PATCH] reorder struct members Signed-off-by: Pantelis Antoniou --- src/blake3/blake3.c | 6 +++--- src/blake3/blake3_internal.h | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/blake3/blake3.c b/src/blake3/blake3.c index 67d3b433..efc0ea7e 100644 --- a/src/blake3/blake3.c +++ b/src/blake3/blake3.c @@ -144,7 +144,7 @@ static inline void blake3_chunk_state_update(blake3_host_state *hs, blake3_chunk // bytes. static inline void blake3_output_chaining_value(blake3_host_state *hs, const blake3_output_t *self, uint8_t cv[32]) { - uint32_t cv_words[8]; + uint32_t cv_words[8] BLAKE3_ALIGN; memcpy(cv_words, self->input_cv, 32); hs->compress_in_place(cv_words, self->block, self->block_len, self->counter, self->flags); @@ -153,9 +153,9 @@ static inline void blake3_output_chaining_value(blake3_host_state *hs, const bla static inline void blake3_output_root_bytes(blake3_host_state *hs, const blake3_output_t *self, uint64_t seek, uint8_t *out, size_t out_len) { + uint8_t wide_buf[64] BLAKE3_ALIGN; uint64_t output_block_counter; size_t offset_within_block; - uint8_t wide_buf[64]; size_t available_bytes; size_t memcpy_len; @@ -651,9 +651,9 @@ void blake3_hasher_reset(blake3_hasher *self) void blake3_hasher_finalize_seek(const blake3_hasher *self, uint64_t seek, uint8_t *out, size_t out_len) { + uint8_t parent_block[BLAKE3_BLOCK_LEN] BLAKE3_ALIGN; blake3_output_t output; size_t cvs_remaining; - uint8_t parent_block[BLAKE3_BLOCK_LEN]; // Explicitly checking for zero avoids causing UB by passing a null pointer // to memcpy. This comes up in practice with things like: diff --git a/src/blake3/blake3_internal.h b/src/blake3/blake3_internal.h index 78327315..18ac47dd 100644 --- a/src/blake3/blake3_internal.h +++ b/src/blake3/blake3_internal.h @@ -33,32 +33,32 @@ enum blake3_flags { typedef struct _blake3_output { uint32_t input_cv[8] BLAKE3_ALIGN; - uint64_t counter; uint8_t block[BLAKE3_BLOCK_LEN] BLAKE3_ALIGN; + uint64_t counter; uint8_t block_len; uint8_t flags; } blake3_output_t BLAKE3_ALIGN; typedef struct _blake3_chunk_state { uint32_t cv[8] BLAKE3_ALIGN; - uint64_t chunk_counter; uint8_t buf[BLAKE3_BLOCK_LEN] BLAKE3_ALIGN; + uint64_t chunk_counter; uint8_t buf_len; uint8_t blocks_compressed; uint8_t flags; } blake3_chunk_state BLAKE3_ALIGN; typedef struct _blake3_hasher { - struct _blake3_host_state *hs; uint32_t key[8] BLAKE3_ALIGN; blake3_chunk_state chunk; - uint8_t cv_stack_len; // The stack size is MAX_DEPTH + 1 because we do lazy merging. For example, // with 7 chunks, we have 3 entries in the stack. Adding an 8th chunk // requires a 4th entry, rather than merging everything down to 1, because we // don't know whether more input is coming. This is different from how the // reference implementation does things. uint8_t cv_stack[(BLAKE3_MAX_DEPTH + 1) * BLAKE3_OUT_LEN] BLAKE3_ALIGN; + uint8_t cv_stack_len; + struct _blake3_host_state *hs; } blake3_hasher BLAKE3_ALIGN; typedef void (*blake3_hash_many_f)(const uint8_t *const *inputs, size_t num_inputs,