11/*
22 BLAKE2 reference source code package - optimized C implementations
3+
34 Written in 2012 by Samuel Neves <sneves@dei.uc.pt>
5+
46 To the extent possible under law, the author(s) have dedicated all copyright
57 and related and neighboring rights to this software to the public domain
68 worldwide. This software is distributed without any warranty.
9+
710 You should have received a copy of the CC0 Public Domain Dedication along with
811 this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
912*/
1316
1417#include <stdint.h>
1518
16- static inline uint32_t load32 (const void * src )
19+ static inline uint32_t load32 ( const void * src )
1720{
1821#if defined(NATIVE_LITTLE_ENDIAN )
19- uint32_t w ;
20- memcpy (& w , src , sizeof w );
21- return w ;
22+ uint32_t w ;
23+ memcpy (& w , src , sizeof w );
24+ return w ;
2225#else
23- const uint8_t * p = (const uint8_t * )src ;
24- uint32_t w = * p ++ ;
25- w |= (uint32_t )( * p ++ ) << 8 ;
26- w |= (uint32_t )( * p ++ ) << 16 ;
27- w |= (uint32_t )( * p ++ ) << 24 ;
28- return w ;
26+ const uint8_t * p = ( const uint8_t * )src ;
27+ uint32_t w = * p ++ ;
28+ w |= ( uint32_t )( * p ++ ) << 8 ;
29+ w |= ( uint32_t )( * p ++ ) << 16 ;
30+ w |= ( uint32_t )( * p ++ ) << 24 ;
31+ return w ;
2932#endif
3033}
3134
32- static inline uint64_t load64 (const void * src )
35+ static inline uint64_t load64 ( const void * src )
3336{
3437#if defined(NATIVE_LITTLE_ENDIAN )
35- uint64_t w ;
36- memcpy (& w , src , sizeof w );
37- return w ;
38+ uint64_t w ;
39+ memcpy (& w , src , sizeof w );
40+ return w ;
3841#else
39- const uint8_t * p = (const uint8_t * )src ;
40- uint64_t w = * p ++ ;
41- w |= (uint64_t )( * p ++ ) << 8 ;
42- w |= (uint64_t )( * p ++ ) << 16 ;
43- w |= (uint64_t )( * p ++ ) << 24 ;
44- w |= (uint64_t )( * p ++ ) << 32 ;
45- w |= (uint64_t )( * p ++ ) << 40 ;
46- w |= (uint64_t )( * p ++ ) << 48 ;
47- w |= (uint64_t )( * p ++ ) << 56 ;
48- return w ;
42+ const uint8_t * p = ( const uint8_t * )src ;
43+ uint64_t w = * p ++ ;
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 ;
51+ return w ;
4952#endif
5053}
5154
52- static inline void store32 (void * dst , uint32_t w )
55+ static inline void store32 ( void * dst , uint32_t w )
5356{
5457#if defined(NATIVE_LITTLE_ENDIAN )
55- memcpy (dst , & w , sizeof w );
58+ memcpy (dst , & w , sizeof w );
5659#else
57- uint8_t * p = (uint8_t * )dst ;
58- * p ++ = (uint8_t )w ;
59- w >>= 8 ;
60- * p ++ = (uint8_t )w ;
61- w >>= 8 ;
62- * p ++ = (uint8_t )w ;
63- w >>= 8 ;
64- * p ++ = (uint8_t )w ;
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 ;
64+ * p ++ = ( uint8_t )w ;
6565#endif
6666}
6767
68- static inline void store64 (void * dst , uint64_t w )
68+ static inline void store64 ( void * dst , uint64_t w )
6969{
7070#if defined(NATIVE_LITTLE_ENDIAN )
71- memcpy (dst , & w , sizeof w );
71+ memcpy (dst , & w , sizeof w );
7272#else
73- uint8_t * p = (uint8_t * )dst ;
74- * p ++ = (uint8_t )w ;
75- w >>= 8 ;
76- * p ++ = (uint8_t )w ;
77- w >>= 8 ;
78- * p ++ = (uint8_t )w ;
79- w >>= 8 ;
80- * p ++ = (uint8_t )w ;
81- w >>= 8 ;
82- * p ++ = (uint8_t )w ;
83- w >>= 8 ;
84- * p ++ = (uint8_t )w ;
85- w >>= 8 ;
86- * p ++ = (uint8_t )w ;
87- w >>= 8 ;
88- * p ++ = (uint8_t )w ;
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 ;
81+ * p ++ = ( uint8_t )w ;
8982#endif
9083}
9184
92- static inline uint64_t load48 (const void * src )
85+ static inline uint64_t load48 ( const void * src )
9386{
94- const uint8_t * p = (const uint8_t * )src ;
95- uint64_t w = * p ++ ;
96- w |= (uint64_t )( * p ++ ) << 8 ;
97- w |= (uint64_t )( * p ++ ) << 16 ;
98- w |= (uint64_t )( * p ++ ) << 24 ;
99- w |= (uint64_t )( * p ++ ) << 32 ;
100- w |= (uint64_t )( * p ++ ) << 40 ;
101- return w ;
87+ const uint8_t * p = ( const uint8_t * )src ;
88+ uint64_t w = * p ++ ;
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 ;
94+ return w ;
10295}
10396
104- static inline void store48 (void * dst , uint64_t w )
97+ static inline void store48 ( void * dst , uint64_t w )
10598{
106- uint8_t * p = (uint8_t * )dst ;
107- * p ++ = (uint8_t )w ;
108- w >>= 8 ;
109- * p ++ = (uint8_t )w ;
110- w >>= 8 ;
111- * p ++ = (uint8_t )w ;
112- w >>= 8 ;
113- * p ++ = (uint8_t )w ;
114- w >>= 8 ;
115- * p ++ = (uint8_t )w ;
116- w >>= 8 ;
117- * p ++ = (uint8_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 ;
105+ * p ++ = ( uint8_t )w ;
118106}
119107
120- static inline uint32_t rotl32 (const uint32_t w , const unsigned c )
108+ static inline uint32_t rotl32 ( const uint32_t w , const unsigned c )
121109{
122- return (w << c ) | (w >> (32 - c ) );
110+ return ( w << c ) | ( w >> ( 32 - c ) );
123111}
124112
125- static inline uint64_t rotl64 (const uint64_t w , const unsigned c )
113+ static inline uint64_t rotl64 ( const uint64_t w , const unsigned c )
126114{
127- return (w << c ) | (w >> (64 - c ) );
115+ return ( w << c ) | ( w >> ( 64 - c ) );
128116}
129117
130- static inline uint32_t rotr32 (const uint32_t w , const unsigned c )
118+ static inline uint32_t rotr32 ( const uint32_t w , const unsigned c )
131119{
132- return (w >> c ) | (w << (32 - c ) );
120+ return ( w >> c ) | ( w << ( 32 - c ) );
133121}
134122
135- static inline uint64_t rotr64 (const uint64_t w , const unsigned c )
123+ static inline uint64_t rotr64 ( const uint64_t w , const unsigned c )
136124{
137- return (w >> c ) | (w << (64 - c ) );
125+ return ( w >> c ) | ( w << ( 64 - c ) );
138126}
139127
140128/* prevents compiler optimizing out memset() */
141- static inline void secure_zero_memory (void * v , size_t n )
129+ static inline void secure_zero_memory ( void * v , size_t n )
142130{
143- volatile uint8_t * p = (volatile uint8_t * )v ;
144- while (n -- )
145- * p ++ = 0 ;
131+ volatile uint8_t * p = ( volatile uint8_t * )v ;
132+ while ( n -- ) * p ++ = 0 ;
146133}
147134
148- #endif
135+ #endif
136+
0 commit comments