Commit 5b7abbef authored by Evan Hunt's avatar Evan Hunt

[master] added isc_safe_memcmp()

3611.	[bug]		Improved resistance to a theoretical authentication
			attack based on differential timing.  [RT #33939]
parent 892506b6
3611. [bug] Improved resistance to a theoretical authentication
attack based on differential timing. [RT #33939]
3610. [cleanup] win32: Some executables had been omitted from the 3610. [cleanup] win32: Some executables had been omitted from the
installer. [RT #34116] installer. [RT #34116]
......
...@@ -1344,6 +1344,7 @@ PERL ...@@ -1344,6 +1344,7 @@ PERL
ETAGS ETAGS
LN LN
ARFLAGS ARFLAGS
CCNOOPT
CCOPT CCOPT
STD_CWARNINGS STD_CWARNINGS
STD_CDEFINES STD_CDEFINES
...@@ -11830,6 +11831,7 @@ fi ...@@ -11830,6 +11831,7 @@ fi
# Warn if the user specified libbind, which is now deprecated # Warn if the user specified libbind, which is now deprecated
# Check whether --enable-libbind was given. # Check whether --enable-libbind was given.
if test "${enable_libbind+set}" = set; then : if test "${enable_libbind+set}" = set; then :
...@@ -12910,6 +12912,13 @@ case "$host" in ...@@ -12910,6 +12912,13 @@ case "$host" in
;; ;;
esac esac
#
# CCNOOPT defaults to -O0 on gcc and disables optimization when is last
#
if test "X$CCNOOPT" = "X" -a "X$GCC" = "Xyes"; then
CCNOOPT="-O0"
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5
$as_echo_n "checking for ANSI C header files... " >&6; } $as_echo_n "checking for ANSI C header files... " >&6; }
if ${ac_cv_header_stdc+:} false; then : if ${ac_cv_header_stdc+:} false; then :
...@@ -15625,11 +15634,13 @@ then ...@@ -15625,11 +15634,13 @@ then
*-freebsd*) *-freebsd*)
CC="$CC -pthread" CC="$CC -pthread"
CCOPT="$CCOPT -pthread" CCOPT="$CCOPT -pthread"
CCNOOPT="$CCNOOPT -pthread"
STD_CDEFINES="$STD_CDEFINES -D_THREAD_SAFE" STD_CDEFINES="$STD_CDEFINES -D_THREAD_SAFE"
;; ;;
*-openbsd*) *-openbsd*)
CC="$CC -pthread" CC="$CC -pthread"
CCOPT="$CCOPT -pthread" CCOPT="$CCOPT -pthread"
CCNOOPT="$CCNOOPT -pthread"
;; ;;
*-solaris*) *-solaris*)
LIBS="$LIBS -lthread" LIBS="$LIBS -lthread"
...@@ -15643,10 +15654,12 @@ then ...@@ -15643,10 +15654,12 @@ then
*-dec-osf*) *-dec-osf*)
CC="$CC -pthread" CC="$CC -pthread"
CCOPT="$CCOPT -pthread" CCOPT="$CCOPT -pthread"
CCNOOPT="$CCNOOPT -pthread"
;; ;;
*-solaris*) *-solaris*)
CC="$CC -mt" CC="$CC -mt"
CCOPT="$CCOPT -mt" CCOPT="$CCOPT -mt"
CCNOOPT="$CCNOOPT -mt"
;; ;;
*-ibm-aix*) *-ibm-aix*)
STD_CDEFINES="$STD_CDEFINES -D_THREAD_SAFE" STD_CDEFINES="$STD_CDEFINES -D_THREAD_SAFE"
...@@ -15654,10 +15667,12 @@ then ...@@ -15654,10 +15667,12 @@ then
*-sco-sysv*uw*|*-*-sysv*UnixWare*) *-sco-sysv*uw*|*-*-sysv*UnixWare*)
CC="$CC -Kthread" CC="$CC -Kthread"
CCOPT="$CCOPT -Kthread" CCOPT="$CCOPT -Kthread"
CCNOOPT="$CCNOOPT -Kthread"
;; ;;
*-*-sysv*OpenUNIX*) *-*-sysv*OpenUNIX*)
CC="$CC -Kpthread" CC="$CC -Kpthread"
CCOPT="$CCOPT -Kpthread" CCOPT="$CCOPT -Kpthread"
CCNOOPT="$CCNOOPT -Kpthread"
;; ;;
esac esac
fi fi
...@@ -16197,6 +16212,7 @@ else ...@@ -16197,6 +16212,7 @@ else
*-dec-osf*) *-dec-osf*)
CC="$CC -std" CC="$CC -std"
CCOPT="$CCOPT -std" CCOPT="$CCOPT -std"
CCNOOPT="$CCNOOPT -std"
MKDEPCC="$CC" MKDEPCC="$CC"
;; ;;
*-hp-hpux*) *-hp-hpux*)
...@@ -16215,6 +16231,7 @@ else ...@@ -16215,6 +16231,7 @@ else
;; ;;
esac esac
CCOPT="$CCOPT -Ae -z" CCOPT="$CCOPT -Ae -z"
CCNOOPT="$CCNOOPT -Ae -z"
LDFLAGS="-Wl,+vnocompatwarnings $LDFLAGS" LDFLAGS="-Wl,+vnocompatwarnings $LDFLAGS"
MKDEPPROG='cc -Ae -E -Wp,-M >/dev/null 2>>$TMP' MKDEPPROG='cc -Ae -E -Wp,-M >/dev/null 2>>$TMP'
;; ;;
......
...@@ -50,6 +50,7 @@ AC_SUBST(STD_CINCLUDES) ...@@ -50,6 +50,7 @@ AC_SUBST(STD_CINCLUDES)
AC_SUBST(STD_CDEFINES) AC_SUBST(STD_CDEFINES)
AC_SUBST(STD_CWARNINGS) AC_SUBST(STD_CWARNINGS)
AC_SUBST(CCOPT) AC_SUBST(CCOPT)
AC_SUBST(CCNOOPT)
# Warn if the user specified libbind, which is now deprecated # Warn if the user specified libbind, which is now deprecated
AC_ARG_ENABLE(libbind, [ --enable-libbind deprecated]) AC_ARG_ENABLE(libbind, [ --enable-libbind deprecated])
...@@ -355,6 +356,13 @@ case "$host" in ...@@ -355,6 +356,13 @@ case "$host" in
;; ;;
esac esac
#
# CCNOOPT defaults to -O0 on gcc and disables optimization when is last
#
if test "X$CCNOOPT" = "X" -a "X$GCC" = "Xyes"; then
CCNOOPT="-O0"
fi
AC_HEADER_STDC AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h regex.h sys/time.h unistd.h sys/mman.h sys/sockio.h sys/select.h sys/param.h sys/sysctl.h net/if6.h,,, AC_CHECK_HEADERS(fcntl.h regex.h sys/time.h unistd.h sys/mman.h sys/sockio.h sys/select.h sys/param.h sys/sysctl.h net/if6.h,,,
...@@ -1307,11 +1315,13 @@ then ...@@ -1307,11 +1315,13 @@ then
*-freebsd*) *-freebsd*)
CC="$CC -pthread" CC="$CC -pthread"
CCOPT="$CCOPT -pthread" CCOPT="$CCOPT -pthread"
CCNOOPT="$CCNOOPT -pthread"
STD_CDEFINES="$STD_CDEFINES -D_THREAD_SAFE" STD_CDEFINES="$STD_CDEFINES -D_THREAD_SAFE"
;; ;;
*-openbsd*) *-openbsd*)
CC="$CC -pthread" CC="$CC -pthread"
CCOPT="$CCOPT -pthread" CCOPT="$CCOPT -pthread"
CCNOOPT="$CCNOOPT -pthread"
;; ;;
*-solaris*) *-solaris*)
LIBS="$LIBS -lthread" LIBS="$LIBS -lthread"
...@@ -1325,10 +1335,12 @@ then ...@@ -1325,10 +1335,12 @@ then
*-dec-osf*) *-dec-osf*)
CC="$CC -pthread" CC="$CC -pthread"
CCOPT="$CCOPT -pthread" CCOPT="$CCOPT -pthread"
CCNOOPT="$CCNOOPT -pthread"
;; ;;
*-solaris*) *-solaris*)
CC="$CC -mt" CC="$CC -mt"
CCOPT="$CCOPT -mt" CCOPT="$CCOPT -mt"
CCNOOPT="$CCNOOPT -mt"
;; ;;
*-ibm-aix*) *-ibm-aix*)
STD_CDEFINES="$STD_CDEFINES -D_THREAD_SAFE" STD_CDEFINES="$STD_CDEFINES -D_THREAD_SAFE"
...@@ -1336,10 +1348,12 @@ then ...@@ -1336,10 +1348,12 @@ then
*-sco-sysv*uw*|*-*-sysv*UnixWare*) *-sco-sysv*uw*|*-*-sysv*UnixWare*)
CC="$CC -Kthread" CC="$CC -Kthread"
CCOPT="$CCOPT -Kthread" CCOPT="$CCOPT -Kthread"
CCNOOPT="$CCNOOPT -Kthread"
;; ;;
*-*-sysv*OpenUNIX*) *-*-sysv*OpenUNIX*)
CC="$CC -Kpthread" CC="$CC -Kpthread"
CCOPT="$CCOPT -Kpthread" CCOPT="$CCOPT -Kpthread"
CCNOOPT="$CCNOOPT -Kpthread"
;; ;;
esac esac
fi fi
...@@ -1591,6 +1605,7 @@ else ...@@ -1591,6 +1605,7 @@ else
*-dec-osf*) *-dec-osf*)
CC="$CC -std" CC="$CC -std"
CCOPT="$CCOPT -std" CCOPT="$CCOPT -std"
CCNOOPT="$CCNOOPT -std"
MKDEPCC="$CC" MKDEPCC="$CC"
;; ;;
*-hp-hpux*) *-hp-hpux*)
...@@ -1609,6 +1624,7 @@ else ...@@ -1609,6 +1624,7 @@ else
;; ;;
esac esac
CCOPT="$CCOPT -Ae -z" CCOPT="$CCOPT -Ae -z"
CCNOOPT="$CCNOOPT -Ae -z"
LDFLAGS="-Wl,+vnocompatwarnings $LDFLAGS" LDFLAGS="-Wl,+vnocompatwarnings $LDFLAGS"
MKDEPPROG='cc -Ae -E -Wp,-M >/dev/null 2>>$TMP' MKDEPPROG='cc -Ae -E -Wp,-M >/dev/null 2>>$TMP'
;; ;;
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include <isc/md5.h> #include <isc/md5.h>
#include <isc/sha1.h> #include <isc/sha1.h>
#include <isc/mem.h> #include <isc/mem.h>
#include <isc/safe.h>
#include <isc/string.h> #include <isc/string.h>
#include <isc/util.h> #include <isc/util.h>
...@@ -138,7 +139,7 @@ hmacmd5_compare(const dst_key_t *key1, const dst_key_t *key2) { ...@@ -138,7 +139,7 @@ hmacmd5_compare(const dst_key_t *key1, const dst_key_t *key2) {
else if (hkey1 == NULL || hkey2 == NULL) else if (hkey1 == NULL || hkey2 == NULL)
return (ISC_FALSE); return (ISC_FALSE);
if (memcmp(hkey1->key, hkey2->key, ISC_SHA1_BLOCK_LENGTH) == 0) if (isc_safe_memcmp(hkey1->key, hkey2->key, ISC_SHA1_BLOCK_LENGTH))
return (ISC_TRUE); return (ISC_TRUE);
else else
return (ISC_FALSE); return (ISC_FALSE);
...@@ -415,7 +416,7 @@ hmacsha1_compare(const dst_key_t *key1, const dst_key_t *key2) { ...@@ -415,7 +416,7 @@ hmacsha1_compare(const dst_key_t *key1, const dst_key_t *key2) {
else if (hkey1 == NULL || hkey2 == NULL) else if (hkey1 == NULL || hkey2 == NULL)
return (ISC_FALSE); return (ISC_FALSE);
if (memcmp(hkey1->key, hkey2->key, ISC_SHA1_BLOCK_LENGTH) == 0) if (isc_safe_memcmp(hkey1->key, hkey2->key, ISC_SHA1_BLOCK_LENGTH))
return (ISC_TRUE); return (ISC_TRUE);
else else
return (ISC_FALSE); return (ISC_FALSE);
...@@ -692,7 +693,7 @@ hmacsha224_compare(const dst_key_t *key1, const dst_key_t *key2) { ...@@ -692,7 +693,7 @@ hmacsha224_compare(const dst_key_t *key1, const dst_key_t *key2) {
else if (hkey1 == NULL || hkey2 == NULL) else if (hkey1 == NULL || hkey2 == NULL)
return (ISC_FALSE); return (ISC_FALSE);
if (memcmp(hkey1->key, hkey2->key, ISC_SHA224_BLOCK_LENGTH) == 0) if (isc_safe_memcmp(hkey1->key, hkey2->key, ISC_SHA224_BLOCK_LENGTH))
return (ISC_TRUE); return (ISC_TRUE);
else else
return (ISC_FALSE); return (ISC_FALSE);
...@@ -971,7 +972,7 @@ hmacsha256_compare(const dst_key_t *key1, const dst_key_t *key2) { ...@@ -971,7 +972,7 @@ hmacsha256_compare(const dst_key_t *key1, const dst_key_t *key2) {
else if (hkey1 == NULL || hkey2 == NULL) else if (hkey1 == NULL || hkey2 == NULL)
return (ISC_FALSE); return (ISC_FALSE);
if (memcmp(hkey1->key, hkey2->key, ISC_SHA256_BLOCK_LENGTH) == 0) if (isc_safe_memcmp(hkey1->key, hkey2->key, ISC_SHA256_BLOCK_LENGTH))
return (ISC_TRUE); return (ISC_TRUE);
else else
return (ISC_FALSE); return (ISC_FALSE);
...@@ -1250,7 +1251,7 @@ hmacsha384_compare(const dst_key_t *key1, const dst_key_t *key2) { ...@@ -1250,7 +1251,7 @@ hmacsha384_compare(const dst_key_t *key1, const dst_key_t *key2) {
else if (hkey1 == NULL || hkey2 == NULL) else if (hkey1 == NULL || hkey2 == NULL)
return (ISC_FALSE); return (ISC_FALSE);
if (memcmp(hkey1->key, hkey2->key, ISC_SHA384_BLOCK_LENGTH) == 0) if (isc_safe_memcmp(hkey1->key, hkey2->key, ISC_SHA384_BLOCK_LENGTH))
return (ISC_TRUE); return (ISC_TRUE);
else else
return (ISC_FALSE); return (ISC_FALSE);
...@@ -1529,7 +1530,7 @@ hmacsha512_compare(const dst_key_t *key1, const dst_key_t *key2) { ...@@ -1529,7 +1530,7 @@ hmacsha512_compare(const dst_key_t *key1, const dst_key_t *key2) {
else if (hkey1 == NULL || hkey2 == NULL) else if (hkey1 == NULL || hkey2 == NULL)
return (ISC_FALSE); return (ISC_FALSE);
if (memcmp(hkey1->key, hkey2->key, ISC_SHA512_BLOCK_LENGTH) == 0) if (isc_safe_memcmp(hkey1->key, hkey2->key, ISC_SHA512_BLOCK_LENGTH))
return (ISC_TRUE); return (ISC_TRUE);
else else
return (ISC_FALSE); return (ISC_FALSE);
......
...@@ -62,7 +62,7 @@ OBJS = @ISC_EXTRA_OBJS@ \ ...@@ -62,7 +62,7 @@ OBJS = @ISC_EXTRA_OBJS@ \
parseint.@O@ portset.@O@ quota.@O@ radix.@O@ random.@O@ \ parseint.@O@ portset.@O@ quota.@O@ radix.@O@ random.@O@ \
ratelimiter.@O@ refcount.@O@ region.@O@ regex.@O@ result.@O@ \ ratelimiter.@O@ refcount.@O@ region.@O@ regex.@O@ result.@O@ \
rwlock.@O@ \ rwlock.@O@ \
serial.@O@ sha1.@O@ sha2.@O@ sockaddr.@O@ stats.@O@ \ safe.@O@ serial.@O@ sha1.@O@ sha2.@O@ sockaddr.@O@ stats.@O@ \
string.@O@ strtoul.@O@ symtab.@O@ task.@O@ taskpool.@O@ \ string.@O@ strtoul.@O@ symtab.@O@ task.@O@ taskpool.@O@ \
timer.@O@ version.@O@ ${UNIXOBJS} ${NLSOBJS} ${THREADOBJS} timer.@O@ version.@O@ ${UNIXOBJS} ${NLSOBJS} ${THREADOBJS}
SYMTBLOBJS = backtrace-emptytbl.@O@ SYMTBLOBJS = backtrace-emptytbl.@O@
...@@ -78,8 +78,9 @@ SRCS = @ISC_EXTRA_SRCS@ \ ...@@ -78,8 +78,9 @@ SRCS = @ISC_EXTRA_SRCS@ \
netaddr.c netscope.c pool.c ondestroy.c \ netaddr.c netscope.c pool.c ondestroy.c \
parseint.c portset.c quota.c radix.c random.c \ parseint.c portset.c quota.c radix.c random.c \
ratelimiter.c refcount.c region.c regex.c result.c rwlock.c \ ratelimiter.c refcount.c region.c regex.c result.c rwlock.c \
serial.c sha1.c sha2.c sockaddr.c stats.c string.c strtoul.c \ safe.c serial.c sha1.c sha2.c sockaddr.c stats.c string.c \
symtab.c symtbl-empty.c task.c taskpool.c timer.c version.c strtoul.c symtab.c symtbl-empty.c task.c taskpool.c timer.c \
version.c
LIBS = @LIBS@ LIBS = @LIBS@
...@@ -93,6 +94,10 @@ TESTDIRS = @UNITTESTS@ ...@@ -93,6 +94,10 @@ TESTDIRS = @UNITTESTS@
@BIND9_MAKE_RULES@ @BIND9_MAKE_RULES@
safe.@O@: safe.c
${LIBTOOL_MODE_COMPILE} ${CC} ${ALL_CFLAGS} @CCNOOPT@ \
-c ${srcdir}/safe.c
version.@O@: version.c version.@O@: version.c
${LIBTOOL_MODE_COMPILE} ${CC} ${ALL_CFLAGS} \ ${LIBTOOL_MODE_COMPILE} ${CC} ${ALL_CFLAGS} \
-DVERSION=\"${VERSION}\" \ -DVERSION=\"${VERSION}\" \
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <isc/hmacmd5.h> #include <isc/hmacmd5.h>
#include <isc/md5.h> #include <isc/md5.h>
#include <isc/platform.h> #include <isc/platform.h>
#include <isc/safe.h>
#include <isc/string.h> #include <isc/string.h>
#include <isc/types.h> #include <isc/types.h>
#include <isc/util.h> #include <isc/util.h>
...@@ -145,5 +146,5 @@ isc_hmacmd5_verify2(isc_hmacmd5_t *ctx, unsigned char *digest, size_t len) { ...@@ -145,5 +146,5 @@ isc_hmacmd5_verify2(isc_hmacmd5_t *ctx, unsigned char *digest, size_t len) {
REQUIRE(len <= ISC_MD5_DIGESTLENGTH); REQUIRE(len <= ISC_MD5_DIGESTLENGTH);
isc_hmacmd5_sign(ctx, newdigest); isc_hmacmd5_sign(ctx, newdigest);
return (ISC_TF(memcmp(digest, newdigest, len) == 0)); return (isc_safe_memcmp(digest, newdigest, len));
} }
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <isc/assertions.h> #include <isc/assertions.h>
#include <isc/hmacsha.h> #include <isc/hmacsha.h>
#include <isc/platform.h> #include <isc/platform.h>
#include <isc/safe.h>
#include <isc/sha1.h> #include <isc/sha1.h>
#include <isc/sha2.h> #include <isc/sha2.h>
#include <isc/string.h> #include <isc/string.h>
...@@ -538,7 +539,7 @@ isc_hmacsha1_verify(isc_hmacsha1_t *ctx, unsigned char *digest, size_t len) { ...@@ -538,7 +539,7 @@ isc_hmacsha1_verify(isc_hmacsha1_t *ctx, unsigned char *digest, size_t len) {
REQUIRE(len <= ISC_SHA1_DIGESTLENGTH); REQUIRE(len <= ISC_SHA1_DIGESTLENGTH);
isc_hmacsha1_sign(ctx, newdigest, ISC_SHA1_DIGESTLENGTH); isc_hmacsha1_sign(ctx, newdigest, ISC_SHA1_DIGESTLENGTH);
return (ISC_TF(memcmp(digest, newdigest, len) == 0)); return (isc_safe_memcmp(digest, newdigest, len));
} }
/* /*
...@@ -551,7 +552,7 @@ isc_hmacsha224_verify(isc_hmacsha224_t *ctx, unsigned char *digest, size_t len) ...@@ -551,7 +552,7 @@ isc_hmacsha224_verify(isc_hmacsha224_t *ctx, unsigned char *digest, size_t len)
REQUIRE(len <= ISC_SHA224_DIGESTLENGTH); REQUIRE(len <= ISC_SHA224_DIGESTLENGTH);
isc_hmacsha224_sign(ctx, newdigest, ISC_SHA224_DIGESTLENGTH); isc_hmacsha224_sign(ctx, newdigest, ISC_SHA224_DIGESTLENGTH);
return (ISC_TF(memcmp(digest, newdigest, len) == 0)); return (isc_safe_memcmp(digest, newdigest, len));
} }
/* /*
...@@ -564,7 +565,7 @@ isc_hmacsha256_verify(isc_hmacsha256_t *ctx, unsigned char *digest, size_t len) ...@@ -564,7 +565,7 @@ isc_hmacsha256_verify(isc_hmacsha256_t *ctx, unsigned char *digest, size_t len)
REQUIRE(len <= ISC_SHA256_DIGESTLENGTH); REQUIRE(len <= ISC_SHA256_DIGESTLENGTH);
isc_hmacsha256_sign(ctx, newdigest, ISC_SHA256_DIGESTLENGTH); isc_hmacsha256_sign(ctx, newdigest, ISC_SHA256_DIGESTLENGTH);
return (ISC_TF(memcmp(digest, newdigest, len) == 0)); return (isc_safe_memcmp(digest, newdigest, len));
} }
/* /*
...@@ -577,7 +578,7 @@ isc_hmacsha384_verify(isc_hmacsha384_t *ctx, unsigned char *digest, size_t len) ...@@ -577,7 +578,7 @@ isc_hmacsha384_verify(isc_hmacsha384_t *ctx, unsigned char *digest, size_t len)
REQUIRE(len <= ISC_SHA384_DIGESTLENGTH); REQUIRE(len <= ISC_SHA384_DIGESTLENGTH);
isc_hmacsha384_sign(ctx, newdigest, ISC_SHA384_DIGESTLENGTH); isc_hmacsha384_sign(ctx, newdigest, ISC_SHA384_DIGESTLENGTH);
return (ISC_TF(memcmp(digest, newdigest, len) == 0)); return (isc_safe_memcmp(digest, newdigest, len));
} }
/* /*
...@@ -590,5 +591,5 @@ isc_hmacsha512_verify(isc_hmacsha512_t *ctx, unsigned char *digest, size_t len) ...@@ -590,5 +591,5 @@ isc_hmacsha512_verify(isc_hmacsha512_t *ctx, unsigned char *digest, size_t len)
REQUIRE(len <= ISC_SHA512_DIGESTLENGTH); REQUIRE(len <= ISC_SHA512_DIGESTLENGTH);
isc_hmacsha512_sign(ctx, newdigest, ISC_SHA512_DIGESTLENGTH); isc_hmacsha512_sign(ctx, newdigest, ISC_SHA512_DIGESTLENGTH);
return (ISC_TF(memcmp(digest, newdigest, len) == 0)); return (isc_safe_memcmp(digest, newdigest, len));
} }
...@@ -37,7 +37,7 @@ HEADERS = app.h assertions.h base64.h bind9.h bitstring.h boolean.h \ ...@@ -37,7 +37,7 @@ HEADERS = app.h assertions.h base64.h bind9.h bitstring.h boolean.h \
namespace.h netaddr.h ondestroy.h os.h parseint.h \ namespace.h netaddr.h ondestroy.h os.h parseint.h \
print.h quota.h radix.h random.h ratelimiter.h \ print.h quota.h radix.h random.h ratelimiter.h \
refcount.h regex.h region.h resource.h \ refcount.h regex.h region.h resource.h \
result.h resultclass.h rwlock.h serial.h sha1.h sha2.h \ result.h resultclass.h rwlock.h safe.h serial.h sha1.h sha2.h \
sockaddr.h socket.h stdio.h stdlib.h string.h \ sockaddr.h socket.h stdio.h stdlib.h string.h \
symtab.h \ symtab.h \
task.h taskpool.h timer.h types.h util.h version.h \ task.h taskpool.h timer.h types.h util.h version.h \
......
/*
* Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id$ */
#ifndef ISC_SAFE_H
#define ISC_SAFE_H 1
/*! \file isc/safe.h */
#include <isc/types.h>
ISC_LANG_BEGINDECLS
isc_boolean_t
isc_safe_memcmp(const void *s1, const void *s2, size_t n);
/*%<
* Clone of libc memcmp() safe to differential timing attacks.
*/
ISC_LANG_ENDDECLS
#endif /* ISC_SAFE_H */
/*
* Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id$ */
/*! \file */
#include <config.h>
#include <isc/safe.h>
#include <isc/util.h>
#ifdef _MSC_VER
#pragma optimize("", off)
#endif
isc_boolean_t
isc_safe_memcmp(const void *s1, const void *s2, size_t n) {
isc_uint8_t acc = 0;
if (n != 0) {
const isc_uint8_t *p1 = s1, *p2 = s2;
do {
acc |= *p1++ ^ *p2++;
} while (--n != 0);
}
return (ISC_TF(acc == 0));
}
...@@ -37,13 +37,14 @@ LIBS = @LIBS@ @ATFLIBS@ ...@@ -37,13 +37,14 @@ LIBS = @LIBS@ @ATFLIBS@
OBJS = isctest.@O@ OBJS = isctest.@O@
SRCS = isctest.c taskpool_test.c socket_test.c hash_test.c \ SRCS = isctest.c taskpool_test.c socket_test.c hash_test.c \
sockaddr_test.c symtab_test.c task_test.c queue_test.c \ sockaddr_test.c symtab_test.c task_test.c queue_test.c \
parse_test.c pool_test.c regex_test.c socket_test.c parse_test.c pool_test.c regex_test.c socket_test.c \
safe_test.c
SUBDIRS = SUBDIRS =
TARGETS = taskpool_test@EXEEXT@ socket_test@EXEEXT@ hash_test@EXEEXT@ \ TARGETS = taskpool_test@EXEEXT@ socket_test@EXEEXT@ hash_test@EXEEXT@ \
sockaddr_test@EXEEXT@ symtab_test@EXEEXT@ task_test@EXEEXT@ \ sockaddr_test@EXEEXT@ symtab_test@EXEEXT@ task_test@EXEEXT@ \
queue_test@EXEEXT@ parse_test@EXEEXT@ pool_test@EXEEXT@ \ queue_test@EXEEXT@ parse_test@EXEEXT@ pool_test@EXEEXT@ \
regex_test@EXEEXT@ socket_test@EXEEXT@ regex_test@EXEEXT@ socket_test@EXEEXT@ safe_test@EXEEXT@
@BIND9_MAKE_RULES@ @BIND9_MAKE_RULES@
...@@ -87,6 +88,10 @@ regex_test@EXEEXT@: regex_test.@O@ ${ISCDEPLIBS} ...@@ -87,6 +88,10 @@ regex_test@EXEEXT@: regex_test.@O@ ${ISCDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \ ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
regex_test.@O@ ${ISCLIBS} ${LIBS} regex_test.@O@ ${ISCLIBS} ${LIBS}
safe_test@EXEEXT@: safe_test.@O@ ${ISCDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
safe_test.@O@ ${ISCLIBS} ${LIBS}
unit:: unit::
sh ${top_srcdir}/unit/unittest.sh sh ${top_srcdir}/unit/unittest.sh
......
/*
* Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM