mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Remove tokstyle exemptions from build files.
We put some tokstyle exemptions into the source files themselves, instead. This way we can check some of the code in those files, and more in the future when tokstyle supports more constructs (like apidsl). Also: hacked ping_array.api.h to not emit `_array` as parameter names. We'll need to fix apidsl to do this better. This works for now.
This commit is contained in:
parent
7f9f8045cd
commit
c08b2fb3e2
|
@ -45,8 +45,8 @@ cc_library(
|
|||
hdrs = ["bwcontroller.h"],
|
||||
deps = [
|
||||
":ring_buffer",
|
||||
"//c-toxcore/toxcore",
|
||||
"//c-toxcore/toxcore:Messenger",
|
||||
"//c-toxcore/toxcore:toxcore",
|
||||
],
|
||||
)
|
||||
|
||||
|
@ -130,10 +130,7 @@ CIMPLE_SRCS = glob(
|
|||
"*.c",
|
||||
"*.h",
|
||||
],
|
||||
exclude = [
|
||||
"*.api.h",
|
||||
"toxav.h",
|
||||
],
|
||||
exclude = ["*.api.h"],
|
||||
)
|
||||
|
||||
sh_test(
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
//!TOKSTYLE-
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -686,5 +688,7 @@ typedef TOXAV_ERR_BIT_RATE_SET Toxav_Err_Bit_Rate_Set;
|
|||
typedef TOXAV_ERR_SEND_FRAME Toxav_Err_Send_Frame;
|
||||
typedef TOXAV_CALL_CONTROL Toxav_Call_Control;
|
||||
|
||||
//!TOKSTYLE+
|
||||
|
||||
#endif // C_TOXCORE_TOXAV_TOXAV_H
|
||||
%}
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
//!TOKSTYLE-
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -815,4 +817,6 @@ typedef TOXAV_ERR_BIT_RATE_SET Toxav_Err_Bit_Rate_Set;
|
|||
typedef TOXAV_ERR_SEND_FRAME Toxav_Err_Send_Frame;
|
||||
typedef TOXAV_CALL_CONTROL Toxav_Call_Control;
|
||||
|
||||
//!TOKSTYLE+
|
||||
|
||||
#endif // C_TOXCORE_TOXAV_TOXAV_H
|
||||
|
|
|
@ -286,14 +286,7 @@ CIMPLE_SRCS = glob(
|
|||
"*.c",
|
||||
"*.h",
|
||||
],
|
||||
exclude = [
|
||||
"*.api.h",
|
||||
"ccompat.h",
|
||||
"crypto_core_mem.c",
|
||||
"ping_array.h",
|
||||
"tox.h",
|
||||
"tox_api.c",
|
||||
],
|
||||
exclude = ["*.api.h"],
|
||||
)
|
||||
|
||||
sh_test(
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#ifndef C_TOXCORE_TOXCORE_CCOMPAT_H
|
||||
#define C_TOXCORE_TOXCORE_CCOMPAT_H
|
||||
|
||||
//!TOKSTYLE-
|
||||
|
||||
// Variable length arrays.
|
||||
// VLA(type, name, size) allocates a variable length array with automatic
|
||||
// storage duration. VLA_SIZE(name) evaluates to the runtime size of that array
|
||||
|
@ -48,4 +50,6 @@
|
|||
#define GNU_PRINTF(f, a)
|
||||
#endif
|
||||
|
||||
//!TOKSTYLE+
|
||||
|
||||
#endif // C_TOXCORE_TOXCORE_CCOMPAT_H
|
||||
|
|
|
@ -69,7 +69,7 @@ const CRYPTO_SHA512_SIZE = 64;
|
|||
* "aaaa" and "baaa" also takes 4 time. With a regular `memcmp`, the latter may
|
||||
* take 1 time, because it immediately knows that the two strings are not equal.
|
||||
*/
|
||||
static int32_t crypto_memcmp(const void *p1, const void *p2, size_t length);
|
||||
static int32_t crypto_memcmp(const uint8_t *p1, const uint8_t *p2, size_t length);
|
||||
|
||||
/**
|
||||
* A `bzero`-like function which won't be optimised away by the compiler. Some
|
||||
|
|
|
@ -83,7 +83,7 @@ uint32_t crypto_sha512_size(void);
|
|||
* "aaaa" and "baaa" also takes 4 time. With a regular `memcmp`, the latter may
|
||||
* take 1 time, because it immediately knows that the two strings are not equal.
|
||||
*/
|
||||
int32_t crypto_memcmp(const void *p1, const void *p2, size_t length);
|
||||
int32_t crypto_memcmp(const uint8_t *p1, const uint8_t *p2, size_t length);
|
||||
|
||||
/**
|
||||
* A `bzero`-like function which won't be optimised away by the compiler. Some
|
||||
|
|
|
@ -37,8 +37,7 @@ void crypto_memzero(void *data, size_t length)
|
|||
{
|
||||
#ifndef VANILLA_NACL
|
||||
sodium_memzero(data, length);
|
||||
#else
|
||||
#ifdef _WIN32
|
||||
#elif defined(_WIN32)
|
||||
SecureZeroMemory(data, length);
|
||||
#elif defined(HAVE_MEMSET_S)
|
||||
|
||||
|
@ -53,32 +52,33 @@ void crypto_memzero(void *data, size_t length)
|
|||
#elif defined(HAVE_EXPLICIT_BZERO)
|
||||
explicit_bzero(data, length);
|
||||
#else
|
||||
volatile unsigned char *volatile pnt =
|
||||
(volatile unsigned char *volatile) data;
|
||||
//!TOKSTYLE-
|
||||
volatile uint8_t *volatile pnt = data;
|
||||
//!TOKSTYLE+
|
||||
size_t i = (size_t) 0U;
|
||||
|
||||
while (i < length) {
|
||||
pnt[i++] = 0U;
|
||||
pnt[i] = 0U;
|
||||
++i;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t crypto_memcmp(const void *p1, const void *p2, size_t length)
|
||||
int32_t crypto_memcmp(const uint8_t *p1, const uint8_t *p2, size_t length)
|
||||
{
|
||||
#ifndef VANILLA_NACL
|
||||
return sodium_memcmp(p1, p2, length);
|
||||
#else
|
||||
const volatile unsigned char *volatile b1 =
|
||||
(const volatile unsigned char *volatile) p1;
|
||||
const volatile unsigned char *volatile b2 =
|
||||
(const volatile unsigned char *volatile) p2;
|
||||
//!TOKSTYLE-
|
||||
const volatile uint8_t *volatile b1 = p1;
|
||||
const volatile uint8_t *volatile b2 = p2;
|
||||
//!TOKSTYLE+
|
||||
|
||||
size_t i;
|
||||
unsigned char d = (unsigned char) 0U;
|
||||
uint8_t d = (uint8_t) 0U;
|
||||
|
||||
for (i = 0U; i < length; i++) {
|
||||
for (i = 0U; i < length; ++i) {
|
||||
d |= b1[i] ^ b2[i];
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "crypto_core.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
|
@ -29,7 +30,7 @@ enum {
|
|||
CRYPTO_TEST_MEMCMP_EPS = 10,
|
||||
};
|
||||
|
||||
clock_t memcmp_time(void *a, void *b, size_t len) {
|
||||
clock_t memcmp_time(uint8_t const *a, uint8_t const *b, size_t len) {
|
||||
clock_t start = clock();
|
||||
volatile int result = crypto_memcmp(a, b, len);
|
||||
(void)result;
|
||||
|
@ -41,8 +42,8 @@ clock_t memcmp_time(void *a, void *b, size_t len) {
|
|||
* equal and non-equal arrays to reduce the influence of external effects
|
||||
* such as the machine being a little more busy 1 second later.
|
||||
*/
|
||||
void memcmp_median(void *src, void *same, void *not_same, size_t len, clock_t *same_median,
|
||||
clock_t *not_same_median) {
|
||||
std::pair<clock_t, clock_t> memcmp_median(uint8_t const *src, uint8_t const *same,
|
||||
uint8_t const *not_same, size_t len) {
|
||||
clock_t same_results[CRYPTO_TEST_MEMCMP_ITERATIONS];
|
||||
clock_t not_same_results[CRYPTO_TEST_MEMCMP_ITERATIONS];
|
||||
|
||||
|
@ -52,9 +53,10 @@ void memcmp_median(void *src, void *same, void *not_same, size_t len, clock_t *s
|
|||
}
|
||||
|
||||
std::sort(same_results, same_results + CRYPTO_TEST_MEMCMP_ITERATIONS);
|
||||
*same_median = same_results[CRYPTO_TEST_MEMCMP_ITERATIONS / 2];
|
||||
clock_t const same_median = same_results[CRYPTO_TEST_MEMCMP_ITERATIONS / 2];
|
||||
std::sort(not_same_results, not_same_results + CRYPTO_TEST_MEMCMP_ITERATIONS);
|
||||
*not_same_median = not_same_results[CRYPTO_TEST_MEMCMP_ITERATIONS / 2];
|
||||
clock_t const not_same_median = not_same_results[CRYPTO_TEST_MEMCMP_ITERATIONS / 2];
|
||||
return {same_median, not_same_median};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,32 +65,28 @@ void memcmp_median(void *src, void *same, void *not_same, size_t len, clock_t *s
|
|||
*/
|
||||
TEST(CryptoCore, MemcmpTimingIsDataIndependent) {
|
||||
// A random piece of memory.
|
||||
auto *src = new uint8_t[CRYPTO_TEST_MEMCMP_SIZE];
|
||||
random_bytes(src, CRYPTO_TEST_MEMCMP_SIZE);
|
||||
std::vector<uint8_t> src(CRYPTO_TEST_MEMCMP_SIZE);
|
||||
random_bytes(src.data(), CRYPTO_TEST_MEMCMP_SIZE);
|
||||
|
||||
// A separate piece of memory containing the same data.
|
||||
auto *same = new uint8_t[CRYPTO_TEST_MEMCMP_SIZE];
|
||||
memcpy(same, src, CRYPTO_TEST_MEMCMP_SIZE);
|
||||
std::vector<uint8_t> same = src;
|
||||
|
||||
// Another piece of memory containing different data.
|
||||
auto *not_same = new uint8_t[CRYPTO_TEST_MEMCMP_SIZE];
|
||||
random_bytes(not_same, CRYPTO_TEST_MEMCMP_SIZE);
|
||||
std::vector<uint8_t> not_same(CRYPTO_TEST_MEMCMP_SIZE);
|
||||
random_bytes(not_same.data(), CRYPTO_TEST_MEMCMP_SIZE);
|
||||
|
||||
clock_t same_median;
|
||||
clock_t not_same_median;
|
||||
memcmp_median(src, same, not_same, CRYPTO_TEST_MEMCMP_SIZE, &same_median, ¬_same_median);
|
||||
|
||||
delete[] not_same;
|
||||
delete[] same;
|
||||
delete[] src;
|
||||
// Once we have C++17:
|
||||
// auto const [same_median, not_same_median] =
|
||||
auto const result =
|
||||
memcmp_median(src.data(), same.data(), not_same.data(), CRYPTO_TEST_MEMCMP_SIZE);
|
||||
|
||||
clock_t const delta =
|
||||
same_median > not_same_median ? same_median - not_same_median : not_same_median - same_median;
|
||||
std::max(result.first, result.second) - std::min(result.first, result.second);
|
||||
|
||||
EXPECT_LT(delta, CRYPTO_TEST_MEMCMP_EPS)
|
||||
<< "Delta time is too long (" << delta << " >= " << CRYPTO_TEST_MEMCMP_EPS << ")\n"
|
||||
<< "Time of the same data comparison: " << same_median << " clocks\n"
|
||||
<< "Time of the different data comparison: " << not_same_median << " clocks";
|
||||
<< "Time of the same data comparison: " << result.first << " clocks\n"
|
||||
<< "Time of the different data comparison: " << result.second << " clocks";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -20,7 +20,7 @@ extern "C" {
|
|||
|
||||
class mono_Time { struct this; }
|
||||
|
||||
class ping_Array {
|
||||
class ping { class array {
|
||||
|
||||
struct this;
|
||||
|
||||
|
@ -55,7 +55,7 @@ uint64_t add(const mono_Time::this *mono_time, const uint8_t *data, uint32_t len
|
|||
*/
|
||||
int32_t check(const mono_Time::this *mono_time, uint8_t[length] data, uint64_t ping_id);
|
||||
|
||||
}
|
||||
} }
|
||||
|
||||
%{
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -39,14 +39,14 @@ struct Ping_Array *ping_array_new(uint32_t size, uint32_t timeout);
|
|||
/**
|
||||
* Free all the allocated memory in a Ping_Array.
|
||||
*/
|
||||
void ping_array_kill(struct Ping_Array *_array);
|
||||
void ping_array_kill(struct Ping_Array *array);
|
||||
|
||||
/**
|
||||
* Add a data with length to the Ping_Array list and return a ping_id.
|
||||
*
|
||||
* @return ping_id on success, 0 on failure.
|
||||
*/
|
||||
uint64_t ping_array_add(struct Ping_Array *_array, const struct Mono_Time *mono_time, const uint8_t *data,
|
||||
uint64_t ping_array_add(struct Ping_Array *array, const struct Mono_Time *mono_time, const uint8_t *data,
|
||||
uint32_t length);
|
||||
|
||||
/**
|
||||
|
@ -56,7 +56,7 @@ uint64_t ping_array_add(struct Ping_Array *_array, const struct Mono_Time *mono_
|
|||
*
|
||||
* @return length of data copied on success, -1 on failure.
|
||||
*/
|
||||
int32_t ping_array_check(struct Ping_Array *_array, const struct Mono_Time *mono_time, uint8_t *data, size_t length,
|
||||
int32_t ping_array_check(struct Ping_Array *array, const struct Mono_Time *mono_time, uint8_t *data, size_t length,
|
||||
uint64_t ping_id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
//!TOKSTYLE-
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -2854,5 +2856,7 @@ typedef TOX_CONNECTION Tox_Connection;
|
|||
typedef TOX_FILE_CONTROL Tox_File_Control;
|
||||
typedef TOX_CONFERENCE_TYPE Tox_Conference_Type;
|
||||
|
||||
//!TOKSTYLE+
|
||||
|
||||
#endif // C_TOXCORE_TOXCORE_TOX_H
|
||||
%}
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
//!TOKSTYLE-
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -3251,4 +3253,6 @@ typedef TOX_CONNECTION Tox_Connection;
|
|||
typedef TOX_FILE_CONTROL Tox_File_Control;
|
||||
typedef TOX_CONFERENCE_TYPE Tox_Conference_Type;
|
||||
|
||||
//!TOKSTYLE+
|
||||
|
||||
#endif // C_TOXCORE_TOXCORE_TOX_H
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#define SET_ERROR_PARAMETER(param, x) do { if (param) { *param = x; } } while (0)
|
||||
|
||||
//!TOKSTYLE-
|
||||
|
||||
#define CONST_FUNCTION(lowercase, uppercase) \
|
||||
uint32_t tox_##lowercase(void) \
|
||||
|
@ -60,6 +61,8 @@ ACCESSORS(void *, log_, user_data)
|
|||
ACCESSORS(bool,, local_discovery_enabled)
|
||||
ACCESSORS(bool,, experimental_thread_safety)
|
||||
|
||||
//!TOKSTYLE+
|
||||
|
||||
const uint8_t *tox_options_get_savedata_data(const struct Tox_Options *options)
|
||||
{
|
||||
return options->savedata_data;
|
||||
|
|
|
@ -201,7 +201,7 @@ crypto_pwhash_scryptsalsa208sha256_str_verify(const char str[crypto_pwhash_scryp
|
|||
return -1;
|
||||
}
|
||||
escrypt_free_local(&escrypt_local);
|
||||
ret = crypto_memcmp(wanted, str, sizeof wanted);
|
||||
ret = crypto_memcmp((const uint8_t *) wanted, (const uint8_t *) str, sizeof wanted);
|
||||
crypto_memzero(wanted, sizeof wanted);
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef C_TOXCORE_TOXENCRYPTSAVE_DEFINES_H
|
||||
#define C_TOXCORE_TOXENCRYPTSAVE_DEFINES_H
|
||||
|
||||
#define TOX_ENC_SAVE_MAGIC_NUMBER "toxEsave"
|
||||
#define TOX_ENC_SAVE_MAGIC_NUMBER ((const uint8_t *)"toxEsave")
|
||||
#define TOX_ENC_SAVE_MAGIC_LENGTH 8
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue
Block a user