mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-19 05:45:05 +01:00
crypto: Add missing WriteBE16 function
Also add fuzz test, mimicing the WriteLE16 one.
This commit is contained in:
parent
33adc7521c
commit
754e425438
@ -70,6 +70,12 @@ uint64_t static inline ReadBE64(const unsigned char* ptr)
|
||||
return be64toh_internal(x);
|
||||
}
|
||||
|
||||
void static inline WriteBE16(unsigned char* ptr, uint16_t x)
|
||||
{
|
||||
uint16_t v = htobe16_internal(x);
|
||||
memcpy(ptr, &v, 2);
|
||||
}
|
||||
|
||||
void static inline WriteBE32(unsigned char* ptr, uint32_t x)
|
||||
{
|
||||
uint32_t v = htobe32_internal(x);
|
||||
|
@ -35,6 +35,10 @@ FUZZ_TARGET(crypto_common)
|
||||
WriteLE64(writele64_arr.data(), random_u64);
|
||||
assert(ReadLE64(writele64_arr.data()) == random_u64);
|
||||
|
||||
std::array<uint8_t, 2> writebe16_arr;
|
||||
WriteBE16(writebe16_arr.data(), random_u16);
|
||||
assert(ReadBE16(writebe16_arr.data()) == random_u16);
|
||||
|
||||
std::array<uint8_t, 4> writebe32_arr;
|
||||
WriteBE32(writebe32_arr.data(), random_u32);
|
||||
assert(ReadBE32(writebe32_arr.data()) == random_u32);
|
||||
|
Loading…
Reference in New Issue
Block a user