Test getentropy

We want to ensure that tools that call getentropy() are also
controlled appropriately.
This commit is contained in:
Daniel Kahn Gillmor
2021-02-24 16:03:57 -05:00
parent 20e74b1b02
commit 3db9d20828
4 changed files with 17 additions and 2 deletions

1
.gitignore vendored
View File

@@ -7,6 +7,7 @@ test/lib*.so
test/use_lib_random
test/use_lib_getpid
test/repeat_random
test/getentropy_test
src/libfaketime.dylib.1
src/libfaketime.1.dylib

View File

@@ -25,7 +25,7 @@ functest:
%_test: %_test.c
${CC} -o $@ ${CFLAGS} $<
randomtest: getrandom_test use_lib_random librandom.so repeat_random
randomtest: getrandom_test use_lib_random librandom.so repeat_random getentropy_test
./randomtest.sh
getpidtest: use_lib_getpid libgetpid.so

14
test/getentropy_test.c Normal file
View File

@@ -0,0 +1,14 @@
#include <unistd.h>
#include <stdio.h>
int main() {
unsigned char buf[16];
if (getentropy(buf, sizeof(buf))) {
perror("failed to getentropy()");
return 1;
}
for (size_t i = 0; i < sizeof(buf); i++)
printf("%02x", buf[i]);
printf("\n");
return 0;
}

View File

@@ -6,7 +6,7 @@ set -e
error=0
for iface in getrandom; do
for iface in getrandom getentropy; do
printf "Testing %s() interception...\n" "$iface"
"./${iface}_test" > "${iface}.alone"