Skip to content

Commit 285b254

Browse files
committed
Use zero memory and store helpers from blake2-impl.h
1 parent 4c0ddb7 commit 285b254

File tree

1 file changed

+3
-69
lines changed

1 file changed

+3
-69
lines changed

Modules/_blake2/blake2module.h

Lines changed: 3 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,6 @@
44
#ifdef HAVE_LIBB2
55
#include <blake2.h>
66

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-
757
#else
768
// use vendored copy of blake2
779

@@ -102,8 +34,10 @@ secure_zero_memory(void *v, size_t n)
10234
#define blake2sp_update PyBlake2_blake2sp_update
10335

10436
#include "impl/blake2.h"
105-
#include "impl/blake2-impl.h" /* for secure_zero_memory() and store48() */
10637

10738
#endif // HAVE_LIBB2
10839

40+
// for secure_zero_memory(), store32(), store48(), and store64()
41+
#include "impl/blake2-impl.h"
42+
10943
#endif // Py_BLAKE2MODULE_H

0 commit comments

Comments
 (0)