1-- The clocks, sleeping and the system's random bytes: kernel32's time
2-- calls and bcrypt's `BCryptGenRandom`, raw.
3
4fixed if compiler.os == windows then
5 linker.library("bcrypt")
6
7 --- The wall clock, `GetSystemTimePreciseAsFileTime`: hundreds of
8 --- nanoseconds since 1601 in UTC, as precise as the system keeps it.
9 public extern(c) link(symbol: "GetSystemTimePreciseAsFileTime") system_time: (into: ptr mut file_time) -> none
10
11 --- The performance counter, `QueryPerformanceCounter`: ticks since the
12 --- system started, which never go back, at `performance_frequency` a
13 --- second. It never fails on a system that runs Windows 10 or later.
14 public extern(c) link(symbol: "QueryPerformanceCounter") performance_counter: (into: ptr mut i64) -> (done: i32)
15
16 --- The performance counter's ticks a second,
17 --- `QueryPerformanceFrequency`, fixed while the system runs.
18 public extern(c) link(symbol: "QueryPerformanceFrequency") performance_frequency: (into: ptr mut i64) -> (done: i32)
19
20 --- Give up the processor for at least `milliseconds`, `Sleep`; zero
21 --- gives up the rest of the thread's turn.
22 public extern(c) link(symbol: "Sleep") sleep: (milliseconds: u32) -> none
23
24 --- `BCRYPT_USE_SYSTEM_PREFERRED_RNG`: `random` asks the system's own
25 --- generator, with no algorithm handle.
26 public system_preferred_generator: u32 = 2
27
28 --- Fill `count` bytes at `into` from the system's random generator,
29 --- which is fit for keys, `BCryptGenRandom`: zero, or an NTSTATUS that
30 --- says why it did not.
31 public extern(c) link(symbol: "BCryptGenRandom") random:
32 (algorithm: usize, into: ptr mut u8, count: u32, flags: u32)
33 -> (status: i32)
34
35 --- Hundreds of nanoseconds from 1601 to 1970, the Unix epoch.
36 public epoch_difference: u64 = 116444736000000000
37end if