|
4 | 4 | #ifdef HAVE_LIBB2
|
5 | 5 | #include <blake2.h>
|
6 | 6 |
|
7 |
| -// copied from blake2-impl.h |
8 |
| -static inline void |
9 |
| -store32( void *dst, uint32_t w ) |
10 |
| -{ |
11 |
| -#if defined(NATIVE_LITTLE_ENDIAN) |
12 |
| - memcpy( dst, &w, sizeof( w ) ); |
13 |
| -#else |
14 |
| - uint8_t *p = ( uint8_t * )dst; |
15 |
| - *p++ = ( uint8_t )w; w >>= 8; |
16 |
| - *p++ = ( uint8_t )w; w >>= 8; |
17 |
| - *p++ = ( uint8_t )w; w >>= 8; |
18 |
| - *p++ = ( uint8_t )w; |
19 |
| -#endif |
20 |
| -} |
21 |
| - |
22 |
| -static inline void |
23 |
| -store48( void *dst, uint64_t w ) |
24 |
| -{ |
25 |
| - uint8_t *p = ( uint8_t * )dst; |
26 |
| - *p++ = ( uint8_t )w; w >>= 8; |
27 |
| - *p++ = ( uint8_t )w; w >>= 8; |
28 |
| - *p++ = ( uint8_t )w; w >>= 8; |
29 |
| - *p++ = ( uint8_t )w; w >>= 8; |
30 |
| - *p++ = ( uint8_t )w; w >>= 8; |
31 |
| - *p++ = ( uint8_t )w; |
32 |
| -} |
33 |
| - |
34 |
| -static inline void |
35 |
| -store64( void *dst, uint64_t w ) |
36 |
| -{ |
37 |
| -#if defined(NATIVE_LITTLE_ENDIAN) |
38 |
| - memcpy( dst, &w, sizeof( w ) ); |
39 |
| -#else |
40 |
| - uint8_t *p = ( uint8_t * )dst; |
41 |
| - *p++ = ( uint8_t )w; w >>= 8; |
42 |
| - *p++ = ( uint8_t )w; w >>= 8; |
43 |
| - *p++ = ( uint8_t )w; w >>= 8; |
44 |
| - *p++ = ( uint8_t )w; w >>= 8; |
45 |
| - *p++ = ( uint8_t )w; w >>= 8; |
46 |
| - *p++ = ( uint8_t )w; w >>= 8; |
47 |
| - *p++ = ( uint8_t )w; w >>= 8; |
48 |
| - *p++ = ( uint8_t )w; |
49 |
| -#endif |
50 |
| -} |
51 |
| - |
52 |
| -static inline void |
53 |
| -secure_zero_memory(void *v, size_t n) |
54 |
| -{ |
55 |
| -#if defined(_WIN32) || defined(WIN32) |
56 |
| - SecureZeroMemory(v, n); |
57 |
| -#elif defined(__hpux) |
58 |
| - static void *(*const volatile memset_v)(void *, int, size_t) = &memset; |
59 |
| - memset_v(v, 0, n); |
60 |
| -#else |
61 |
| -// prioritize first the general C11 call |
62 |
| -#if defined(HAVE_MEMSET_S) |
63 |
| - memset_s(v, n, 0, n); |
64 |
| -#elif defined(HAVE_EXPLICIT_BZERO) |
65 |
| - explicit_bzero(v, n); |
66 |
| -#elif defined(HAVE_EXPLICIT_MEMSET) |
67 |
| - explicit_memset(v, 0, n); |
68 |
| -#else |
69 |
| - memset(v, 0, n); |
70 |
| - __asm__ __volatile__("" :: "r"(v) : "memory"); |
71 |
| -#endif |
72 |
| -#endif |
73 |
| -} |
74 |
| - |
75 | 7 | #else
|
76 | 8 | // use vendored copy of blake2
|
77 | 9 |
|
@@ -102,8 +34,10 @@ secure_zero_memory(void *v, size_t n)
|
102 | 34 | #define blake2sp_update PyBlake2_blake2sp_update
|
103 | 35 |
|
104 | 36 | #include "impl/blake2.h"
|
105 |
| -#include "impl/blake2-impl.h" /* for secure_zero_memory() and store48() */ |
106 | 37 |
|
107 | 38 | #endif // HAVE_LIBB2
|
108 | 39 |
|
| 40 | +// for secure_zero_memory(), store32(), store48(), and store64() |
| 41 | +#include "impl/blake2-impl.h" |
| 42 | + |
109 | 43 | #endif // Py_BLAKE2MODULE_H
|
0 commit comments