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:
Zach Brown
2016-09-27 09:47:50 -07:00
parent 4ccb80a8ec
commit 0dff7f55a6
2 changed files with 5 additions and 23 deletions

View File

@@ -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 $<]

View File

@@ -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);
}