Skip to content

Commit

Permalink
Fix be2enc and be2dec includes
Browse files Browse the repository at this point in the history
  • Loading branch information
chromatic committed Nov 29, 2024
1 parent b4a5d2b commit 9663ddf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ AC_CHECK_DECLS([strnlen])
# Check for daemon(3), unrelated to --with-daemon (although used by it)
AC_CHECK_DECLS([daemon])

AC_CHECK_DECLS([le16toh, le32toh, le64toh, htole16, htole32, htole64, be16toh, be32toh, be64toh, htobe16, htobe32, htobe64],,,
AC_CHECK_DECLS([le16toh, le32toh, le64toh, htole16, htole32, htole64, be16toh, be32toh, be64toh, htobe16, htobe32, htobe64, be32dec, be32enc],,,
[#if HAVE_ENDIAN_H
#include <endian.h>
#elif HAVE_SYS_ENDIAN_H
Expand Down
20 changes: 20 additions & 0 deletions src/compat/endian.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,26 @@ inline uint64_t le64toh(uint64_t little_endian_64bits)
}
#endif // HAVE_DECL_LE64TOH

#if HAVE_DECL_BE32DEC == 0
static inline uint32_t be32dec(const void *pp)
{
const uint8_t *p = (uint8_t const *)pp;
return ((uint32_t)(p[3]) + ((uint32_t)(p[2]) << 8) +
((uint32_t)(p[1]) << 16) + ((uint32_t)(p[0]) << 24));
}
#endif // HAVE_DECL_BE32DEC

#if HAVE_DECL_BE32ENC == 0
static inline void be32enc(void *pp, uint32_t x)
{
uint8_t *p = (uint8_t *)pp;
p[3] = x & 0xff;
p[2] = (x >> 8) & 0xff;
p[1] = (x >> 16) & 0xff;
p[0] = (x >> 24) & 0xff;
}
#endif // HAVE_DECL_BE32ENC

#endif // WORDS_BIGENDIAN

#endif // BITCOIN_COMPAT_ENDIAN_H
19 changes: 1 addition & 18 deletions src/crypto/scrypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "compat/endian.h"

#if defined(USE_SSE2) && !defined(USE_SSE2_ALWAYS)
#ifdef _MSC_VER
Expand All @@ -43,24 +44,6 @@
#endif
#endif

#ifndef __FreeBSD__
static inline uint32_t be32dec(const void *pp)
{
const uint8_t *p = (uint8_t const *)pp;
return ((uint32_t)(p[3]) + ((uint32_t)(p[2]) << 8) +
((uint32_t)(p[1]) << 16) + ((uint32_t)(p[0]) << 24));
}

static inline void be32enc(void *pp, uint32_t x)
{
uint8_t *p = (uint8_t *)pp;
p[3] = x & 0xff;
p[2] = (x >> 8) & 0xff;
p[1] = (x >> 16) & 0xff;
p[0] = (x >> 24) & 0xff;
}

#endif
/**
* PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, c, buf, dkLen):
* Compute PBKDF2(passwd, salt, c, dkLen) using HMAC-SHA256 as the PRF, and
Expand Down

0 comments on commit 9663ddf

Please sign in to comment.