Coverage Report

Created: 2026-10-24 08:16

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