diff --git a/README.md b/README.md index 66b481e5d0..63284caad8 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ To build, run: * With CMake: - `mkdir build && cmake build && cmake .. && cmake --build .` + `mkdir -p build && cd build && cmake .. && cmake --build .` * With Autotools: diff --git a/src/pbkdf2.cpp b/src/pbkdf2.cpp index c59a894089..bcd75f3f86 100644 --- a/src/pbkdf2.cpp +++ b/src/pbkdf2.cpp @@ -16,6 +16,7 @@ be32dec(const void *pp) } */ +#ifndef __FreeBSD__ static inline void be32enc(void *pp, uint32_t x) { @@ -26,7 +27,7 @@ be32enc(void *pp, uint32_t x) p[1] = (x >> 16) & 0xff; p[0] = (x >> 24) & 0xff; } - +#endif /** * PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, c, buf, dkLen): diff --git a/src/random.cpp b/src/random.cpp index 368fa1f9bc..bf360ad2ff 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -29,14 +29,10 @@ #include #endif -#ifdef HAVE_SYS_GETRANDOM -#include -#include -#endif -#if defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX) -#include +#if defined(HAVE_GETRANDOM) || (defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX)) #include #endif + #ifdef HAVE_SYSCTL_ARND #include #endif @@ -286,23 +282,14 @@ void GetOSRand(unsigned char *ent32) RandFailure(); } CryptReleaseContext(hProvider, 0); -#elif defined(HAVE_SYS_GETRANDOM) +#elif defined(HAVE_GETRANDOM) /* Linux. From the getrandom(2) man page: * "If the urandom source has been initialized, reads of up to 256 bytes * will always return as many bytes as requested and will not be * interrupted by signals." */ - int rv = syscall(SYS_getrandom, ent32, NUM_OS_RANDOM_BYTES, 0); - if (rv != NUM_OS_RANDOM_BYTES) { - if (rv < 0 && errno == ENOSYS) { - /* Fallback for kernel <3.17: the return value will be -1 and errno - * ENOSYS if the syscall is not available, in that case fall back - * to /dev/urandom. - */ - GetDevURandom(ent32); - } else { - RandFailure(); - } + if (getrandom(ent32, NUM_OS_RANDOM_BYTES, 0) != NUM_OS_RANDOM_BYTES) { + RandFailure(); } #elif defined(__OpenBSD__) /* OpenBSD. From the arc4random(3) man page: