Coverage Report

Created: 2025-10-08 19:34

/work/toxcore/os_random.c
Line
Count
Source (jump to first uncovered line)
1
/* SPDX-License-Identifier: GPL-3.0-or-later
2
 * Copyright © 2022-2025 The TokTok team.
3
 */
4
#include "os_random.h"
5
6
#include <sodium.h>
7
8
#include "attributes.h"
9
#include "ccompat.h"
10
#include "tox_random.h"
11
#include "tox_random_impl.h"
12
13
static void os_random_bytes(void *_Nonnull self, uint8_t *_Nonnull bytes, uint32_t length)
14
1.39M
{
15
1.39M
    randombytes(bytes, length);
16
1.39M
}
17
18
static uint32_t os_random_uniform(void *_Nonnull self, uint32_t upper_bound)
19
247k
{
20
247k
    return randombytes_uniform(upper_bound);
21
247k
}
22
23
static const Tox_Random_Funcs os_random_funcs = {
24
    os_random_bytes,
25
    os_random_uniform,
26
};
27
28
const Tox_Random os_random_obj = {&os_random_funcs};
29
30
const Tox_Random *os_random(void)
31
3.34k
{
32
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
33
1.40k
    if ((true)) {
34
1.40k
        return nullptr;
35
1.40k
    }
36
0
#endif /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */
37
    // It is safe to call this function more than once and from different
38
    // threads -- subsequent calls won't have any effects.
39
1.94k
    if (sodium_init() == -1) {
40
0
        return nullptr;
41
0
    }
42
1.94k
    return &os_random_obj;
43
0
}
os_random
Line
Count
Source
31
1.40k
{
32
1.40k
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
33
1.40k
    if ((true)) {
34
1.40k
        return nullptr;
35
1.40k
    }
36
0
#endif /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */
37
    // It is safe to call this function more than once and from different
38
    // threads -- subsequent calls won't have any effects.
39
0
    if (sodium_init() == -1) {
40
0
        return nullptr;
41
0
    }
42
0
    return &os_random_obj;
43
0
}
os_random
Line
Count
Source
31
1.94k
{
32
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
33
    if ((true)) {
34
        return nullptr;
35
    }
36
#endif /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */
37
    // It is safe to call this function more than once and from different
38
    // threads -- subsequent calls won't have any effects.
39
1.94k
    if (sodium_init() == -1) {
40
0
        return nullptr;
41
0
    }
42
1.94k
    return &os_random_obj;
43
1.94k
}