23#if !defined(__cplusplus) && (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L)
25#define BLAKE2_INLINE __inline
26#elif defined(__GNUC__)
27#define BLAKE2_INLINE __inline__
32#define BLAKE2_INLINE inline
35static BLAKE2_INLINE uint32_t load32(
const void* src)
37#if defined(NATIVE_LITTLE_ENDIAN)
39 memcpy(&w, src,
sizeof w);
42 const uint8_t* p = (
const uint8_t*)src;
43 return ((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) | ((uint32_t)(p[2]) << 16) | ((uint32_t)(p[3]) << 24);
47static BLAKE2_INLINE uint64_t load64(
const void* src)
49#if defined(NATIVE_LITTLE_ENDIAN)
51 memcpy(&w, src,
sizeof w);
54 const uint8_t* p = (
const uint8_t*)src;
55 return ((uint64_t)(p[0]) << 0) | ((uint64_t)(p[1]) << 8) | ((uint64_t)(p[2]) << 16) | ((uint64_t)(p[3]) << 24) |
56 ((uint64_t)(p[4]) << 32) | ((uint64_t)(p[5]) << 40) | ((uint64_t)(p[6]) << 48) | ((uint64_t)(p[7]) << 56);
60static BLAKE2_INLINE uint16_t load16(
const void* src)
62#if defined(NATIVE_LITTLE_ENDIAN)
64 memcpy(&w, src,
sizeof w);
67 const uint8_t* p = (
const uint8_t*)src;
68 return (uint16_t)(((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8));
72static BLAKE2_INLINE
void store16(
void* dst, uint16_t w)
74#if defined(NATIVE_LITTLE_ENDIAN)
75 memcpy(dst, &w,
sizeof w);
77 uint8_t* p = (uint8_t*)dst;
79 w = (uint16_t)(w >> 8);
84static BLAKE2_INLINE
void store32(
void* dst, uint32_t w)
86#if defined(NATIVE_LITTLE_ENDIAN)
87 memcpy(dst, &w,
sizeof w);
89 uint8_t* p = (uint8_t*)dst;
90 p[0] = (uint8_t)(w >> 0);
91 p[1] = (uint8_t)(w >> 8);
92 p[2] = (uint8_t)(w >> 16);
93 p[3] = (uint8_t)(w >> 24);
97static BLAKE2_INLINE
void store64(
void* dst, uint64_t w)
99#if defined(NATIVE_LITTLE_ENDIAN)
100 memcpy(dst, &w,
sizeof w);
102 uint8_t* p = (uint8_t*)dst;
103 p[0] = (uint8_t)(w >> 0);
104 p[1] = (uint8_t)(w >> 8);
105 p[2] = (uint8_t)(w >> 16);
106 p[3] = (uint8_t)(w >> 24);
107 p[4] = (uint8_t)(w >> 32);
108 p[5] = (uint8_t)(w >> 40);
109 p[6] = (uint8_t)(w >> 48);
110 p[7] = (uint8_t)(w >> 56);
114static BLAKE2_INLINE uint64_t load48(
const void* src)
116 const uint8_t* p = (
const uint8_t*)src;
117 return ((uint64_t)(p[0]) << 0) | ((uint64_t)(p[1]) << 8) | ((uint64_t)(p[2]) << 16) | ((uint64_t)(p[3]) << 24) |
118 ((uint64_t)(p[4]) << 32) | ((uint64_t)(p[5]) << 40);
121static BLAKE2_INLINE
void store48(
void* dst, uint64_t w)
123 uint8_t* p = (uint8_t*)dst;
124 p[0] = (uint8_t)(w >> 0);
125 p[1] = (uint8_t)(w >> 8);
126 p[2] = (uint8_t)(w >> 16);
127 p[3] = (uint8_t)(w >> 24);
128 p[4] = (uint8_t)(w >> 32);
129 p[5] = (uint8_t)(w >> 40);
132static BLAKE2_INLINE uint32_t rotr32(
const uint32_t w,
const unsigned c)
134 return (w >> c) | (w << (32 - c));
137static BLAKE2_INLINE uint64_t rotr64(
const uint64_t w,
const unsigned c)
139 return (w >> c) | (w << (64 - c));
143static BLAKE2_INLINE
void secure_zero_memory(
void* v,
size_t n)
145 static void* (*
const volatile memset_v)(
void*,
int,
size_t) = &memset;