21 #if !defined(__cplusplus) && \ 22 (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L) 24 #define BLAKE2_INLINE __inline 25 #elif defined(__GNUC__) 26 #define BLAKE2_INLINE __inline__ 31 #define BLAKE2_INLINE inline 34 static BLAKE2_INLINE uint32_t load32(
const void *src) {
35 #if defined(NATIVE_LITTLE_ENDIAN) 37 memcpy(&w, src,
sizeof w);
40 const uint8_t *p = (
const uint8_t *)src;
41 return ((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) |
42 ((uint32_t)(p[2]) << 16) | ((uint32_t)(p[3]) << 24);
46 static BLAKE2_INLINE uint64_t load64(
const void *src) {
47 #if defined(NATIVE_LITTLE_ENDIAN) 49 memcpy(&w, src,
sizeof w);
52 const uint8_t *p = (
const uint8_t *)src;
53 return ((uint64_t)(p[0]) << 0) | ((uint64_t)(p[1]) << 8) |
54 ((uint64_t)(p[2]) << 16) | ((uint64_t)(p[3]) << 24) |
55 ((uint64_t)(p[4]) << 32) | ((uint64_t)(p[5]) << 40) |
56 ((uint64_t)(p[6]) << 48) | ((uint64_t)(p[7]) << 56);
60 static BLAKE2_INLINE uint16_t load16(
const void *src) {
61 #if defined(NATIVE_LITTLE_ENDIAN) 63 memcpy(&w, src,
sizeof w);
66 const uint8_t *p = (
const uint8_t *)src;
67 return (uint16_t)(((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8));
71 static BLAKE2_INLINE
void store16(
void *dst, uint16_t w) {
72 #if defined(NATIVE_LITTLE_ENDIAN) 73 memcpy(dst, &w,
sizeof w);
75 uint8_t *p = (uint8_t *)dst;
82 static BLAKE2_INLINE
void store32(
void *dst, uint32_t w) {
83 #if defined(NATIVE_LITTLE_ENDIAN) 84 memcpy(dst, &w,
sizeof w);
86 uint8_t *p = (uint8_t *)dst;
87 p[0] = (uint8_t)(w >> 0);
88 p[1] = (uint8_t)(w >> 8);
89 p[2] = (uint8_t)(w >> 16);
90 p[3] = (uint8_t)(w >> 24);
94 static BLAKE2_INLINE
void store64(
void *dst, uint64_t w) {
95 #if defined(NATIVE_LITTLE_ENDIAN) 96 memcpy(dst, &w,
sizeof w);
98 uint8_t *p = (uint8_t *)dst;
99 p[0] = (uint8_t)(w >> 0);
100 p[1] = (uint8_t)(w >> 8);
101 p[2] = (uint8_t)(w >> 16);
102 p[3] = (uint8_t)(w >> 24);
103 p[4] = (uint8_t)(w >> 32);
104 p[5] = (uint8_t)(w >> 40);
105 p[6] = (uint8_t)(w >> 48);
106 p[7] = (uint8_t)(w >> 56);
110 static BLAKE2_INLINE uint64_t load48(
const void *src) {
111 const uint8_t *p = (
const uint8_t *)src;
112 return ((uint64_t)(p[0]) << 0) | ((uint64_t)(p[1]) << 8) |
113 ((uint64_t)(p[2]) << 16) | ((uint64_t)(p[3]) << 24) |
114 ((uint64_t)(p[4]) << 32) | ((uint64_t)(p[5]) << 40);
117 static BLAKE2_INLINE
void store48(
void *dst, uint64_t w) {
118 uint8_t *p = (uint8_t *)dst;
119 p[0] = (uint8_t)(w >> 0);
120 p[1] = (uint8_t)(w >> 8);
121 p[2] = (uint8_t)(w >> 16);
122 p[3] = (uint8_t)(w >> 24);
123 p[4] = (uint8_t)(w >> 32);
124 p[5] = (uint8_t)(w >> 40);
127 static BLAKE2_INLINE uint32_t rotr32(
const uint32_t w,
const unsigned c) {
128 return (w >> c) | (w << (32 - c));
131 static BLAKE2_INLINE uint64_t rotr64(
const uint64_t w,
const unsigned c) {
132 return (w >> c) | (w << (64 - c));
136 static BLAKE2_INLINE
void secure_zero_memory(
void *v,
size_t n) {
137 static void *(*
const volatile memset_v)(
void *,
int,
size_t) = &memset;