14 #ifndef __BLAKE2_IMPL_H__ 15 #define __BLAKE2_IMPL_H__ 19 static inline uint32_t load32(
const void *src )
21 #if defined(NATIVE_LITTLE_ENDIAN) 26 const uint8_t *p = (
const uint8_t * )src;
28 w |= ( uint32_t )( *p++ ) << 8;
29 w |= ( uint32_t )( *p++ ) << 16;
30 w |= ( uint32_t )( *p++ ) << 24;
35 static inline uint64_t load64(
const void *src )
37 #if defined(NATIVE_LITTLE_ENDIAN) 42 const uint8_t *p = (
const uint8_t * )src;
44 w |= ( uint64_t )( *p++ ) << 8;
45 w |= ( uint64_t )( *p++ ) << 16;
46 w |= ( uint64_t )( *p++ ) << 24;
47 w |= ( uint64_t )( *p++ ) << 32;
48 w |= ( uint64_t )( *p++ ) << 40;
49 w |= ( uint64_t )( *p++ ) << 48;
50 w |= ( uint64_t )( *p++ ) << 56;
55 static inline void store32(
void *dst, uint32_t w )
57 #if defined(NATIVE_LITTLE_ENDIAN) 60 uint8_t *p = ( uint8_t * )dst;
61 *p++ = ( uint8_t )w; w >>= 8;
62 *p++ = ( uint8_t )w; w >>= 8;
63 *p++ = ( uint8_t )w; w >>= 8;
68 static inline void store64(
void *dst, uint64_t w )
70 #if defined(NATIVE_LITTLE_ENDIAN) 73 uint8_t *p = ( uint8_t * )dst;
74 *p++ = ( uint8_t )w; w >>= 8;
75 *p++ = ( uint8_t )w; w >>= 8;
76 *p++ = ( uint8_t )w; w >>= 8;
77 *p++ = ( uint8_t )w; w >>= 8;
78 *p++ = ( uint8_t )w; w >>= 8;
79 *p++ = ( uint8_t )w; w >>= 8;
80 *p++ = ( uint8_t )w; w >>= 8;
85 static inline uint64_t load48(
const void *src )
87 const uint8_t *p = (
const uint8_t * )src;
89 w |= ( uint64_t )( *p++ ) << 8;
90 w |= ( uint64_t )( *p++ ) << 16;
91 w |= ( uint64_t )( *p++ ) << 24;
92 w |= ( uint64_t )( *p++ ) << 32;
93 w |= ( uint64_t )( *p++ ) << 40;
97 static inline void store48(
void *dst, uint64_t w )
99 uint8_t *p = ( uint8_t * )dst;
100 *p++ = ( uint8_t )w; w >>= 8;
101 *p++ = ( uint8_t )w; w >>= 8;
102 *p++ = ( uint8_t )w; w >>= 8;
103 *p++ = ( uint8_t )w; w >>= 8;
104 *p++ = ( uint8_t )w; w >>= 8;
108 static inline uint32_t rotl32(
const uint32_t w,
const unsigned c )
110 return ( w << c ) | ( w >> ( 32 -
c ) );
113 static inline uint64_t rotl64(
const uint64_t w,
const unsigned c )
115 return ( w << c ) | ( w >> ( 64 -
c ) );
118 static inline uint32_t rotr32(
const uint32_t w,
const unsigned c )
120 return ( w >> c ) | ( w << ( 32 -
c ) );
123 static inline uint64_t rotr64(
const uint64_t w,
const unsigned c )
125 return ( w >> c ) | ( w << ( 64 -
c ) );
129 static inline void secure_zero_memory(
void *v,
size_t n )
131 volatile uint8_t *p = (
volatile uint8_t * )v;
132 while( n-- ) *p++ = 0;
void * memcpy(void *a, const void *b, size_t c)