/work/toxcore/timed_auth.h
Line | Count | Source |
1 | | /* SPDX-License-Identifier: GPL-3.0-or-later |
2 | | * Copyright © 2019-2021 The TokTok team. |
3 | | */ |
4 | | #ifndef C_TOXCORE_TOXCORE_TIMED_AUTH_H |
5 | | #define C_TOXCORE_TOXCORE_TIMED_AUTH_H |
6 | | |
7 | | #include "crypto_core.h" |
8 | | #include "mono_time.h" |
9 | | |
10 | 1.35M | #define TIMED_AUTH_SIZE CRYPTO_HMAC_SIZE |
11 | | |
12 | | /** |
13 | | * @brief Write timed authentication code of data to timed_auth. |
14 | | * |
15 | | * @param timed_auth Must be of size TIMED_AUTH_SIZE. |
16 | | */ |
17 | | |
18 | | non_null(1, 3, 6) nullable(4) |
19 | | void generate_timed_auth(const Mono_Time *mono_time, uint16_t timeout, const uint8_t *key, |
20 | | const uint8_t *data, uint16_t length, uint8_t *timed_auth); |
21 | | |
22 | | /** |
23 | | * @brief Check timed_auth. This succeeds if `timed_auth` was generated by |
24 | | * `generate_timed_auth` at most `timeout` seconds ago, and fails if at least |
25 | | * `2*timeout` seconds ago. More precisely, it succeeds iff |
26 | | * `current_time / timeout` is equal to or one more than |
27 | | * `creation_time / timeout`. |
28 | | * |
29 | | * @param timed_auth Must be of size TIMED_AUTH_SIZE. |
30 | | * @return true on success, false otherwise. |
31 | | */ |
32 | | non_null(1, 3, 6) nullable(4) |
33 | | bool check_timed_auth(const Mono_Time *mono_time, uint16_t timeout, const uint8_t *key, |
34 | | const uint8_t *data, uint16_t length, const uint8_t *timed_auth); |
35 | | #endif /* C_TOXCORE_TOXCORE_TIMED_AUTH_H */ |