5#ifndef BITCOIN_CRYPTO_COMMON_H
6#define BITCOIN_CRYPTO_COMMON_H
8#if defined(HAVE_CONFIG_H)
9#include <config/bitcoin-config.h>
17static inline uint16_t
ReadLE16(
const uint8_t *ptr) {
19 memcpy((
char *)&x, ptr, 2);
23static inline uint32_t
ReadLE32(
const uint8_t *ptr) {
25 memcpy((
char *)&x, ptr, 4);
29static inline uint64_t
ReadLE64(
const uint8_t *ptr) {
31 memcpy((
char *)&x, ptr, 8);
35static inline void WriteLE16(uint8_t *ptr, uint16_t x) {
37 memcpy(ptr, (
char *)&v, 2);
40static inline void WriteLE32(uint8_t *ptr, uint32_t x) {
42 memcpy(ptr, (
char *)&v, 4);
45static inline void WriteLE64(uint8_t *ptr, uint64_t x) {
47 memcpy(ptr, (
char *)&v, 8);
50uint16_t
static inline ReadBE16(
const uint8_t *ptr) {
52 memcpy((
char *)&x, ptr, 2);
56static inline uint32_t
ReadBE32(
const uint8_t *ptr) {
58 memcpy((
char *)&x, ptr, 4);
62static inline uint64_t
ReadBE64(
const uint8_t *ptr) {
64 memcpy((
char *)&x, ptr, 8);
68static inline void WriteBE32(uint8_t *ptr, uint32_t x) {
70 memcpy(ptr, (
char *)&v, 4);
73static inline void WriteBE64(uint8_t *ptr, uint64_t x) {
75 memcpy(ptr, (
char *)&v, 8);
83#if HAVE_DECL___BUILTIN_CLZL
84 if (
sizeof(
unsigned long) >=
sizeof(uint64_t)) {
85 return x ? 8 *
sizeof(
unsigned long) - __builtin_clzl(x) : 0;
88#if HAVE_DECL___BUILTIN_CLZLL
89 if (
sizeof(
unsigned long long) >=
sizeof(uint64_t)) {
90 return x ? 8 *
sizeof(
unsigned long long) - __builtin_clzll(x) : 0;
static void WriteLE16(uint8_t *ptr, uint16_t x)
static void WriteLE32(uint8_t *ptr, uint32_t x)
static void WriteBE64(uint8_t *ptr, uint64_t x)
static void WriteBE32(uint8_t *ptr, uint32_t x)
static uint64_t ReadLE64(const uint8_t *ptr)
static uint16_t ReadBE16(const uint8_t *ptr)
static uint32_t ReadBE32(const uint8_t *ptr)
static uint16_t ReadLE16(const uint8_t *ptr)
static uint64_t ReadBE64(const uint8_t *ptr)
static uint64_t CountBits(uint64_t x)
Return the smallest number n such that (x >> n) == 0 (or 64 if the highest bit in x is set.
static uint32_t ReadLE32(const uint8_t *ptr)
static void WriteLE64(uint8_t *ptr, uint64_t x)
uint16_t be16toh(uint16_t big_endian_16bits)
uint32_t le32toh(uint32_t little_endian_32bits)
uint32_t htobe32(uint32_t host_32bits)
uint16_t le16toh(uint16_t little_endian_16bits)
uint64_t htobe64(uint64_t host_64bits)
uint64_t be64toh(uint64_t big_endian_64bits)
uint32_t be32toh(uint32_t big_endian_32bits)
uint64_t htole64(uint64_t host_64bits)
uint32_t htole32(uint32_t host_32bits)
uint16_t htole16(uint16_t host_16bits)
uint64_t le64toh(uint64_t little_endian_64bits)