Skip to content

Commit

Permalink
cleanup: Merge crypto_core and crypto_core_mem.
Browse files Browse the repository at this point in the history
The remaining memory functions are small and don't need their own file.
  • Loading branch information
iphydf committed Jan 14, 2022
1 parent dfa7a01 commit d984042
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 63 deletions.
6 changes: 1 addition & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
9 changes: 2 additions & 7 deletions toxcore/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion toxcore/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
37 changes: 37 additions & 0 deletions toxcore/crypto_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,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
Expand Down
50 changes: 0 additions & 50 deletions toxcore/crypto_core_mem.c

This file was deleted.

0 comments on commit d984042

Please sign in to comment.