cleanup: Merge crypto_core and crypto_core_mem.

The remaining memory functions are small and don't need their own file.
This commit is contained in:
iphydf 2022-01-14 01:19:02 +00:00
parent 6823fcbae1
commit 2671095f4a
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
6 changed files with 41 additions and 64 deletions

View File

@ -163,11 +163,7 @@ set(toxcore_PKGCONFIG_REQUIRES)
set(toxcore_SOURCES ${toxcore_SOURCES} set(toxcore_SOURCES ${toxcore_SOURCES}
toxcore/ccompat.h toxcore/ccompat.h
toxcore/crypto_core.c toxcore/crypto_core.c
toxcore/crypto_core.h 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)
set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} ${LIBSODIUM_LIBRARIES}) set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} ${LIBSODIUM_LIBRARIES})
set(toxcore_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} libsodium) set(toxcore_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} libsodium)

View File

@ -1 +1 @@
fc6b060abddd1898d97b0cf067d19c7a9d68999469690d91e7cf59327e700dbf /usr/local/bin/tox-bootstrapd 243145e05d7d20b7703a339ae0898d0445400ef2ecc852096f13e32b1609912c /usr/local/bin/tox-bootstrapd

View File

@ -16,13 +16,8 @@ cc_library(
cc_library( cc_library(
name = "crypto_core", name = "crypto_core",
srcs = [ srcs = ["crypto_core.c"],
"crypto_core.c", hdrs = ["crypto_core.h"],
"crypto_core_mem.c",
],
hdrs = [
"crypto_core.h",
],
visibility = ["//c-toxcore:__subpackages__"], visibility = ["//c-toxcore:__subpackages__"],
deps = [ deps = [
":ccompat", ":ccompat",

View File

@ -14,7 +14,6 @@ libtoxcore_la_SOURCES = ../toxcore/ccompat.h \
../toxcore/network.c \ ../toxcore/network.c \
../toxcore/crypto_core.h \ ../toxcore/crypto_core.h \
../toxcore/crypto_core.c \ ../toxcore/crypto_core.c \
../toxcore/crypto_core_mem.c \
../toxcore/ping_array.h \ ../toxcore/ping_array.h \
../toxcore/ping_array.c \ ../toxcore/ping_array.c \
../toxcore/net_crypto.h \ ../toxcore/net_crypto.h \

View File

@ -80,6 +80,43 @@ static void crypto_free(uint8_t *ptr, size_t bytes)
} }
#endif // !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION) #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) int32_t public_key_cmp(const uint8_t *pk1, const uint8_t *pk2)
{ {
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION

View File

@ -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 <sodium.h>
#else
#include <string.h>
#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
}