diff --git a/auto_tests/auto_test_support.c b/auto_tests/auto_test_support.c index b9a1fb9eae..2a45d0ca08 100644 --- a/auto_tests/auto_test_support.c +++ b/auto_tests/auto_test_support.c @@ -235,7 +235,7 @@ static void autotox_add_friend(AutoTox *autotoxes, uint32_t adding, uint32_t add static void initialise_friend_graph(Graph_Type graph, uint32_t num_toxes, AutoTox *autotoxes) { if (graph == GRAPH_LINEAR) { - printf("toxes #%u-#%u each add adjacent toxes as friends\n", 0, num_toxes - 1); + printf("toxes #%d-#%u each add adjacent toxes as friends\n", 0, num_toxes - 1); for (uint32_t i = 0; i < num_toxes; ++i) { for (uint32_t j = i - 1; j != i + 3; j += 2) { @@ -245,7 +245,7 @@ static void initialise_friend_graph(Graph_Type graph, uint32_t num_toxes, AutoTo } } } else if (graph == GRAPH_COMPLETE) { - printf("toxes #%u-#%u add each other as friends\n", 0, num_toxes - 1); + printf("toxes #%d-#%u add each other as friends\n", 0, num_toxes - 1); for (uint32_t i = 0; i < num_toxes; ++i) { for (uint32_t j = 0; j < num_toxes; ++j) { diff --git a/auto_tests/auto_test_support.h b/auto_tests/auto_test_support.h index 16faa40f63..f0296c1fc8 100644 --- a/auto_tests/auto_test_support.h +++ b/auto_tests/auto_test_support.h @@ -21,17 +21,17 @@ typedef struct AutoTox { void *state; } AutoTox; -bool all_connected(AutoTox *toxes, uint32_t tox_count); +bool all_connected(AutoTox *autotoxes, uint32_t tox_count); -bool all_friends_connected(AutoTox *toxes, uint32_t tox_count); +bool all_friends_connected(AutoTox *autotoxes, uint32_t tox_count); -void iterate_all_wait(AutoTox *toxes, uint32_t tox_count, uint32_t wait); +void iterate_all_wait(AutoTox *autotoxes, uint32_t tox_count, uint32_t wait); void save_autotox(AutoTox *autotox); void kill_autotox(AutoTox *autotox); void reload(AutoTox *autotox); -void set_mono_time_callback(AutoTox *tox); +void set_mono_time_callback(AutoTox *autotox); typedef enum Graph_Type { GRAPH_COMPLETE = 0, diff --git a/other/analysis/gen-file.sh b/other/analysis/gen-file.sh index 55a1a9dd48..bf74112d65 100644 --- a/other/analysis/gen-file.sh +++ b/other/analysis/gen-file.sh @@ -8,7 +8,6 @@ CPPFLAGS+=("-Iother/bootstrap_daemon/src") CPPFLAGS+=("-Iother/fun") CPPFLAGS+=("-Itesting") CPPFLAGS+=("-Itesting/fuzzing") -CPPFLAGS+=("-Itesting/groupchats") CPPFLAGS+=("-Itoxcore") CPPFLAGS+=("-Itoxcore/events") CPPFLAGS+=("-Itoxav") diff --git a/other/analysis/run-cppcheck b/other/analysis/run-cppcheck index 871f08eb2e..c71d6e355c 100755 --- a/other/analysis/run-cppcheck +++ b/other/analysis/run-cppcheck @@ -6,9 +6,29 @@ SKIP_GTEST=1 set -e +CPPCHECK="--enable=all" +CPPCHECK+=("--inconclusive") +CPPCHECK+=("--error-exitcode=1") +# Used for VLA. +CPPCHECK+=("--suppress=allocaCalled") +# We actually write C code. +CPPCHECK+=("--suppress=cstyleCast") +# Used to enable/disable parts using if with constant condition. +CPPCHECK+=("--suppress=knownConditionTrueFalse") +# Cppcheck does not need standard library headers to get proper results. +CPPCHECK+=("--suppress=missingIncludeSystem") +# Range-for is fine. +CPPCHECK+=("--suppress=useStlAlgorithm") +# TODO(iphydf): Maybe fix? +CPPCHECK+=("--suppress=shadowArgument") +CPPCHECK+=("--suppress=shadowFunction") +CPPCHECK+=("--suppress=signConversion") +# TODO(iphydf): Fixed in the toxav refactor PR. +CPPCHECK+=("--suppress=redundantAssignment") + run() { echo "Running cppcheck in variant '$*'" - cppcheck amalgamation.cc "${CPPFLAGS[@]}" "$@" + cppcheck "${CPPCHECK[@]}" amalgamation.cc "${CPPFLAGS[@]}" "$@" } . other/analysis/variants.sh diff --git a/other/fun/create_common.h b/other/fun/create_common.h index 89ddaac981..c17c922205 100644 --- a/other/fun/create_common.h +++ b/other/fun/create_common.h @@ -60,7 +60,7 @@ static void handle_args(const int argc, const char *const argv[], const char *co crypto_scalarmult_base(public_key, secret_key); } else if (argc == 2) { - printf("Error: Secret key must be a %d character hex string.\n", crypto_box_SECRETKEYBYTES * 2); + printf("Error: Secret key must be a %u character hex string.\n", crypto_box_SECRETKEYBYTES * 2); exit(1); } else { print_usage(argv[0], does_what); diff --git a/toxav/toxav.c b/toxav/toxav.c index 19c7de4054..f0dfa6edc0 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c @@ -638,7 +638,7 @@ bool toxav_call_control(ToxAV *av, uint32_t friend_number, Toxav_Call_Control co return rc == TOXAV_ERR_CALL_CONTROL_OK; } -bool toxav_audio_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, +bool toxav_audio_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t bit_rate, Toxav_Err_Bit_Rate_Set *error) { Toxav_Err_Bit_Rate_Set rc = TOXAV_ERR_BIT_RATE_SET_OK; @@ -649,7 +649,7 @@ bool toxav_audio_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t audio_ goto RETURN; } - if (audio_bit_rate > 0 && audio_bit_rate_invalid(audio_bit_rate)) { + if (bit_rate > 0 && audio_bit_rate_invalid(bit_rate)) { rc = TOXAV_ERR_BIT_RATE_SET_INVALID_BIT_RATE; goto RETURN; } @@ -663,10 +663,10 @@ bool toxav_audio_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t audio_ goto RETURN; } - LOGGER_DEBUG(av->m->log, "Setting new audio bitrate to: %d", audio_bit_rate); + LOGGER_DEBUG(av->m->log, "Setting new audio bitrate to: %d", bit_rate); - if (call->audio_bit_rate == audio_bit_rate) { - LOGGER_DEBUG(av->m->log, "Audio bitrate already set to: %d", audio_bit_rate); + if (call->audio_bit_rate == bit_rate) { + LOGGER_DEBUG(av->m->log, "Audio bitrate already set to: %d", bit_rate); } else if (audio_bit_rate == 0) { LOGGER_DEBUG(av->m->log, "Turned off audio sending"); @@ -694,10 +694,10 @@ bool toxav_audio_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t audio_ goto RETURN; } } else { - LOGGER_DEBUG(av->m->log, "Set new audio bit rate %d", audio_bit_rate); + LOGGER_DEBUG(av->m->log, "Set new audio bit rate %d", bit_rate); } - call->audio_bit_rate = audio_bit_rate; + call->audio_bit_rate = bit_rate; pthread_mutex_unlock(call->toxav_call_mutex); } @@ -710,7 +710,7 @@ bool toxav_audio_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t audio_ return rc == TOXAV_ERR_BIT_RATE_SET_OK; } -bool toxav_video_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t video_bit_rate, +bool toxav_video_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t bit_rate, Toxav_Err_Bit_Rate_Set *error) { Toxav_Err_Bit_Rate_Set rc = TOXAV_ERR_BIT_RATE_SET_OK; @@ -721,7 +721,7 @@ bool toxav_video_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t video_ goto RETURN; } - if (video_bit_rate > 0 && video_bit_rate_invalid(video_bit_rate)) { + if (bit_rate > 0 && video_bit_rate_invalid(bit_rate)) { rc = TOXAV_ERR_BIT_RATE_SET_INVALID_BIT_RATE; goto RETURN; } @@ -735,10 +735,10 @@ bool toxav_video_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t video_ goto RETURN; } - LOGGER_DEBUG(av->m->log, "Setting new video bitrate to: %d", video_bit_rate); + LOGGER_DEBUG(av->m->log, "Setting new video bitrate to: %d", bit_rate); - if (call->video_bit_rate == video_bit_rate) { - LOGGER_DEBUG(av->m->log, "Video bitrate already set to: %d", video_bit_rate); + if (call->video_bit_rate == bit_rate) { + LOGGER_DEBUG(av->m->log, "Video bitrate already set to: %d", bit_rate); } else if (video_bit_rate == 0) { LOGGER_DEBUG(av->m->log, "Turned off video sending"); @@ -766,10 +766,10 @@ bool toxav_video_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t video_ goto RETURN; } } else { - LOGGER_DEBUG(av->m->log, "Set new video bit rate %d", video_bit_rate); + LOGGER_DEBUG(av->m->log, "Set new video bit rate %d", bit_rate); } - call->video_bit_rate = video_bit_rate; + call->video_bit_rate = bit_rate; pthread_mutex_unlock(call->toxav_call_mutex); } diff --git a/toxcore/LAN_discovery.h b/toxcore/LAN_discovery.h index 9d36a50855..faa6c339bd 100644 --- a/toxcore/LAN_discovery.h +++ b/toxcore/LAN_discovery.h @@ -36,7 +36,7 @@ Broadcast_Info *lan_discovery_init(DHT *dht); * Clear packet handlers. */ non_null() -void lan_discovery_kill(DHT *dht, Broadcast_Info *info); +void lan_discovery_kill(DHT *dht, Broadcast_Info *broadcast); /** * Is IP a local ip or not. diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 82bfec8ddf..f9836eddaa 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -1617,15 +1617,12 @@ static void do_reqchunk_filecb(Messenger *m, int32_t friendnumber, void *userdat */ static void break_files(const Messenger *m, int32_t friendnumber) { + Friend *const friend = &m->friendlist[friendnumber]; + // TODO(irungentoo): Inform the client which file transfers get killed with a callback? for (uint32_t i = 0; i < MAX_CONCURRENT_FILE_PIPES; ++i) { - if (m->friendlist[friendnumber].file_sending[i].status != FILESTATUS_NONE) { - m->friendlist[friendnumber].file_sending[i].status = FILESTATUS_NONE; - } - - if (m->friendlist[friendnumber].file_receiving[i].status != FILESTATUS_NONE) { - m->friendlist[friendnumber].file_receiving[i].status = FILESTATUS_NONE; - } + friend->file_sending[i].status = FILESTATUS_NONE; + friend->file_receiving[i].status = FILESTATUS_NONE; } } diff --git a/toxcore/bin_unpack.h b/toxcore/bin_unpack.h index b2d0dc4d7e..3751153f89 100644 --- a/toxcore/bin_unpack.h +++ b/toxcore/bin_unpack.h @@ -14,7 +14,7 @@ non_null() bool bin_unpack_bool(bool *val, const msgpack_object *obj); non_null() bool bin_unpack_u16(uint16_t *val, const msgpack_object *obj); non_null() bool bin_unpack_u32(uint32_t *val, const msgpack_object *obj); non_null() bool bin_unpack_u64(uint64_t *val, const msgpack_object *obj); -non_null() bool bin_unpack_bytes(uint8_t **data, size_t *data_length, const msgpack_object *obj); +non_null() bool bin_unpack_bytes(uint8_t **data_ptr, size_t *data_length_ptr, const msgpack_object *obj); non_null() bool bin_unpack_bytes_fixed(uint8_t *data, uint32_t data_length, const msgpack_object *obj); #endif // C_TOXCORE_TOXCORE_BIN_UNPACK_H diff --git a/toxcore/crypto_core.c b/toxcore/crypto_core.c index faf4e0368d..9f710dee33 100644 --- a/toxcore/crypto_core.c +++ b/toxcore/crypto_core.c @@ -190,10 +190,10 @@ int32_t encrypt_precompute(const uint8_t *public_key, const uint8_t *secret_key, return crypto_box_beforenm(shared_key, public_key, secret_key); } -int32_t encrypt_data_symmetric(const uint8_t *secret_key, const uint8_t *nonce, +int32_t encrypt_data_symmetric(const uint8_t *shared_key, const uint8_t *nonce, const uint8_t *plain, size_t length, uint8_t *encrypted) { - if (length == 0 || !secret_key || !nonce || !plain || !encrypted) { + if (length == 0 || !shared_key || !nonce || !plain || !encrypted) { return -1; } @@ -226,7 +226,7 @@ int32_t encrypt_data_symmetric(const uint8_t *secret_key, const uint8_t *nonce, memcpy(temp_plain + crypto_box_ZEROBYTES, plain, length); if (crypto_box_afternm(temp_encrypted, temp_plain, length + crypto_box_ZEROBYTES, nonce, - secret_key) != 0) { + shared_key) != 0) { crypto_free(temp_plain, size_temp_plain); crypto_free(temp_encrypted, size_temp_encrypted); return -1; @@ -241,10 +241,10 @@ int32_t encrypt_data_symmetric(const uint8_t *secret_key, const uint8_t *nonce, return length + crypto_box_MACBYTES; } -int32_t decrypt_data_symmetric(const uint8_t *secret_key, const uint8_t *nonce, +int32_t decrypt_data_symmetric(const uint8_t *shared_key, const uint8_t *nonce, const uint8_t *encrypted, size_t length, uint8_t *plain) { - if (length <= crypto_box_BOXZEROBYTES || !secret_key || !nonce || !encrypted || !plain) { + if (length <= crypto_box_BOXZEROBYTES || !shared_key || !nonce || !encrypted || !plain) { return -1; } @@ -275,7 +275,7 @@ int32_t decrypt_data_symmetric(const uint8_t *secret_key, const uint8_t *nonce, memcpy(temp_encrypted + crypto_box_BOXZEROBYTES, encrypted, length); if (crypto_box_open_afternm(temp_plain, temp_encrypted, length + crypto_box_BOXZEROBYTES, nonce, - secret_key) != 0) { + shared_key) != 0) { crypto_free(temp_plain, size_temp_plain); crypto_free(temp_encrypted, size_temp_encrypted); return -1; @@ -395,11 +395,11 @@ void crypto_sha512(uint8_t *hash, const uint8_t *data, size_t length) crypto_hash_sha512(hash, data, length); } -void random_bytes(uint8_t *data, size_t length) +void random_bytes(uint8_t *bytes, size_t length) { #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - fuzz_random_bytes(data, length); + fuzz_random_bytes(bytes, length); #else - randombytes(data, length); + randombytes(bytes, length); #endif } diff --git a/toxcore/events/conference_invite.c b/toxcore/events/conference_invite.c index 0c7939939c..84c3c688e2 100644 --- a/toxcore/events/conference_invite.c +++ b/toxcore/events/conference_invite.c @@ -147,14 +147,13 @@ static Tox_Event_Conference_Invite *tox_events_add_conference_invite(Tox_Events if (events->conference_invite_size == events->conference_invite_capacity) { const uint32_t new_conference_invite_capacity = events->conference_invite_capacity * 2 + 1; - Tox_Event_Conference_Invite *new_conference_invite = (Tox_Event_Conference_Invite *)realloc( + events->conference_invite = (Tox_Event_Conference_Invite *)realloc( events->conference_invite, new_conference_invite_capacity * sizeof(Tox_Event_Conference_Invite)); - if (new_conference_invite == nullptr) { + if (events->conference_invite == nullptr) { return nullptr; } - events->conference_invite = new_conference_invite; events->conference_invite_capacity = new_conference_invite_capacity; } diff --git a/toxcore/events/friend_status.c b/toxcore/events/friend_status.c index a39b403040..815d9840cc 100644 --- a/toxcore/events/friend_status.c +++ b/toxcore/events/friend_status.c @@ -25,7 +25,7 @@ struct Tox_Event_Friend_Status { uint32_t friend_number; - Tox_User_Status connection_status; + Tox_User_Status status; }; non_null() @@ -55,16 +55,16 @@ uint32_t tox_event_friend_status_get_friend_number(const Tox_Event_Friend_Status } non_null() -static void tox_event_friend_status_set_connection_status(Tox_Event_Friend_Status *friend_status, - Tox_User_Status connection_status) +static void tox_event_friend_status_set_status(Tox_Event_Friend_Status *friend_status, + Tox_User_Status status) { assert(friend_status != nullptr); - friend_status->connection_status = connection_status; + friend_status->status = status; } -Tox_User_Status tox_event_friend_status_get_connection_status(const Tox_Event_Friend_Status *friend_status) +Tox_User_Status tox_event_friend_status_get_status(const Tox_Event_Friend_Status *friend_status) { assert(friend_status != nullptr); - return friend_status->connection_status; + return friend_status->status; } non_null() @@ -76,7 +76,7 @@ static void tox_event_friend_status_pack( bin_pack_u32(mp, TOX_EVENT_FRIEND_STATUS); bin_pack_array(mp, 2); bin_pack_u32(mp, event->friend_number); - bin_pack_u32(mp, event->connection_status); + bin_pack_u32(mp, event->status); } non_null() @@ -90,7 +90,7 @@ static bool tox_event_friend_status_unpack( } return bin_unpack_u32(&event->friend_number, &obj->via.array.ptr[0]) - && tox_unpack_user_status(&event->connection_status, &obj->via.array.ptr[1]); + && tox_unpack_user_status(&event->status, &obj->via.array.ptr[1]); } @@ -187,7 +187,7 @@ bool tox_events_unpack_friend_status(Tox_Events *events, const msgpack_object *o *****************************************************/ -void tox_events_handle_friend_status(Tox *tox, uint32_t friend_number, Tox_User_Status connection_status, +void tox_events_handle_friend_status(Tox *tox, uint32_t friend_number, Tox_User_Status status, void *user_data) { Tox_Events_State *state = tox_events_alloc(user_data); @@ -201,5 +201,5 @@ void tox_events_handle_friend_status(Tox *tox, uint32_t friend_number, Tox_User_ } tox_event_friend_status_set_friend_number(friend_status, friend_number); - tox_event_friend_status_set_connection_status(friend_status, connection_status); + tox_event_friend_status_set_status(friend_status, status); } diff --git a/toxcore/events/friend_status_message.c b/toxcore/events/friend_status_message.c index c6a5a2b191..e735dec4c9 100644 --- a/toxcore/events/friend_status_message.c +++ b/toxcore/events/friend_status_message.c @@ -24,8 +24,8 @@ struct Tox_Event_Friend_Status_Message { uint32_t friend_number; - uint8_t *status_message; - size_t status_message_length; + uint8_t *message; + size_t message_length; }; non_null() @@ -38,7 +38,7 @@ static void tox_event_friend_status_message_construct(Tox_Event_Friend_Status_Me non_null() static void tox_event_friend_status_message_destruct(Tox_Event_Friend_Status_Message *friend_status_message) { - free(friend_status_message->status_message); + free(friend_status_message->message); } non_null() @@ -55,38 +55,38 @@ uint32_t tox_event_friend_status_message_get_friend_number(const Tox_Event_Frien } non_null() -static bool tox_event_friend_status_message_set_status_message(Tox_Event_Friend_Status_Message *friend_status_message, - const uint8_t *status_message, size_t status_message_length) +static bool tox_event_friend_status_message_set_message(Tox_Event_Friend_Status_Message *friend_status_message, + const uint8_t *message, size_t message_length) { assert(friend_status_message != nullptr); - if (friend_status_message->status_message != nullptr) { - free(friend_status_message->status_message); - friend_status_message->status_message = nullptr; - friend_status_message->status_message_length = 0; + if (friend_status_message->message != nullptr) { + free(friend_status_message->message); + friend_status_message->message = nullptr; + friend_status_message->message_length = 0; } - friend_status_message->status_message = (uint8_t *)malloc(status_message_length); + friend_status_message->message = (uint8_t *)malloc(message_length); - if (friend_status_message->status_message == nullptr) { + if (friend_status_message->message == nullptr) { return false; } - memcpy(friend_status_message->status_message, status_message, status_message_length); - friend_status_message->status_message_length = status_message_length; + memcpy(friend_status_message->message, message, message_length); + friend_status_message->message_length = message_length; return true; } -size_t tox_event_friend_status_message_get_status_message_length(const Tox_Event_Friend_Status_Message +size_t tox_event_friend_status_message_get_message_length(const Tox_Event_Friend_Status_Message *friend_status_message) { assert(friend_status_message != nullptr); - return friend_status_message->status_message_length; + return friend_status_message->message_length; } -const uint8_t *tox_event_friend_status_message_get_status_message(const Tox_Event_Friend_Status_Message +const uint8_t *tox_event_friend_status_message_get_message(const Tox_Event_Friend_Status_Message *friend_status_message) { assert(friend_status_message != nullptr); - return friend_status_message->status_message; + return friend_status_message->message; } non_null() @@ -98,7 +98,7 @@ static void tox_event_friend_status_message_pack( bin_pack_u32(mp, TOX_EVENT_FRIEND_STATUS_MESSAGE); bin_pack_array(mp, 2); bin_pack_u32(mp, event->friend_number); - bin_pack_bytes(mp, event->status_message, event->status_message_length); + bin_pack_bytes(mp, event->message, event->message_length); } non_null() @@ -112,7 +112,7 @@ static bool tox_event_friend_status_message_unpack( } return bin_unpack_u32(&event->friend_number, &obj->via.array.ptr[0]) - && bin_unpack_bytes(&event->status_message, &event->status_message_length, &obj->via.array.ptr[1]); + && bin_unpack_bytes(&event->message, &event->message_length, &obj->via.array.ptr[1]); } @@ -210,7 +210,7 @@ bool tox_events_unpack_friend_status_message(Tox_Events *events, const msgpack_o *****************************************************/ -void tox_events_handle_friend_status_message(Tox *tox, uint32_t friend_number, const uint8_t *status_message, +void tox_events_handle_friend_status_message(Tox *tox, uint32_t friend_number, const uint8_t *message, size_t length, void *user_data) { Tox_Events_State *state = tox_events_alloc(user_data); @@ -224,5 +224,5 @@ void tox_events_handle_friend_status_message(Tox *tox, uint32_t friend_number, c } tox_event_friend_status_message_set_friend_number(friend_status_message, friend_number); - tox_event_friend_status_message_set_status_message(friend_status_message, status_message, length); + tox_event_friend_status_message_set_message(friend_status_message, message, length); } diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index af5cfae0cf..090d20ffc7 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -1856,7 +1856,8 @@ static int create_crypto_connection(Net_Crypto *c) if (realloc_cryptoconnection(c, c->crypto_connections_length + 1) == 0) { id = c->crypto_connections_length; ++c->crypto_connections_length; - memset(&c->crypto_connections[id], 0, sizeof(Crypto_Connection)); + const Crypto_Connection empty_crypto_connection = {{0}}; + c->crypto_connections[id] = empty_crypto_connection; } } diff --git a/toxcore/tox.h b/toxcore/tox.h index aa3c71489e..b1c0d6a561 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -728,7 +728,7 @@ void tox_options_set_log_user_data(struct Tox_Options *options, void *user_data) bool tox_options_get_experimental_thread_safety(const struct Tox_Options *options); -void tox_options_set_experimental_thread_safety(struct Tox_Options *options, bool thread_safety); +void tox_options_set_experimental_thread_safety(struct Tox_Options *options, bool experimental_thread_safety); /** * @brief Initialises a Tox_Options object with the default options. @@ -1652,10 +1652,10 @@ bool tox_friend_get_typing(const Tox *tox, uint32_t friend_number, Tox_Err_Frien /** * @param friend_number The friend number of the friend who started or stopped * typing. - * @param is_typing The result of calling tox_friend_get_typing on the passed + * @param typing The result of calling tox_friend_get_typing on the passed * friend_number. */ -typedef void tox_friend_typing_cb(Tox *tox, uint32_t friend_number, bool is_typing, void *user_data); +typedef void tox_friend_typing_cb(Tox *tox, uint32_t friend_number, bool typing, void *user_data); /** diff --git a/toxcore/tox_events.h b/toxcore/tox_events.h index 35607451ad..27a19c8146 100644 --- a/toxcore/tox_events.h +++ b/toxcore/tox_events.h @@ -160,15 +160,15 @@ size_t tox_event_friend_request_get_message_length( const Tox_Event_Friend_Request *friend_request); typedef struct Tox_Event_Friend_Status Tox_Event_Friend_Status; -Tox_User_Status tox_event_friend_status_get_connection_status( +Tox_User_Status tox_event_friend_status_get_status( const Tox_Event_Friend_Status *friend_status); uint32_t tox_event_friend_status_get_friend_number( const Tox_Event_Friend_Status *friend_status); typedef struct Tox_Event_Friend_Status_Message Tox_Event_Friend_Status_Message; -const uint8_t *tox_event_friend_status_message_get_status_message( +const uint8_t *tox_event_friend_status_message_get_message( const Tox_Event_Friend_Status_Message *friend_status_message); -size_t tox_event_friend_status_message_get_status_message_length( +size_t tox_event_friend_status_message_get_message_length( const Tox_Event_Friend_Status_Message *friend_status_message); uint32_t tox_event_friend_status_message_get_friend_number( const Tox_Event_Friend_Status_Message *friend_status_message); diff --git a/toxencryptsave/toxencryptsave.c b/toxencryptsave/toxencryptsave.c index 76c6ce6bb3..a588398900 100644 --- a/toxencryptsave/toxencryptsave.c +++ b/toxencryptsave/toxencryptsave.c @@ -50,9 +50,9 @@ struct Tox_Pass_Key { uint8_t key[TOX_PASS_KEY_LENGTH]; }; -void tox_pass_key_free(Tox_Pass_Key *pass_key) +void tox_pass_key_free(Tox_Pass_Key *key) { - free(pass_key); + free(key); } /* Clients should consider alerting their users that, unlike plain data, if even one bit @@ -68,20 +68,20 @@ void tox_pass_key_free(Tox_Pass_Key *pass_key) * success does not say anything about the validity of the data, only that data of * the appropriate size was copied */ -bool tox_get_salt(const uint8_t *data, uint8_t *salt, Tox_Err_Get_Salt *error) +bool tox_get_salt(const uint8_t *ciphertext, uint8_t *salt, Tox_Err_Get_Salt *error) { - if (!data || !salt) { + if (!ciphertext || !salt) { SET_ERROR_PARAMETER(error, TOX_ERR_GET_SALT_NULL); return false; } - if (memcmp(data, TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) != 0) { + if (memcmp(ciphertext, TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) != 0) { SET_ERROR_PARAMETER(error, TOX_ERR_GET_SALT_BAD_FORMAT); return false; } - data += TOX_ENC_SAVE_MAGIC_LENGTH; - memcpy(salt, data, crypto_pwhash_scryptsalsa208sha256_SALTBYTES); + ciphertext += TOX_ENC_SAVE_MAGIC_LENGTH; + memcpy(salt, ciphertext, crypto_pwhash_scryptsalsa208sha256_SALTBYTES); SET_ERROR_PARAMETER(error, TOX_ERR_GET_SALT_OK); return true; } @@ -97,27 +97,27 @@ bool tox_get_salt(const uint8_t *data, uint8_t *salt, Tox_Err_Get_Salt *error) * * returns true on success */ -Tox_Pass_Key *tox_pass_key_derive(const uint8_t *passphrase, size_t pplength, +Tox_Pass_Key *tox_pass_key_derive(const uint8_t *passphrase, size_t passphrase_len, Tox_Err_Key_Derivation *error) { uint8_t salt[crypto_pwhash_scryptsalsa208sha256_SALTBYTES]; random_bytes(salt, sizeof(salt)); - return tox_pass_key_derive_with_salt(passphrase, pplength, salt, error); + return tox_pass_key_derive_with_salt(passphrase, passphrase_len, salt, error); } /* Same as above, except with use the given salt for deterministic key derivation. * The salt must be TOX_PASS_SALT_LENGTH bytes in length. */ -Tox_Pass_Key *tox_pass_key_derive_with_salt(const uint8_t *passphrase, size_t pplength, +Tox_Pass_Key *tox_pass_key_derive_with_salt(const uint8_t *passphrase, size_t passphrase_len, const uint8_t *salt, Tox_Err_Key_Derivation *error) { - if (!salt || (!passphrase && pplength != 0)) { + if (!salt || (!passphrase && passphrase_len != 0)) { SET_ERROR_PARAMETER(error, TOX_ERR_KEY_DERIVATION_NULL); return nullptr; } uint8_t passkey[crypto_hash_sha256_BYTES]; - crypto_hash_sha256(passkey, passphrase, pplength); + crypto_hash_sha256(passkey, passphrase, passphrase_len); uint8_t key[CRYPTO_SHARED_KEY_SIZE]; @@ -206,11 +206,11 @@ bool tox_pass_key_encrypt(const Tox_Pass_Key *key, const uint8_t *plaintext, siz * * returns true on success */ -bool tox_pass_encrypt(const uint8_t *data, size_t data_len, const uint8_t *passphrase, size_t pplength, uint8_t *out, - Tox_Err_Encryption *error) +bool tox_pass_encrypt(const uint8_t *plaintext, size_t plaintext_len, const uint8_t *passphrase, size_t passphrase_len, + uint8_t *ciphertext, Tox_Err_Encryption *error) { Tox_Err_Key_Derivation err; - Tox_Pass_Key *key = tox_pass_key_derive(passphrase, pplength, &err); + Tox_Pass_Key *key = tox_pass_key_derive(passphrase, passphrase_len, &err); if (key == nullptr) { if (err == TOX_ERR_KEY_DERIVATION_NULL) { @@ -222,7 +222,7 @@ bool tox_pass_encrypt(const uint8_t *data, size_t data_len, const uint8_t *passp return 0; } - bool result = tox_pass_key_encrypt(key, data, data_len, out, error); + bool result = tox_pass_key_encrypt(key, plaintext, plaintext_len, ciphertext, error); tox_pass_key_free(key); return result; } @@ -234,7 +234,7 @@ bool tox_pass_encrypt(const uint8_t *data, size_t data_len, const uint8_t *passp * * returns true on success */ -bool tox_pass_key_decrypt(const Tox_Pass_Key *key, const uint8_t *data, size_t length, uint8_t *out, +bool tox_pass_key_decrypt(const Tox_Pass_Key *key, const uint8_t *ciphertext, size_t length, uint8_t *plaintext, Tox_Err_Decryption *error) { if (length <= TOX_PASS_ENCRYPTION_EXTRA_LENGTH) { @@ -242,27 +242,27 @@ bool tox_pass_key_decrypt(const Tox_Pass_Key *key, const uint8_t *data, size_t l return 0; } - if (!data || !key || !out) { + if (!ciphertext || !key || !plaintext) { SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_NULL); return 0; } - if (memcmp(data, TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) != 0) { + if (memcmp(ciphertext, TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) != 0) { SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_BAD_FORMAT); return 0; } - data += TOX_ENC_SAVE_MAGIC_LENGTH; - data += crypto_pwhash_scryptsalsa208sha256_SALTBYTES; // salt only affects key derivation + ciphertext += TOX_ENC_SAVE_MAGIC_LENGTH; + ciphertext += crypto_pwhash_scryptsalsa208sha256_SALTBYTES; // salt only affects key derivation size_t decrypt_length = length - TOX_PASS_ENCRYPTION_EXTRA_LENGTH; uint8_t nonce[crypto_box_NONCEBYTES]; - memcpy(nonce, data, crypto_box_NONCEBYTES); - data += crypto_box_NONCEBYTES; + memcpy(nonce, ciphertext, crypto_box_NONCEBYTES); + ciphertext += crypto_box_NONCEBYTES; - /* decrypt the data */ - if (decrypt_data_symmetric(key->key, nonce, data, decrypt_length + crypto_box_MACBYTES, out) + /* decrypt the ciphertext */ + if (decrypt_data_symmetric(key->key, nonce, ciphertext, decrypt_length + crypto_box_MACBYTES, plaintext) != decrypt_length) { SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_FAILED); return 0; @@ -280,29 +280,29 @@ bool tox_pass_key_decrypt(const Tox_Pass_Key *key, const uint8_t *data, size_t l * * returns true on success */ -bool tox_pass_decrypt(const uint8_t *data, size_t length, const uint8_t *passphrase, size_t pplength, uint8_t *out, - Tox_Err_Decryption *error) +bool tox_pass_decrypt(const uint8_t *ciphertext, size_t ciphertext_len, const uint8_t *passphrase, + size_t passphrase_len, uint8_t *plaintext, Tox_Err_Decryption *error) { - if (length <= TOX_PASS_ENCRYPTION_EXTRA_LENGTH) { + if (ciphertext_len <= TOX_PASS_ENCRYPTION_EXTRA_LENGTH) { SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_INVALID_LENGTH); return 0; } - if (!data || !passphrase || !out) { + if (!ciphertext || !passphrase || !plaintext) { SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_NULL); return 0; } - if (memcmp(data, TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) != 0) { + if (memcmp(ciphertext, TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) != 0) { SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_BAD_FORMAT); return 0; } uint8_t salt[crypto_pwhash_scryptsalsa208sha256_SALTBYTES]; - memcpy(salt, data + TOX_ENC_SAVE_MAGIC_LENGTH, crypto_pwhash_scryptsalsa208sha256_SALTBYTES); + memcpy(salt, ciphertext + TOX_ENC_SAVE_MAGIC_LENGTH, crypto_pwhash_scryptsalsa208sha256_SALTBYTES); /* derive the key */ - Tox_Pass_Key *key = tox_pass_key_derive_with_salt(passphrase, pplength, salt, nullptr); + Tox_Pass_Key *key = tox_pass_key_derive_with_salt(passphrase, passphrase_len, salt, nullptr); if (key == nullptr) { /* out of memory most likely */ @@ -310,7 +310,7 @@ bool tox_pass_decrypt(const uint8_t *data, size_t length, const uint8_t *passphr return 0; } - bool result = tox_pass_key_decrypt(key, data, length, out, error); + bool result = tox_pass_key_decrypt(key, ciphertext, ciphertext_len, plaintext, error); tox_pass_key_free(key); return result; }