Skip to content

Commit

Permalink
reorder struct members
Browse files Browse the repository at this point in the history
Signed-off-by: Pantelis Antoniou <[email protected]>
  • Loading branch information
pantoniou committed Sep 9, 2023
1 parent ece7fd0 commit 3ac1c01
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/blake3/blake3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;

Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions src/blake3/blake3_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3ac1c01

Please sign in to comment.