mirror of
https://github.com/versity/scoutfs.git
synced 2026-01-04 11:24:21 +00:00
Use openssl for pseudo random bytes
The pseudo random byte wrapper function used the intel instructions so that it could deal with high call rates, like initializing random node priorities for a large treap. But this is obviously not remotely portable and has the annoying habit of tripping up versions of valgrind that haven't yet learned about these instructions. We don't actually have high bandwidth callers so let's back off and just let openssl take care of this for us. Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
CFLAGS := -Wall -O2 -Werror -D_FILE_OFFSET_BITS=64 -g -mrdrnd -msse4.2 \
|
||||
CFLAGS := -Wall -O2 -Werror -D_FILE_OFFSET_BITS=64 -g -msse4.2 \
|
||||
-fno-strict-aliasing
|
||||
|
||||
BIN := src/scoutfs
|
||||
@@ -21,7 +21,7 @@ endif
|
||||
|
||||
$(BIN): $(OBJ)
|
||||
$(QU) [BIN $@]
|
||||
$(VE)gcc -o $@ $^ -luuid -lm
|
||||
$(VE)gcc -o $@ $^ -luuid -lm -lcrypto
|
||||
|
||||
%.o %.d: %.c Makefile sparse.sh
|
||||
$(QU) [CC $<]
|
||||
|
||||
@@ -4,27 +4,9 @@
|
||||
#include "sparse.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <openssl/rand.h>
|
||||
|
||||
void pseudo_random_bytes(void *data, unsigned int len)
|
||||
{
|
||||
unsigned long long tmp;
|
||||
unsigned long long *ll = data;
|
||||
unsigned int sz = sizeof(*ll);
|
||||
unsigned int unaligned;
|
||||
|
||||
/* see if the initial buffer is unaligned */
|
||||
unaligned = min((unsigned long)data & (sz - 1), len);
|
||||
if (unaligned) {
|
||||
__builtin_ia32_rdrand64_step(&tmp);
|
||||
memcpy(data, &tmp, unaligned);
|
||||
data += unaligned;
|
||||
len -= unaligned;
|
||||
}
|
||||
|
||||
for (ll = data; len >= sz; ll++, len -= sz)
|
||||
__builtin_ia32_rdrand64_step(ll);
|
||||
|
||||
if (len) {
|
||||
__builtin_ia32_rdrand64_step(&tmp);
|
||||
memcpy(ll, &tmp, len);
|
||||
}
|
||||
RAND_pseudo_bytes(data, len);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user