Skip to content

Commit 46b6a36

Browse files
committed
compat: use timingsafe_bcmp if available
Its return value is the opposite of consttime_memequal. This function is available all modern BSD's except for NetBSD where we have consttime_memequal.
1 parent 16d6560 commit 46b6a36

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

configure

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,9 +1150,31 @@ EOF
11501150
echo "$CONSTTIME_MEMEQUAL"
11511151
rm -f _consttime_memequal.c _consttime_memequal
11521152
fi
1153+
if [ "$CONSTTIME_MEMEQUAL" = no ] && [ -z "$TIMINGSAFE_BCMP" ]; then
1154+
printf "Testing for timingsafe_bcmp ... "
1155+
cat <<EOF >_timingsafe_bcmp.c
1156+
#include <string.h>
1157+
int main(void) {
1158+
return timingsafe_bcmp("deadbeef", "deadbeef", 8);
1159+
}
1160+
EOF
1161+
if $XCC _timingsafe_bcmp.c -o _timingsafe_bcmp 2>&3; then
1162+
TIMINGSAFE_BCMP=yes
1163+
else
1164+
TIMINGSAFE_BCMP=no
1165+
fi
1166+
echo "$TIMINGSAFE_BCMP"
1167+
rm -f _timingsafe_bcmp.c _timingsafe_bcmp
1168+
fi
1169+
11531170
if [ "$CONSTTIME_MEMEQUAL" = no ]; then
1154-
echo "#include \"compat/consttime_memequal.h\"" \
1155-
>>$CONFIG_H
1171+
if [ "$TIMINGSAFE_BCMP" = yes ]; then
1172+
echo "#define consttime_memequal !timingsafe_bcmp" \
1173+
>>$CONFIG_H
1174+
else
1175+
echo "#include \"compat/consttime_memequal.h\"" \
1176+
>>$CONFIG_H
1177+
fi
11561178
fi
11571179

11581180
if [ -z "$DPRINTF" ]; then

0 commit comments

Comments
 (0)