diff --git a/CMakeLists.txt b/CMakeLists.txt index edfd3b2a..17ccfd54 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -163,11 +163,7 @@ set(toxcore_PKGCONFIG_REQUIRES) set(toxcore_SOURCES ${toxcore_SOURCES} toxcore/ccompat.h toxcore/crypto_core.c - toxcore/crypto_core.h - toxcore/crypto_core_mem.c) -include(CheckFunctionExists) -check_function_exists(explicit_bzero HAVE_EXPLICIT_BZERO) -check_function_exists(memset_s HAVE_MEMSET_S) + toxcore/crypto_core.h) set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} ${LIBSODIUM_LIBRARIES}) set(toxcore_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} libsodium) diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 index 7b4b6e78..534a8cef 100644 --- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 +++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 @@ -1 +1 @@ -fc6b060abddd1898d97b0cf067d19c7a9d68999469690d91e7cf59327e700dbf /usr/local/bin/tox-bootstrapd +243145e05d7d20b7703a339ae0898d0445400ef2ecc852096f13e32b1609912c /usr/local/bin/tox-bootstrapd diff --git a/toxcore/BUILD.bazel b/toxcore/BUILD.bazel index 2169cf63..d7b3f7ba 100644 --- a/toxcore/BUILD.bazel +++ b/toxcore/BUILD.bazel @@ -16,13 +16,8 @@ cc_library( cc_library( name = "crypto_core", - srcs = [ - "crypto_core.c", - "crypto_core_mem.c", - ], - hdrs = [ - "crypto_core.h", - ], + srcs = ["crypto_core.c"], + hdrs = ["crypto_core.h"], visibility = ["//c-toxcore:__subpackages__"], deps = [ ":ccompat", diff --git a/toxcore/Makefile.inc b/toxcore/Makefile.inc index bcf6781a..30aa177f 100644 --- a/toxcore/Makefile.inc +++ b/toxcore/Makefile.inc @@ -14,7 +14,6 @@ libtoxcore_la_SOURCES = ../toxcore/ccompat.h \ ../toxcore/network.c \ ../toxcore/crypto_core.h \ ../toxcore/crypto_core.c \ - ../toxcore/crypto_core_mem.c \ ../toxcore/ping_array.h \ ../toxcore/ping_array.c \ ../toxcore/net_crypto.h \ diff --git a/toxcore/crypto_core.c b/toxcore/crypto_core.c index 3f029ef7..23fdc50f 100644 --- a/toxcore/crypto_core.c +++ b/toxcore/crypto_core.c @@ -80,6 +80,43 @@ static void crypto_free(uint8_t *ptr, size_t bytes) } #endif // !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION) +void crypto_memzero(void *data, size_t length) +{ +#ifndef VANILLA_NACL + sodium_memzero(data, length); +#else + memset(data, 0, length); +#endif +} + +bool crypto_memlock(void *data, size_t length) +{ +#ifndef VANILLA_NACL + + if (sodium_mlock(data, length) != 0) { + return false; + } + + return true; +#else + return false; +#endif +} + +bool crypto_memunlock(void *data, size_t length) +{ +#ifndef VANILLA_NACL + + if (sodium_munlock(data, length) != 0) { + return false; + } + + return true; +#else + return false; +#endif +} + int32_t public_key_cmp(const uint8_t *pk1, const uint8_t *pk2) { #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION diff --git a/toxcore/crypto_core_mem.c b/toxcore/crypto_core_mem.c deleted file mode 100644 index 7b002b72..00000000 --- a/toxcore/crypto_core_mem.c +++ /dev/null @@ -1,50 +0,0 @@ -/* SPDX-License-Identifier: ISC - * Copyright © 2016-2021 The TokTok team. - */ - -#include "crypto_core.h" - -#ifndef VANILLA_NACL -// We use libsodium by default. -#include -#else -#include -#endif - - -void crypto_memzero(void *data, size_t length) -{ -#ifndef VANILLA_NACL - sodium_memzero(data, length); -#else - memset(data, 0, length); -#endif -} - -bool crypto_memlock(void *data, size_t length) -{ -#ifndef VANILLA_NACL - - if (sodium_mlock(data, length) != 0) { - return false; - } - - return true; -#else - return false; -#endif -} - -bool crypto_memunlock(void *data, size_t length) -{ -#ifndef VANILLA_NACL - - if (sodium_munlock(data, length) != 0) { - return false; - } - - return true; -#else - return false; -#endif -}