Skip to content

Commit 9ba9e8a

Browse files
authored
Merge pull request #2770 from wilkart/fix-build-freebsd
fix build on FreeBSD
2 parents 5644af6 + 1a6f001 commit 9ba9e8a

File tree

3 files changed

+8
-20
lines changed

3 files changed

+8
-20
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ To build, run:
2727

2828
* With CMake:
2929

30-
`mkdir build && cmake build && cmake .. && cmake --build .`
30+
`mkdir -p build && cd build && cmake .. && cmake --build .`
3131

3232
* With Autotools:
3333

src/pbkdf2.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ be32dec(const void *pp)
1616
}
1717
*/
1818

19+
#ifndef __FreeBSD__
1920
static inline void
2021
be32enc(void *pp, uint32_t x)
2122
{
@@ -26,7 +27,7 @@ be32enc(void *pp, uint32_t x)
2627
p[1] = (x >> 16) & 0xff;
2728
p[0] = (x >> 24) & 0xff;
2829
}
29-
30+
#endif
3031

3132
/**
3233
* PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, c, buf, dkLen):

src/random.cpp

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,10 @@
2929
#include <sys/time.h>
3030
#endif
3131

32-
#ifdef HAVE_SYS_GETRANDOM
33-
#include <sys/syscall.h>
34-
#include <linux/random.h>
35-
#endif
36-
#if defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX)
37-
#include <unistd.h>
32+
#if defined(HAVE_GETRANDOM) || (defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX))
3833
#include <sys/random.h>
3934
#endif
35+
4036
#ifdef HAVE_SYSCTL_ARND
4137
#include <sys/sysctl.h>
4238
#endif
@@ -286,23 +282,14 @@ void GetOSRand(unsigned char *ent32)
286282
RandFailure();
287283
}
288284
CryptReleaseContext(hProvider, 0);
289-
#elif defined(HAVE_SYS_GETRANDOM)
285+
#elif defined(HAVE_GETRANDOM)
290286
/* Linux. From the getrandom(2) man page:
291287
* "If the urandom source has been initialized, reads of up to 256 bytes
292288
* will always return as many bytes as requested and will not be
293289
* interrupted by signals."
294290
*/
295-
int rv = syscall(SYS_getrandom, ent32, NUM_OS_RANDOM_BYTES, 0);
296-
if (rv != NUM_OS_RANDOM_BYTES) {
297-
if (rv < 0 && errno == ENOSYS) {
298-
/* Fallback for kernel <3.17: the return value will be -1 and errno
299-
* ENOSYS if the syscall is not available, in that case fall back
300-
* to /dev/urandom.
301-
*/
302-
GetDevURandom(ent32);
303-
} else {
304-
RandFailure();
305-
}
291+
if (getrandom(ent32, NUM_OS_RANDOM_BYTES, 0) != NUM_OS_RANDOM_BYTES) {
292+
RandFailure();
306293
}
307294
#elif defined(__OpenBSD__)
308295
/* OpenBSD. From the arc4random(3) man page:

0 commit comments

Comments
 (0)