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 15, 2022
1 parent 6823fcb commit 2671095
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 64 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
2 changes: 1 addition & 1 deletion other/bootstrap_daemon/docker/tox-bootstrapd.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fc6b060abddd1898d97b0cf067d19c7a9d68999469690d91e7cf59327e700dbf /usr/local/bin/tox-bootstrapd
243145e05d7d20b7703a339ae0898d0445400ef2ecc852096f13e32b1609912c /usr/local/bin/tox-bootstrapd
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 @@ -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
Expand Down
50 changes: 0 additions & 50 deletions toxcore/crypto_core_mem.c

This file was deleted.

0 comments on commit 2671095

Please sign in to comment.