summaryrefslogtreecommitdiff
path: root/protocols/Tox/libtox/src/toxcore/timed_auth.h
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2022-07-24 16:44:24 +0300
committerGeorge Hazan <ghazan@miranda.im>2022-07-24 16:44:24 +0300
commite55d071e5485a937efd427d159b76c208cccdcce (patch)
tree48d09dc5cf1df2581fd6471b5ccf1560015fa3a4 /protocols/Tox/libtox/src/toxcore/timed_auth.h
parentf36629f67153bc500c828cf51de31988122a1024 (diff)
fixes #3118 (Update toxcore to 0.2.18)
Diffstat (limited to 'protocols/Tox/libtox/src/toxcore/timed_auth.h')
-rw-r--r--protocols/Tox/libtox/src/toxcore/timed_auth.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/protocols/Tox/libtox/src/toxcore/timed_auth.h b/protocols/Tox/libtox/src/toxcore/timed_auth.h
new file mode 100644
index 0000000000..691b04d0df
--- /dev/null
+++ b/protocols/Tox/libtox/src/toxcore/timed_auth.h
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later
+ * Copyright © 2019-2021 The TokTok team.
+ */
+#ifndef C_TOXCORE_TOXCORE_TIMED_AUTH_H
+#define C_TOXCORE_TOXCORE_TIMED_AUTH_H
+
+#include "crypto_core.h"
+#include "mono_time.h"
+
+#define TIMED_AUTH_SIZE CRYPTO_HMAC_SIZE
+
+/**
+ * @brief Write timed authentication code of data to timed_auth.
+ *
+ * @param timed_auth Must be of size TIMED_AUTH_SIZE.
+ */
+
+non_null(1, 3, 6) nullable(4)
+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);
+
+/**
+ * @brief Check timed_auth. This succeeds if `timed_auth` was generated by
+ * `generate_timed_auth` at most `timeout` seconds ago, and fails if at least
+ * `2*timeout` seconds ago. More precisely, it succeeds iff
+ * `current_time / timeout` is equal to or one more than
+ * `creation_time / timeout`.
+ *
+ * @param timed_auth Must be of size TIMED_AUTH_SIZE.
+ * @return true on success, false otherwise.
+ */
+non_null(1, 3, 6) nullable(4)
+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);
+#endif