36 #ifndef WOLFCRYPT_BLAKE2_IMPL_H 37 #define WOLFCRYPT_BLAKE2_IMPL_H 41 static WC_INLINE word32 load32(
const void *src )
43 #if defined(LITTLE_ENDIAN_ORDER) 44 return *( word32 * )( src );
46 const byte *p = ( byte * )src;
48 w |= ( word32 )( *p++ ) << 8;
49 w |= ( word32 )( *p++ ) << 16;
50 w |= ( word32 )( *p++ ) << 24;
55 static WC_INLINE word64 load64(
const void *src )
57 #if defined(LITTLE_ENDIAN_ORDER) 58 return *( word64 * )( src );
60 const byte *p = ( byte * )src;
62 w |= ( word64 )( *p++ ) << 8;
63 w |= ( word64 )( *p++ ) << 16;
64 w |= ( word64 )( *p++ ) << 24;
65 w |= ( word64 )( *p++ ) << 32;
66 w |= ( word64 )( *p++ ) << 40;
67 w |= ( word64 )( *p++ ) << 48;
68 w |= ( word64 )( *p++ ) << 56;
73 static WC_INLINE
void store32(
void *dst, word32 w )
75 #if defined(LITTLE_ENDIAN_ORDER) 76 *( word32 * )( dst ) = w;
78 byte *p = ( byte * )dst;
79 *p++ = ( byte )w; w >>= 8;
80 *p++ = ( byte )w; w >>= 8;
81 *p++ = ( byte )w; w >>= 8;
86 static WC_INLINE
void store64(
void *dst, word64 w )
88 #if defined(LITTLE_ENDIAN_ORDER) 89 *( word64 * )( dst ) = w;
91 byte *p = ( byte * )dst;
92 *p++ = ( byte )w; w >>= 8;
93 *p++ = ( byte )w; w >>= 8;
94 *p++ = ( byte )w; w >>= 8;
95 *p++ = ( byte )w; w >>= 8;
96 *p++ = ( byte )w; w >>= 8;
97 *p++ = ( byte )w; w >>= 8;
98 *p++ = ( byte )w; w >>= 8;
103 static WC_INLINE word64 load48(
const void *src )
105 const byte *p = (
const byte * )src;
107 w |= ( word64 )( *p++ ) << 8;
108 w |= ( word64 )( *p++ ) << 16;
109 w |= ( word64 )( *p++ ) << 24;
110 w |= ( word64 )( *p++ ) << 32;
111 w |= ( word64 )( *p++ ) << 40;
115 static WC_INLINE
void store48(
void *dst, word64 w )
117 byte *p = ( byte * )dst;
118 *p++ = ( byte )w; w >>= 8;
119 *p++ = ( byte )w; w >>= 8;
120 *p++ = ( byte )w; w >>= 8;
121 *p++ = ( byte )w; w >>= 8;
122 *p++ = ( byte )w; w >>= 8;
126 static WC_INLINE word32 rotl32(
const word32 w,
const unsigned c )
128 return ( w << c ) | ( w >> ( 32 - c ) );
131 static WC_INLINE word64 rotl64(
const word64 w,
const unsigned c )
133 return ( w << c ) | ( w >> ( 64 - c ) );
136 static WC_INLINE word32 rotr32(
const word32 w,
const unsigned c )
138 return ( w >> c ) | ( w << ( 32 - c ) );
141 static WC_INLINE word64 rotr64(
const word64 w,
const unsigned c )
143 return ( w >> c ) | ( w << ( 64 - c ) );
147 static WC_INLINE
void secure_zero_memory(
void *v, word64 n )
149 volatile byte *p = (
volatile byte * )v;
151 while( n-- ) *p++ = 0;