Skip to content

Commit 58d865d

Browse files
committed
Update scrypt.h
1 parent 546aaaa commit 58d865d

1 file changed

Lines changed: 23 additions & 17 deletions

File tree

src/crypto/scrypt.h

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,31 @@ void
2727
PBKDF2_SHA256(const uint8_t *passwd, size_t passwdlen, const uint8_t *salt,
2828
size_t saltlen, uint64_t c, uint8_t *buf, size_t dkLen);
2929

30-
// Use system-provided endian functions on BSD/macOS, provide our own elsewhere
30+
// Use system-provided endian functions when available, provide our own elsewhere
3131
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
32-
#include <sys/endian.h>
32+
// BSD/macOS: use sys/endian.h
33+
#include <sys/endian.h>
34+
#elif defined(__linux__) || defined(__GLIBC__)
35+
// Linux: use endian.h and provide BSD-style function names
36+
#include <endian.h>
37+
#define le32dec(p) le32toh(*(const uint32_t *)(p))
38+
#define le32enc(p, v) do { *(uint32_t *)(p) = htole32(v); } while (0)
3339
#else
34-
// Portable inline implementations for little-endian encoding/decoding
35-
static inline uint32_t le32dec(const void *pp)
36-
{
37-
const uint8_t *p = (uint8_t const *)pp;
38-
return ((uint32_t)(p[0]) + ((uint32_t)(p[1]) << 8) +
39-
((uint32_t)(p[2]) << 16) + ((uint32_t)(p[3]) << 24));
40-
}
40+
// Fallback: portable inline implementations for little-endian encoding/decoding
41+
static inline uint32_t le32dec(const void *pp)
42+
{
43+
const uint8_t *p = (uint8_t const *)pp;
44+
return ((uint32_t)(p[0]) + ((uint32_t)(p[1]) << 8) +
45+
((uint32_t)(p[2]) << 16) + ((uint32_t)(p[3]) << 24));
46+
}
4147

42-
static inline void le32enc(void *pp, uint32_t x)
43-
{
44-
uint8_t *p = (uint8_t *)pp;
45-
p[0] = x & 0xff;
46-
p[1] = (x >> 8) & 0xff;
47-
p[2] = (x >> 16) & 0xff;
48-
p[3] = (x >> 24) & 0xff;
49-
}
48+
static inline void le32enc(void *pp, uint32_t x)
49+
{
50+
uint8_t *p = (uint8_t *)pp;
51+
p[0] = x & 0xff;
52+
p[1] = (x >> 8) & 0xff;
53+
p[2] = (x >> 16) & 0xff;
54+
p[3] = (x >> 24) & 0xff;
55+
}
5056
#endif
5157
#endif

0 commit comments

Comments
 (0)