Coverage Report

Created: 2025-10-08 19:34

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