Skip to content

Commit dbe2105

Browse files
committed
fcmp_pp: get_output_ref_hash: fix aliasing, endianness, and 32-bit
1 parent 556e26d commit dbe2105

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

src/fcmp_pp/tree_cache.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
#include "tree_cache.h"
3030

3131
#include "common/merge_sorted_vectors.h"
32+
#include "int-util.h"
3233
#include "misc_log_ex.h"
3334
#include "profile_tools.h"
34-
#include "string_tools.h"
3535

3636
#include <algorithm>
3737

@@ -50,20 +50,18 @@ static OutputRefHash get_output_ref_hash(const OutputPair &o_variant)
5050

5151
// Hash the type info as well
5252
crypto::public_key type = crypto::null_pkey;
53-
const std::size_t variant_index = o_variant.index();
53+
const std::uint64_t variant_index = SWAP64LE(static_cast<std::uint64_t>(o_variant.index()));
5454
static_assert(sizeof(type) >= sizeof(variant_index), "variant index type is too large");
5555
memcpy(&type, &variant_index, sizeof(variant_index));
5656

5757
static constexpr std::size_t N_HASH_ELEMS = 3;
58-
const crypto::public_key data[N_HASH_ELEMS] = {
58+
const crypto::ec_point data[N_HASH_ELEMS] = {
5959
output_pubkey,
60-
(crypto::public_key&)commitment,
60+
commitment,
6161
type
6262
};
6363

64-
crypto::hash h;
65-
crypto::cn_fast_hash(data, N_HASH_ELEMS * sizeof(crypto::public_key), h);
66-
return h;
64+
return crypto::cn_fast_hash(data, sizeof(data));
6765
};
6866
//----------------------------------------------------------------------------------------------------------------------
6967
static void assign_new_output(const OutputPair &output_pair,

0 commit comments

Comments
 (0)