]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Replace isc_safe routines with their OpenSSL counter parts
authorOndřej Surý <ondrej@sury.org>
Wed, 25 Apr 2018 12:04:31 +0000 (14:04 +0200)
committerOndřej Surý <ondrej@sury.org>
Fri, 20 Jul 2018 04:34:26 +0000 (00:34 -0400)
lib/isc/Makefile.in
lib/isc/include/isc/safe.h
lib/isc/safe.c [deleted file]
lib/isc/win32/libisc.def.in
lib/isc/win32/libisc.vcxproj.filters.in
lib/isc/win32/libisc.vcxproj.in

index 7fcc405760fa683e3be1e063a9592b277148a09e..eede04eaf168354db8e00ba07edc4fd0d1a68833 100644 (file)
@@ -58,7 +58,7 @@ OBJS =                @ISC_EXTRA_OBJS@ pk11.@O@ pk11_result.@O@ \
                parseint.@O@ portset.@O@ quota.@O@ radix.@O@ random.@O@ \
                ratelimiter.@O@ refcount.@O@ region.@O@ regex.@O@ result.@O@ \
                rwlock.@O@ \
-               safe.@O@ serial.@O@ sha1.@O@ sha2.@O@ sockaddr.@O@ stats.@O@ \
+               serial.@O@ sha1.@O@ sha2.@O@ sockaddr.@O@ stats.@O@ \
                string.@O@ strtoul.@O@ symtab.@O@ task.@O@ taskpool.@O@ \
                tm.@O@ timer.@O@ version.@O@ \
                ${UNIXOBJS} ${NLSOBJS} ${THREADOBJS}
@@ -75,7 +75,7 @@ SRCS =                @ISC_EXTRA_SRCS@ pk11.c pk11_result.c \
                netaddr.c netscope.c nonce.c openssl_shim.c pool.c \
                parseint.c portset.c quota.c radix.c random.c \
                ratelimiter.c refcount.c region.c regex.c result.c rwlock.c \
-               safe.c serial.c sha1.c sha2.c sockaddr.c stats.c string.c \
+               serial.c sha1.c sha2.c sockaddr.c stats.c string.c \
                strtoul.c symtab.c task.c taskpool.c timer.c \
                tm.c version.c
 
@@ -91,10 +91,6 @@ TESTDIRS =   @UNITTESTS@
 
 @BIND9_MAKE_RULES@
 
-safe.@O@: safe.c
-       ${LIBTOOL_MODE_COMPILE} ${CC} ${ALL_CFLAGS} @CCNOOPT@ \
-               -c ${srcdir}/safe.c
-
 version.@O@: version.c
        ${LIBTOOL_MODE_COMPILE} ${CC} ${ALL_CFLAGS} \
                -DVERSION=\"${VERSION}\" \
index f29f00bac6d1ca7b7966f76c80d5edc9c179d231..cba570fdf53d57985d9cf405a2c707431ef438f3 100644 (file)
 
 /*! \file isc/safe.h */
 
-#include <isc/types.h>
-#include <stdlib.h>
+#include <isc/boolean.h>
+#include <isc/lang.h>
+
+#include <openssl/crypto.h>
 
 ISC_LANG_BEGINDECLS
 
-isc_boolean_t
-isc_safe_memequal(const void *s1, const void *s2, size_t n);
+#define isc_safe_memequal(s1, s2, n) ISC_TF(!CRYPTO_memcmp(s1, s2, n))
 /*%<
  * Returns ISC_TRUE iff. two blocks of memory are equal, otherwise
  * ISC_FALSE.
  *
  */
 
-int
-isc_safe_memcompare(const void *b1, const void *b2, size_t len);
+#define isc_safe_memcompare(b1, b2, n) CRYPTO_memcmp(b1, b2, n)
 /*%<
  * Clone of libc memcmp() which is safe to differential timing attacks.
  */
 
-void
-isc_safe_memwipe(void *ptr, size_t len);
+#define isc_safe_memwipe(ptr, len) OPENSSL_cleanse(ptr, len)
 /*%<
  * Clear the memory of length `len` pointed to by `ptr`.
  *
diff --git a/lib/isc/safe.c b/lib/isc/safe.c
deleted file mode 100644 (file)
index 5c9e1e2..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * See the COPYRIGHT file distributed with this work for additional
- * information regarding copyright ownership.
- */
-
-/*! \file */
-
-#include <config.h>
-
-#include <isc/safe.h>
-#include <isc/string.h>
-#include <isc/util.h>
-
-#ifdef WIN32
-#include <windows.h>
-#endif
-
-#ifdef _MSC_VER
-#pragma optimize("", off)
-#endif
-
-isc_boolean_t
-isc_safe_memequal(const void *s1, const void *s2, size_t n) {
-       isc_uint8_t acc = 0;
-
-       if (n != 0U) {
-               const isc_uint8_t *p1 = s1, *p2 = s2;
-
-               do {
-                       acc |= *p1++ ^ *p2++;
-               } while (--n != 0U);
-       }
-       return (ISC_TF(acc == 0));
-}
-
-
-int
-isc_safe_memcompare(const void *b1, const void *b2, size_t len) {
-       const unsigned char *p1 = b1, *p2 = b2;
-       size_t i;
-       int res = 0, done = 0;
-
-       for (i = 0; i < len; i++) {
-               /* lt is -1 if p1[i] < p2[i]; else 0. */
-               int lt = (p1[i] - p2[i]) >> CHAR_BIT;
-
-               /* gt is -1 if p1[i] > p2[i]; else 0. */
-               int gt = (p2[i] - p1[i]) >> CHAR_BIT;
-
-               /* cmp is 1 if p1[i] > p2[i]; -1 if p1[i] < p2[i]; else 0. */
-               int cmp = lt - gt;
-
-               /* set res = cmp if !done. */
-               res |= cmp & ~done;
-
-               /* set done if p1[i] != p2[i]. */
-               done |= lt | gt;
-       }
-
-       return (res);
-}
-
-void
-isc_safe_memwipe(void *ptr, size_t len) {
-       if (ISC_UNLIKELY(ptr == NULL || len == 0))
-               return;
-
-#ifdef WIN32
-       SecureZeroMemory(ptr, len);
-#elif HAVE_EXPLICIT_BZERO
-       explicit_bzero(ptr, len);
-#else
-       memset(ptr, 0, len);
-#endif
-}
index 6f61d6b13e0d9f06a96dfd3c8749b25400a8b984..1e112fa93d7a312d9bd37281edf02f7b52ed1732 100644 (file)
@@ -538,9 +538,6 @@ isc_rwlock_lock
 isc_rwlock_trylock
 isc_rwlock_tryupgrade
 isc_rwlock_unlock
-isc_safe_memcompare
-isc_safe_memequal
-isc_safe_memwipe
 isc_serial_eq
 isc_serial_ge
 isc_serial_gt
index f27963d40e1e4aa37034bb364f60282e1d10df9b..75c578da12ad188025bfbba36d87c5c95762875c 100644 (file)
     <ClCompile Include="..\rwlock.c">
       <Filter>Library Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="..\safe.c">
-      <Filter>Library Source Files</Filter>
-    </ClCompile>
     <ClCompile Include="..\serial.c">
       <Filter>Library Source Files</Filter>
     </ClCompile>
index e824ccd76890dfa553fce9e92ded5c9ac29530d7..c0a8fd1c64f4e7c1992e1b27dcf2429251fb570b 100644 (file)
@@ -468,7 +468,6 @@ copy InstallFiles ..\Build\Release\
     <ClCompile Include="..\region.c" />
     <ClCompile Include="..\result.c" />
     <ClCompile Include="..\rwlock.c" />
-    <ClCompile Include="..\safe.c" />
     <ClCompile Include="..\serial.c" />
     <ClCompile Include="..\sha1.c" />
     <ClCompile Include="..\sha2.c" />