Debian Codegraph @

NOTES

raw
1
2 TIME
3 ================================================================================
4 A cryptographic RNG implementation can:
5 - read from the /dev/urandom device in Linux-based systems (using the open and read system calls where available)[^21],
6 - call the arc4random or arc4random_buf method on FreeBSD or macOS,
7 - call the getentropy method on OpenBSD, or
8 - call the BCryptGenRandom API in Windows 10 and later.
9
10
11 ==== Windows Random Generators =================================================
12 There are three of them:
13
14 RtlGenRandom a.k.a. SystemFunction036 in advapi32.dll. This is the oldest one, and is hacky, but it does work and won't be going away any time soon.
15 CryptGenRandom, the older CryptoAPI in Windows. Crypt32 is obsolete, but current versions will accept it though might be slow.
16 BCryptGenRandom, the BCrypt library added in Windows Vista, is the current most supported one.
17 BCryptGenRandom is the one I would recommend.
18
19 Windows does not have a pseudo-file like /dev/urandom. The NT path \Device\KsecDD is the kernel driver behind these GenRandom functions, but accessing the generator is done via DeviceIoControl rather than direct read operations.
20 ================================================================================
21
22
23 RANDOM
24 ================================================================================
25 https://www.ietf.org/archive/id/draft-peabody-dispatch-new-uuid-format-04.html
26 --------------------------------------------------------------------------------
27 # Unix Nanosecond precision to Gregorian 100-nanosecond intervals
28 gregorian_100_ns = (Unix_64_bit_nanoseconds / 100) + gregorian_Unix_offset
29
30 # Gregorian to Unix Offset:
31 # The number of 100-ns intervals between the
32 # UUID epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00.
33 # gregorian_Unix_offset = 0x01b21dd213814000 or 122192928000000000
34
35 # Unix 64 bit Nanosecond Timestamp:
36 # Unix NS: Tuesday, February 22, 2022 2:22:22 PM GMT-05:00
37 # Unix_64_bit_nanoseconds = 0x16D6320C3D4DCC00 or 1645557742000000000
38
39 # Work:
40 # gregorian_100_ns = (1645557742000000000 / 100) + 122192928000000000
41 # (138648505420000000 - 122192928000000000) * 100 = Unix_64_bit_nanoseconds
42
43 # Final:
44 # gregorian_100_ns = 0x1EC9414C232AB00 or 138648505420000000
45
46 # Original: 000111101100100101000001010011000010001100101010101100000000
47 # UUIDv1: 11000010001100101010101100000000|1001010000010100|0001|000111101100
48 # UUIDv6: 00011110110010010100000101001100|0010001100101010|0110|101100000000
49 ================================================================================
50
51
52 VERSIONS (culled from RFC4122.bis)
53 ================================================================================
54 v1: (gregorian epoch timestamp)
55 0 1 2 3
56 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
57 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
58 | time_low |
59 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
60 | time_mid | ver | time_high |
61 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
62 |var| clock_seq | node |
63 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
64 | node |
65 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
66
67 v2: (gregorian epoch timestamp)
68 C309 C311
69
70 v3: (no timestamp)
71 0 1 2 3
72 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
73 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
74 | md5_high |
75 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
76 | md5_high | ver | md5_mid |
77 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
78 |var| md5_low |
79 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
80 | md5_low |
81 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
82
83 v4: (no timestamp)
84 0 1 2 3
85 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
86 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
87 | random_a |
88 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
89 | random_a | ver | random_b |
90 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
91 |var| random_c |
92 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
93 | random_c |
94 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
95
96 v5: (no timestamp)
97 0 1 2 3
98 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
99 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
100 | sha1_high |
101 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
102 | sha1_high | ver | sha1_mid |
103 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
104 |var| sha1_low |
105 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
106 | sha1_low |
107 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
108
109 v6: (gregorian epoch timestamp)
110 0 1 2 3
111 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
112 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
113 | time_high |
114 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
115 | time_mid | ver | time_low |
116 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
117 |var| clock_seq | node |
118 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
119 | node |
120 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
121
122 v7: (unix epoch timestamp)
123 0 1 2 3
124 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
125 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
126 | unix_ts_ms |
127 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
128 | unix_ts_ms | ver | rand_a |
129 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
130 |var| rand_b |
131 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
132 | rand_b |
133 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
134
135 v8: (no timestamp)
136 0 1 2 3
137 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
138 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
139 | custom_a |
140 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
141 | custom_a | ver | custom_b |
142 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
143 |var| custom_c |
144 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
145 | custom_c |
146 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+