Debian Codegraph @

nanorand-abi/nanorand.h

raw symbols SCIP
1 /*
2 * Copyright (c) 2022 Lucy <[email protected]>
3 * This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held
4 * liable for any damages arising from the use of this software.
5 * Permission is granted to anyone to use this software for any purpose, including commercial applications, and to
6 * alter it and redistribute it freely, subject to the following restrictions:
7 * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original
8 * software. If you use this software in a product, an acknowledgment in the product documentation would be
9 * appreciated but is not required.
10 * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original
11 * software.
12 * 3. This notice may not be removed or altered from any source distribution.
13 */
14
15 #ifndef NANORAND_H
16 #define NANORAND_H
17
18 #define DEFINE_NANORAND_BASE(type, buffered_type, name) \
19 type *new_##name(void); \
20 void free_##name(type *rng); \
21 void name##_fill(type *rng, void *buffer, usize length); \
22 buffered_type *name##_buffered(type *rng); \
23 void free_##name##_buffered(buffered_type *rng); \
24 void name##_buffered_fill(buffered_type *rng, void *buffer, usize length);
25
26 #define DEFINE_NANORAND_RANGES(type, name) \
27 u8 name##_range_u8(type *rng, u8 lower, u8 upper); \
28 u16 name##_range_u16(type *rng, u16 lower, u16 upper); \
29 u32 name##_range_u32(type *rng, u32 lower, u32 upper); \
30 u64 name##_range_u64(type *rng, u64 lower, u64 upper); \
31 usize name##_range_usize(type *rng, usize lower, usize upper); \
32 i8 name##_range_i8(type *rng, i8 lower, i8 upper); \
33 i16 name##_range_i16(type *rng, i16 lower, i16 upper); \
34 i32 name##_range_i32(type *rng, i32 lower, i32 upper); \
35 i64 name##_range_i64(type *rng, i64 lower, i64 upper); \
36 isize name##_range_isize(type *rng, isize lower, isize upper);
37
38 #include <stdint.h>
39 typedef uint8_t u8;
40 typedef uint16_t u16;
41 typedef uint32_t u32;
42 typedef uint64_t u64;
43 typedef uintptr_t usize;
44 typedef int8_t i8;
45 typedef int16_t i16;
46 typedef int32_t i32;
47 typedef int64_t i64;
48 typedef intptr_t isize;
49
50 #ifdef __cplusplus
51 extern "C"
52 {
53 #endif
54
55 typedef struct _WyRand WyRand;
56 typedef struct _BufferedWyRand BufferedWyRand;
57 DEFINE_NANORAND_BASE(WyRand, BufferedWyRand, wyrand);
58 DEFINE_NANORAND_RANGES(WyRand, wyrand);
59
60 typedef struct _Pcg64 Pcg64;
61 typedef struct _BufferedPcg64 BufferedPcg64;
62 DEFINE_NANORAND_BASE(Pcg64, BufferedPcg64, pcg64);
63 DEFINE_NANORAND_RANGES(Pcg64, pcg64);
64
65 typedef struct _ChaCha8 ChaCha8;
66 typedef struct _BufferedChaCha8 BufferedChaCha8;
67 DEFINE_NANORAND_BASE(ChaCha8, BufferedChaCha8, chacha8);
68 DEFINE_NANORAND_RANGES(ChaCha8, chacha8);
69
70 typedef struct _ChaCha12 ChaCha12;
71 typedef struct _BufferedChaCha12 BufferedChaCha12;
72 DEFINE_NANORAND_BASE(ChaCha12, BufferedChaCha12, chacha12);
73 DEFINE_NANORAND_RANGES(ChaCha12, chacha12);
74
75 typedef struct _ChaCha20 ChaCha20;
76 typedef struct _BufferedChaCha20 BufferedChaCha20;
77 DEFINE_NANORAND_BASE(ChaCha20, BufferedChaCha20, chacha20);
78 DEFINE_NANORAND_RANGES(ChaCha20, chacha20);
79
80 #ifdef __cplusplus
81 }
82 #endif
83
84 #endif