summaryrefslogtreecommitdiff
path: root/protocols/Tox/libtox/src/toxcore/timed_auth.c
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-02-15 12:18:35 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-02-15 12:18:35 +0300
commit31e72718ee54867accf0b739a24adc86f8b7ab54 (patch)
treef964c10c5d97d9fe4fd2bd8187c250faedcb0fd7 /protocols/Tox/libtox/src/toxcore/timed_auth.c
parent282e9c18d9d3b726cce3d2ef0babc88029661cb8 (diff)
libtox update
Diffstat (limited to 'protocols/Tox/libtox/src/toxcore/timed_auth.c')
-rw-r--r--protocols/Tox/libtox/src/toxcore/timed_auth.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/protocols/Tox/libtox/src/toxcore/timed_auth.c b/protocols/Tox/libtox/src/toxcore/timed_auth.c
index ebd5100286..875003257b 100644
--- a/protocols/Tox/libtox/src/toxcore/timed_auth.c
+++ b/protocols/Tox/libtox/src/toxcore/timed_auth.c
@@ -5,9 +5,12 @@
#include <string.h>
+#include "attributes.h"
#include "ccompat.h"
+#include "crypto_core.h"
+#include "mono_time.h"
-non_null(1,6) nullable(4)
+non_null(1, 6) nullable(4)
static void create_timed_auth_to_hash(const Mono_Time *mono_time, uint16_t timeout, bool previous, const uint8_t *data,
uint16_t length, uint8_t *to_hash)
{
@@ -22,20 +25,22 @@ static void create_timed_auth_to_hash(const Mono_Time *mono_time, uint16_t timeo
void generate_timed_auth(const Mono_Time *mono_time, uint16_t timeout, const uint8_t *key,
const uint8_t *data, uint16_t length, uint8_t *timed_auth)
{
- VLA(uint8_t, to_hash, sizeof(uint64_t) + length);
+ const uint16_t to_hash_size = sizeof(uint64_t) + length;
+ VLA(uint8_t, to_hash, to_hash_size);
create_timed_auth_to_hash(mono_time, timeout, false, data, length, to_hash);
- crypto_hmac(timed_auth, key, to_hash, SIZEOF_VLA(to_hash));
+ crypto_hmac(timed_auth, key, to_hash, to_hash_size);
}
bool check_timed_auth(const Mono_Time *mono_time, uint16_t timeout, const uint8_t *key, const uint8_t *data,
uint16_t length, const uint8_t *timed_auth)
{
- VLA(uint8_t, to_hash, sizeof(uint64_t) + length);
+ const uint16_t to_hash_size = sizeof(uint64_t) + length;
+ VLA(uint8_t, to_hash, to_hash_size);
for (uint8_t i = 0; i < 2; ++i) {
create_timed_auth_to_hash(mono_time, timeout, i != 0, data, length, to_hash);
- if (crypto_hmac_verify(timed_auth, key, to_hash, SIZEOF_VLA(to_hash))) {
+ if (crypto_hmac_verify(timed_auth, key, to_hash, to_hash_size)) {
return true;
}
}