Subversion Repositories uuid_mac_utils

Rev

Rev 69 | Rev 71 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
31 daniel-mar 1
<?php
2 daniel-mar 2
 
31 daniel-mar 3
/*
4
* UUID & MAC Utils
5
* Copyright 2017 - 2023 Daniel Marschall, ViaThinkSoft
69 daniel-mar 6
* Version 2023-09-23
31 daniel-mar 7
*
8
* Licensed under the Apache License, Version 2.0 (the "License");
9
* you may not use this file except in compliance with the License.
10
* You may obtain a copy of the License at
11
*
12
*     http://www.apache.org/licenses/LICENSE-2.0
13
*
14
* Unless required by applicable law or agreed to in writing, software
15
* distributed under the License is distributed on an "AS IS" BASIS,
16
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
* See the License for the specific language governing permissions and
18
* limitations under the License.
19
*/
20
 
21
include_once __DIR__.'/includes/uuid_utils.inc.php';
22
 
23
const AUTO_NEW_UUIDS = 10;
24
 
25
?><!DOCTYPE html>
26
<html lang="en">
27
 
2 daniel-mar 28
<head>
29
        <meta charset="iso-8859-1">
30
        <link rel="stylesheet" type="text/css" href="style.css">
31
        <title>UUID &amp; MAC Utils by Daniel Marschall</title>
35 daniel-mar 32
        <meta name=viewport content="width=device-width, initial-scale=1">
2 daniel-mar 33
</head>
34
 
35
<body>
36
 
25 daniel-mar 37
<h1>UUID &amp; MAC Utils by Daniel Marschall</h1>
2 daniel-mar 38
 
12 daniel-mar 39
<p><a href="https://github.com/danielmarschall/uuid_mac_utils/">View the source code</a></p>
2 daniel-mar 40
 
31 daniel-mar 41
<h2>Overview</h2>
2 daniel-mar 42
 
31 daniel-mar 43
<ul>
44
    <li><a href="#gen_uuid">Generate random and/or time-based UUIDs</a><ul>
45
            <li><a href="#gen_uuidv7"><font color="green">New:</font> Generate Unix Epoch Time (version 7) UUID</a></li>
46
            <li><a href="#gen_uuidv6"><font color="green">New:</font> Generate reordered time-based (version 6) UUID</a></li>
47
            <li><a href="#gen_uuidv4">Generate random (version 4) UUID</a></li>
48
            <li><a href="#gen_uuidv1">Generate time-based (version 1) UUID</a></li>
49
        </ul></li>
50
    <li><a href="#gen_other_uuid">Generate other UUID types</a><ul>
53 daniel-mar 51
            <li><a href="#gen_uuid_ncs">NCS (variant 0) UUID</a></li>
31 daniel-mar 52
            <li><a href="#gen_uuidv2">Generate DCE Security (version 2) UUID</a></li>
61 daniel-mar 53
            <li><a href="#gen_uuidv35">Generate name-based (version 3 / 5 / <font color="green">New: 8</font>) UUID</a></li>
54
            <li><a href="#gen_uuidv8"><font color="green">New:</font> Generate Custom (version 8) UUID</a></li>
31 daniel-mar 55
        </ul></li>
56
    <li><a href="#interpret_uuid">Interpret a UUID</a></li>
41 daniel-mar 57
    <li><a href="#interpret_mac">Interpret a MAC address (MAC / EUI / ELI / SAI / AAI)</a><ul>
58
        <li><a href="#gen_aai">Generate an AAI</a></li>
59
    </ul></li>
31 daniel-mar 60
</ul>
2 daniel-mar 61
 
31 daniel-mar 62
<h2 id="gen_uuid">Generate random and/or time-based UUIDs</h2>
30 daniel-mar 63
 
62 daniel-mar 64
<h3 id="gen_uuidv7"><font color="green">New:</font> Generate Unix Epoch Time (version 7) UUID &#11088;</h3>
31 daniel-mar 65
 
35 daniel-mar 66
<p><i>A UUIDv7 is made of time and 74 random&nbsp;bits.
31 daniel-mar 67
        Since the time is at the beginning, the UUIDs are monotonically increasing.
68
        Due to the missing MAC address, this UUID version is recommended due to
69
        improved privacy.</i></p>
70
 
35 daniel-mar 71
<script>
72
function show_uuidv7_info() {
73
        document.getElementById("uuidv7_info_button").style.display = "none";
74
        document.getElementById("uuidv7_info").style.display = "block";
75
}
76
</script>
62 daniel-mar 77
<p><a id="uuidv7_info_button" href="javascript:show_uuidv7_info()">Show format</a>
35 daniel-mar 78
<pre id="uuidv7_info" style="display:none">Variant 1, Version 7 UUID:
37 daniel-mar 79
- 48 bit <abbr title="Count of 1ms intervals passed since 1 Jan 1970 00:00:00 GMT">Unix Time in milliseconds</abbr>
35 daniel-mar 80
-  4 bit Version (fix 0x7)
70 daniel-mar 81
- 12 bit Data
35 daniel-mar 82
-  2 bit Variant (fix 0b10)
70 daniel-mar 83
- 62 bit Data
35 daniel-mar 84
 
70 daniel-mar 85
Structure of data (74 bits):
86
- OPTIONAL : Sub-millisecond timestamp fraction (0-12 bits)
87
- OPTIONAL : Carefully seeded counter
88
- Random generated bits for any remaining space
89
 
90
Time resolution for various sub-millisecond bits:
31 daniel-mar 91
<?php
70 daniel-mar 92
for ($num_ms_frac_bits=0; $num_ms_frac_bits<=12; $num_ms_frac_bits++) {
93
        $resolution_ns = 1000000 / pow(2,$num_ms_frac_bits);
94
        if ($resolution_ns >= 1000000) $resolution_ns_hf = ($resolution_ns/1000000)." ms";
95
        else if ($resolution_ns >= 1000) $resolution_ns_hf = ($resolution_ns/1000)." &micro;s";
96
        else $resolution_ns_hf = "$resolution_ns ns";
97
        echo "$num_ms_frac_bits bits fraction = $resolution_ns_hf\n";
98
}
99
?>
100
 
101
</pre></p>
102
 
103
<?php
31 daniel-mar 104
if (AUTO_NEW_UUIDS > 0) { /** @phpstan-ignore-line */
35 daniel-mar 105
        echo '<p>Here are '.AUTO_NEW_UUIDS.' UUIDs that were created just for you! (Reload the page to get more)</p>';
31 daniel-mar 106
 
107
        echo '<pre>';
70 daniel-mar 108
        for ($i=0; $i<AUTO_NEW_UUIDS; $i++) {
31 daniel-mar 109
                $uuid = gen_uuid_v7();
110
                echo '<a href="interprete_uuid.php?uuid='.$uuid.'">'.$uuid.'</a><br>';
111
        }
112
        echo '</pre>';
113
}
114
?>
115
 
2 daniel-mar 116
<form method="GET" action="interprete_uuid.php">
31 daniel-mar 117
    <input type="hidden" name="version" value="7">
118
    <input type="hidden" name="uuid" value="CREATE"> <input type="submit" value="Create and display another UUID">
2 daniel-mar 119
</form>
120
 
32 daniel-mar 121
<h3 id="gen_uuidv6"><font color="green">New:</font> Generate reordered time-based (version 6) UUID &#9200;</h3>
2 daniel-mar 122
 
31 daniel-mar 123
<p><i>Like UUIDv1, this kind of UUID is made of the MAC address of the generating computer,
124
        the time, and a clock sequence. However, the components in UUIDv6 are reordered (time is at the beginning),
125
        so that UUIDs are monotonically increasing.</i></p>
2 daniel-mar 126
 
35 daniel-mar 127
<script>
128
function show_uuidv6_info() {
129
        document.getElementById("uuidv6_info_button").style.display = "none";
130
        document.getElementById("uuidv6_info").style.display = "block";
131
}
132
</script>
62 daniel-mar 133
<p><a id="uuidv6_info_button" href="javascript:show_uuidv6_info()">Show format</a>
35 daniel-mar 134
<pre id="uuidv6_info" style="display:none">Variant 1, Version 6 UUID:
37 daniel-mar 135
- 48 bit High <abbr title="Count of 100ns intervals passed since 15 Oct 1582 00:00:00 GMT">Time</abbr>
35 daniel-mar 136
-  4 bit Version (fix 0x6)
37 daniel-mar 137
- 12 bit Low <abbr title="Count of 100ns intervals passed since 15 Oct 1582 00:00:00 GMT">Time</abbr>
35 daniel-mar 138
-  2 bit Variant (fix 0b10)
139
-  6 bit Clock Sequence High
140
-  8 bit Clock Sequence Low
141
- 48 bit MAC Address</pre></p>
142
 
31 daniel-mar 143
<?php
144
if (AUTO_NEW_UUIDS > 0) { /** @phpstan-ignore-line */
35 daniel-mar 145
        echo '<p>Here are '.AUTO_NEW_UUIDS.' UUIDs that were created just for you! (Reload the page to get more)</p>';
31 daniel-mar 146
 
147
        echo '<pre>';
70 daniel-mar 148
        for ($i=0; $i<AUTO_NEW_UUIDS; $i++) {
31 daniel-mar 149
                $uuid = gen_uuid_v6();
150
                echo '<a href="interprete_uuid.php?uuid='.$uuid.'">'.$uuid.'</a><br>';
151
        }
152
        echo '</pre>';
153
}
154
?>
155
 
2 daniel-mar 156
<form method="GET" action="interprete_uuid.php">
31 daniel-mar 157
    <input type="hidden" name="version" value="6">
158
    <input type="hidden" name="uuid" value="CREATE"> <input type="submit" value="Create and display another UUID">
30 daniel-mar 159
</form>
160
 
31 daniel-mar 161
<h3 id="gen_uuidv4">Generate random (version 4) UUID &#x1F3B2;</h3>
30 daniel-mar 162
 
35 daniel-mar 163
<p><i>A UUIDv4 is made of 122 random&nbsp;bits. No other information is encoded in this kind of UUID.</i></p>
30 daniel-mar 164
 
35 daniel-mar 165
<script>
166
function show_uuidv4_info() {
167
        document.getElementById("uuidv4_info_button").style.display = "none";
168
        document.getElementById("uuidv4_info").style.display = "block";
169
}
170
</script>
62 daniel-mar 171
<p><a id="uuidv4_info_button" href="javascript:show_uuidv4_info()">Show format</a>
35 daniel-mar 172
<pre id="uuidv4_info" style="display:none">Variant 1, Version 4 UUID:
173
- 48 bit Random High
174
-  4 bit Version (fix 0x4)
175
- 12 bit Random Mid
176
-  2 bit Variant (fix 0b10)
177
- 62 bit Random Low</pre></p>
178
 
31 daniel-mar 179
<?php
180
if (AUTO_NEW_UUIDS > 0) { /** @phpstan-ignore-line */
35 daniel-mar 181
        echo '<p>Here are '.AUTO_NEW_UUIDS.' UUIDs that were created just for you! (Reload the page to get more)</p>';
31 daniel-mar 182
 
183
        echo '<pre>';
70 daniel-mar 184
        for ($i=0; $i<AUTO_NEW_UUIDS; $i++) {
31 daniel-mar 185
                $uuid = gen_uuid_v4();
186
                echo '<a href="interprete_uuid.php?uuid='.$uuid.'">'.$uuid.'</a><br>';
187
        }
188
        echo '</pre>';
189
}
190
?>
191
 
30 daniel-mar 192
<form method="GET" action="interprete_uuid.php">
31 daniel-mar 193
    <input type="hidden" name="version" value="4">
194
    <input type="hidden" name="uuid" value="CREATE"> <input type="submit" value="Create and display another UUID">
30 daniel-mar 195
</form>
196
 
32 daniel-mar 197
<h3 id="gen_uuidv1">Generate time-based (version 1) UUID &#9200;</h3>
30 daniel-mar 198
 
31 daniel-mar 199
<p><i>A UUIDv1 is made of the MAC address of the generating computer,
200
the time, and a clock sequence.</i></p>
30 daniel-mar 201
 
35 daniel-mar 202
<script>
203
function show_uuidv1_info() {
204
        document.getElementById("uuidv1_info_button").style.display = "none";
205
        document.getElementById("uuidv1_info").style.display = "block";
206
}
207
</script>
62 daniel-mar 208
<p><a id="uuidv1_info_button" href="javascript:show_uuidv1_info()">Show format</a>
35 daniel-mar 209
<pre id="uuidv1_info" style="display:none">Variant 1, Version 1 UUID:
37 daniel-mar 210
- 32 bit Low <abbr title="Count of 100ns intervals passed since 15 Oct 1582 00:00:00 GMT">Time</abbr>
211
- 16 bit Mid <abbr title="Count of 100ns intervals passed since 15 Oct 1582 00:00:00 GMT">Time</abbr>
35 daniel-mar 212
-  4 bit Version (fix 0x1)
37 daniel-mar 213
- 12 bit High <abbr title="Count of 100ns intervals passed since 15 Oct 1582 00:00:00 GMT">Time</abbr>
35 daniel-mar 214
-  2 bit Variant (fix 0b10)
215
-  6 bit Clock Sequence High
216
-  8 bit Clock Sequence Low
217
- 48 bit MAC Address</pre></p>
218
 
31 daniel-mar 219
<?php
220
if (AUTO_NEW_UUIDS > 0) { /** @phpstan-ignore-line */
35 daniel-mar 221
    echo '<p>Here are '.AUTO_NEW_UUIDS.' UUIDs that were created just for you! (Reload the page to get more)</p>';
31 daniel-mar 222
 
223
    echo '<pre>';
70 daniel-mar 224
    for ($i=0; $i<AUTO_NEW_UUIDS; $i++) {
31 daniel-mar 225
        $uuid = gen_uuid_v1();
226
        echo '<a href="interprete_uuid.php?uuid='.$uuid.'">'.$uuid.'</a><br>';
227
    }
228
    echo '</pre>';
229
}
230
?>
231
 
30 daniel-mar 232
<form method="GET" action="interprete_uuid.php">
31 daniel-mar 233
    <input type="hidden" name="version" value="1">
234
    <input type="hidden" name="uuid" value="CREATE"> <input type="submit" value="Create and display another UUID">
30 daniel-mar 235
</form>
236
 
31 daniel-mar 237
<h2 id="gen_other_uuid">Generate other UUID types</h2>
30 daniel-mar 238
 
47 daniel-mar 239
<p><i>The following types of UUIDs are less common and/or require special knowledge. Please only use the following
30 daniel-mar 240
generators if you know what you are doing.</i></p>
241
 
53 daniel-mar 242
<h3 id="gen_uuid_ncs">NCS (variant 0) UUID</h3>
30 daniel-mar 243
 
53 daniel-mar 244
<p>The <abbr title="Network Computing System">NCS</abbr> UUIDs are a legacy format
245
initially designed by Apollo Computer that cannot be generated anymore, because the
30 daniel-mar 246
amount of available timestamp bits was exhausted on <strong>5 September 2015</strong>.
53 daniel-mar 247
As an example, here is the last possible NCS UUID (all bits of the timestamp are set to 1) for IP address 127.0.0.1:
34 daniel-mar 248
<a href="interprete_uuid.php?uuid=ffffffff-ffff-0000-027f-000001000000"><code>ffffffff-ffff-0000-027f-000001000000</code></a>.</p>
30 daniel-mar 249
 
35 daniel-mar 250
<script>
251
function show_uuidnce_info() {
252
        document.getElementById("uuidnce_info_button").style.display = "none";
253
        document.getElementById("uuidnce_info").style.display = "block";
254
}
255
</script>
62 daniel-mar 256
<p><a id="uuidnce_info_button" href="javascript:show_uuidnce_info()">Show format</a>
35 daniel-mar 257
<pre id="uuidnce_info" style="display:none">Variant 0 UUID:
37 daniel-mar 258
- 32 bit High <abbr title="Count of 4&#xB5;s intervals passed since 1 Jan 1980 00:00:00 GMT">Time</abbr>
259
- 16 bit Low <abbr title="Count of 4&#xB5;s intervals passed since 1 Jan 1980 00:00:00 GMT">Time</abbr>
35 daniel-mar 260
- 16 bit Reserved
261
-  1 bit Variant (fix 0b0)
37 daniel-mar 262
-  7 bit <abbr title="socket_$unspec (0x0)
263
socket_$unix (0x1)
264
socket_$internet (0x2)
265
socket_$implink (0x3)
266
socket_$pup (0x4)
267
socket_$chaos (0x5)
268
socket_$ns (0x6)
269
socket_$nbs (0x7)
270
socket_$ecma (0x8)
271
socket_$datakit (0x9)
272
socket_$ccitt (0xA)
273
socket_$sna (0xB)
274
socket_$unspec2 (0xC)
275
socket_$dds (0xD)">Family</abbr>
35 daniel-mar 276
- 56 bit Node</pre></p>
277
 
31 daniel-mar 278
<h3 id="gen_uuidv2">Generate DCE Security (version 2) UUID</h3>
30 daniel-mar 279
 
37 daniel-mar 280
<p><i>An UUIDv2 contains information about the creator (person, group, or organization), the generating system (MAC address), and time.
35 daniel-mar 281
The creator information replaced parts of the time bits, therefore the time resolution is very low.</i></p>
282
 
283
<script>
284
function show_uuidv2_info() {
285
        document.getElementById("uuidv2_info_button").style.display = "none";
286
        document.getElementById("uuidv2_info").style.display = "block";
287
}
288
</script>
62 daniel-mar 289
<p><a id="uuidv2_info_button" href="javascript:show_uuidv2_info()">Show format</a>
35 daniel-mar 290
<pre id="uuidv2_info" style="display:none">Variant 1, Version 2 UUID:
291
- 32 bit Local Domain Number
37 daniel-mar 292
- 16 bit Mid <abbr title="Count of 429.4967296s intervals passed since 15 Oct 1582 00:00:00 GMT">Time</abbr>
35 daniel-mar 293
-  4 bit Version (fix 0x2)
37 daniel-mar 294
- 12 bit High <abbr title="Count of 429.4967296s intervals passed since 15 Oct 1582 00:00:00 GMT">Time</abbr>
35 daniel-mar 295
-  2 bit Variant (fix 0b10)
296
-  6 bit Clock Sequence
37 daniel-mar 297
-  8 bit <abbr title="0 = person
298
1 = group
299
2 = org
300
3-255 = site-defined">Local Domain</abbr>
35 daniel-mar 301
- 48 bit MAC Address</pre></p>
302
 
30 daniel-mar 303
<form method="GET" action="interprete_uuid.php">
2 daniel-mar 304
        <input type="hidden" name="version" value="2">
35 daniel-mar 305
        <label>Domain (8&nbsp;bits):</label><select name="domain_choose" id="dce_domain_choice" onchange="javascript:dce_domain_choose();">
34 daniel-mar 306
                <option value="uid">Person (e.g. POSIX UID)</option>
307
                <option value="gid">Group (e.g. POSIX GID)</option>
308
                <option value="org">Organization</option>
2 daniel-mar 309
                <option value="site">Site-defined</option>
62 daniel-mar 310
        </select> = Address Family ID: <input type="number" min="0" max="255" name="dce_domain" value="" id="dce_domain" style="width:50px" pattern="[0-9]+"> (decimal notation)<br>
35 daniel-mar 311
        <label>Value (32&nbsp;bits):</label><input type="number" min="0" max="4294967295" name="dce_id" value="0" id="dce_id" style="width:200px" pattern="[0-9]+"> (decimal notation)<br>
37 daniel-mar 312
        <font color="red">Warning</font>: The timestamp has an accuracy of 7:10 minutes,
30 daniel-mar 313
        therefore the uniqueness of these UUIDs is not guaranteed!<br><br>
59 daniel-mar 314
        <input type="hidden" name="uuid" value="CREATE"> <input type="submit" value="Create UUIDv2">
2 daniel-mar 315
</form>
316
<script>
317
function dce_domain_choose() {
318
        var ns = document.getElementById('dce_domain_choice').value;
319
        if (ns == "uid") {
320
                document.getElementById('dce_domain').value = "0";
321
        }
322
        if (ns == "gid") {
323
                document.getElementById('dce_domain').value = "1";
324
        }
325
        if (ns == "org") {
326
                document.getElementById('dce_domain').value = "2";
327
        }
328
        if (ns == "site") {
329
                document.getElementById('dce_domain').value = "";
330
        }
331
}
332
dce_domain_choose();
333
</script>
334
 
61 daniel-mar 335
<h3 id="gen_uuidv35">Generate name-based (version 3 / 5 / <font color="green">New: 8</font>) UUID</h3>
2 daniel-mar 336
 
57 daniel-mar 337
<p><i>An UUIDv3 is made out of a MD5 hash and an UUIDv5 is made out of a SHA1 hash.
338
The revision of RFC4122 also contains an example for a custom UUIDv8 that
69 daniel-mar 339
allows SHA2, SHA3 and SHAKE hash algorithms.</i></p>
35 daniel-mar 340
 
341
<script>
342
function show_uuidv35_info() {
343
        document.getElementById("uuidv35_info_button").style.display = "none";
344
        document.getElementById("uuidv35_info").style.display = "block";
345
}
346
</script>
62 daniel-mar 347
<p><a id="uuidv35_info_button" href="javascript:show_uuidv35_info()">Show format</a>
58 daniel-mar 348
<pre id="uuidv35_info" style="display:none">Variant 1, Version 3/5/8 UUID:
35 daniel-mar 349
- 48 bit Hash High
58 daniel-mar 350
-  4 bit Version (fix 0x3, 0x5, or 0x8)
35 daniel-mar 351
- 12 bit Hash Mid
352
-  2 bit Variant (fix 0b10)
62 daniel-mar 353
- 62 bit Hash Low
35 daniel-mar 354
 
62 daniel-mar 355
 
69 daniel-mar 356
<u>As defined by <a href="https://datatracker.ietf.org/doc/rfc4122/">RFC4122</a>:</u>
357
UUIDv3(<i>NamespaceUuid</i>, <i>Data</i>) := <abbr title="Adds UUID variant 0b10 and version 3">ConvertRawBytesToUuid_v3</abbr>(MD5( Binary[<i>NameSpaceUuid</i>] || <i>Data</i> )).
358
UUIDv5(<i>NamespaceUuid</i>, <i>Data</i>) := <abbr title="Adds UUID variant 0b10 and version 5">ConvertRawBytesToUuid_v5</abbr>(SHA1( Binary[<i>NameSpaceUuid</i>] || <i>Data</i> )).
62 daniel-mar 359
NameSpaceUuid&lt;DNS&gt;          := "6ba7b810-9dad-11d1-80b4-00c04fd430c8".
360
NameSpaceUuid&lt;URL&gt;          := "6ba7b811-9dad-11d1-80b4-00c04fd430c8".
361
NameSpaceUuid&lt;OID&gt;          := "6ba7b812-9dad-11d1-80b4-00c04fd430c8".
362
NameSpaceUuid&lt;X500&gt;         := "6ba7b814-9dad-11d1-80b4-00c04fd430c8".
363
 
69 daniel-mar 364
<u>As defined by <a href="https://datatracker.ietf.org/doc/draft-ietf-uuidrev-rfc4122bis/">draft-ietf-uuidrev-rfc4122bis-11</a>:</u>
365
UUIDv8(<i>HashAlgo</i>, <i>NameSpaceUuid</i>, <i>Data</i>) := <abbr title="Adds UUID variant 0b10 and version 8">ConvertRawBytesToUuid_v8</abbr>(<i>HashAlgo</i>( Binary[HashSpaceUuid&lt;<i>HashAlgo</i>&gt;] || Binary[<i>NameSpaceUuid</i>] || <i>Data</i> )).
66 daniel-mar 366
<?php
62 daniel-mar 367
 
66 daniel-mar 368
$tmp = [];
69 daniel-mar 369
foreach (get_uuidv8_hash_space_ids() as list($algo,$space,$friendlyName,$author,$available)) {
370
        $line = str_pad('HashSpaceUuid&lt;'.htmlentities($friendlyName).'&gt;', 34, ' ', STR_PAD_RIGHT);
371
        $line .= ':= "'.$space.'".';
372
        if (!$available) $line .= " (Currently not available on this system)";
373
        $line .= "\n";
374
        $tmp[$friendlyName] = $line;
66 daniel-mar 375
}
376
ksort($tmp);
377
foreach ($tmp as $line) {
378
        echo $line;
379
}
380
 
381
?>
382
 
69 daniel-mar 383
<u>Custom implementation ("Raw Hash"):</u>
384
UUIDv8(<i>HashAlgo</i>, <i>NameSpaceUuid</i>, <i>Data</i>) := <abbr title="Adds UUID variant 0b10 and version 8">ConvertRawBytesToUuid_v8</abbr>(<i>HashAlgo</i>( Binary[<i>NameSpaceUuid</i>] || <i>Data</i> )).
67 daniel-mar 385
 
62 daniel-mar 386
</pre></p>
387
 
35 daniel-mar 388
<style>
389
label {
390
        width:120px;
391
        text-align:left;
392
        margin-right: 20px;
393
        display:inline-block;
394
}
395
</style>
396
 
2 daniel-mar 397
<form method="GET" action="interprete_uuid.php">
59 daniel-mar 398
        <label>Hash algorithm:</label><select name="version" id="nb_version" onchange="javascript:nb_version_choose();">
399
                <?php
67 daniel-mar 400
 
401
                echo "\t\t<option disabled>--- UUIDv3 (RFC 4122) ---</option>\n";
402
                echo "\t\t<option value=\"3\">MD5</option>\n";
403
                echo "\t\t<option disabled>--- UUIDv5 (RFC 4122) ---</option>\n";
404
                echo "\t\t<option value=\"5\" selected>SHA1</option>\n";
405
 
406
                $categories = [];
62 daniel-mar 407
                foreach (get_uuidv8_hash_space_ids() as list($algo,$space,$friendlyName,$author,$available)) {
67 daniel-mar 408
                        if (!in_array($author, $categories)) $categories[] = $author;
409
                }
410
                sort($categories);
411
 
412
                foreach ($categories as $category) {
413
                        echo "\t\t<option disabled>--- UUIDv8 (defined by ".htmlentities($category).") ---</option>\n";
414
                        $tmp = [];
415
                        foreach (get_uuidv8_hash_space_ids() as list($algo,$space,$friendlyName,$author,$available)) {
416
                                if ($author != $category) continue;
417
                                if ($available) {
418
                                        $tmp[$friendlyName] = '<option value="8_namebased_'.$space.'">'.htmlentities($friendlyName).'</option>';
419
                                }
62 daniel-mar 420
                        }
67 daniel-mar 421
                        ksort($tmp);
422
                        foreach ($tmp as $html) {
423
                                echo "\t\t$html\n";
424
                        }
59 daniel-mar 425
                }
69 daniel-mar 426
 
427
                echo "\t\t<option disabled>--- UUIDv8 (Raw Hash) ---</option>\n";
428
                $tmp = [];
429
                $algos = hash_algos();
430
                $algos[] = 'shake128';
431
                $algos[] = 'shake256';
432
                foreach ($algos as $algo) {
433
                        if ($algo == 'md5') continue; // use UUIDv3 instead
434
                        if ($algo == 'sha1') continue; // use UUIDv5 instead
435
                        $friendlyName = strtoupper($algo);
436
 
437
                        if ($algo == 'shake128') $bits = 999;
438
                        else if ($algo == 'shake256') $bits = 999;
439
                        else $bits = strlen(hash($algo, '', true)) * 8;
440
                        if ($bits < 128) $friendlyName .= " (Small hash size! $bits bits)";
441
 
442
                        $space = $algo;
443
                        $tmp[$friendlyName] = '<option value="8_namebased_'.$space.'">'.htmlentities($friendlyName).'</option>';
444
                }
445
                natsort($tmp);
446
                foreach ($tmp as $html) {
447
                        echo "\t\t$html\n";
448
                }
449
 
59 daniel-mar 450
                ?>
451
        </select><font size="-1"><span id="nb_hash_info"></span></font><br>
35 daniel-mar 452
        <label>Namespace:</label><select name="namespace_choose" id="nb_nsc" onchange="javascript:nb_ns_choose();">
2 daniel-mar 453
                <option value="dns">DNS</option>
454
                <option value="url">URL</option>
455
                <option value="oid">OID</option>
456
                <option value="x500">X.500 DN</option>
35 daniel-mar 457
                <!-- <option value="oidplus_ns">OIDplus ns only</option> -->
458
                <!-- <option value="oidplus_ns_val">OIDplus ns+val</option> -->
28 daniel-mar 459
                <!-- <option value="oidplus_pubkey">OIDplus pubkey</option> -->
2 daniel-mar 460
                <option value="other">Other</option>
59 daniel-mar 461
        </select> = Namespace UUID: <input type="text" name="nb_ns" value="" id="nb_ns" style="width:270px" onchange="javascript:nb_ns_textchange();" pattern="[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}"><br>
35 daniel-mar 462
        <label>Value:</label><input type="text" name="nb_val" value="" id="nb_val" style="width:300px"><br>
30 daniel-mar 463
        <font color="red">Warning</font>: These UUIDs do not contain a timestamp,
464
        therefore the uniqueness of these UUIDs is not guaranteed!<br><br>
59 daniel-mar 465
        <input type="hidden" name="uuid" value="CREATE"> <input type="submit" id="nb_create_btn" value="Create UUID">
2 daniel-mar 466
</form>
467
<script>
59 daniel-mar 468
function nb_version_choose() {
469
        var ver = document.getElementById('nb_version').value;
470
        document.getElementById('nb_create_btn').value = 'Create UUIDv' + ver.substr(0,1);
471
        var x = ver.split('_namebased_');
69 daniel-mar 472
        if ((x.length == 2) && (x[1].length == 36)) {
61 daniel-mar 473
                document.getElementById('nb_hash_info').innerHTML = ' (UUIDv8 Hash Space ID: ' + x[1] + ')';
59 daniel-mar 474
        } else {
475
                document.getElementById('nb_hash_info').innerHTML = '';
476
        }
477
 
478
}
35 daniel-mar 479
function nb_ns_textchange() {
480
        var ns = document.getElementById('nb_ns').value.toLowerCase();
481
        if (ns == "6ba7b810-9dad-11d1-80b4-00c04fd430c8") {
482
                if (document.getElementById('nb_nsc').value != "dns") {
483
                        document.getElementById('nb_nsc').value = "dns";
57 daniel-mar 484
                        document.getElementById('nb_val').value = "www.example.com";
35 daniel-mar 485
                }
486
        }
487
        else if (ns == "6ba7b811-9dad-11d1-80b4-00c04fd430c8") {
488
                if (document.getElementById('nb_nsc').value != "url") {
489
                        document.getElementById('nb_nsc').value = "url";
57 daniel-mar 490
                        document.getElementById('nb_val').value = "http://www.example.com/";
35 daniel-mar 491
                }
492
        }
493
        else if (ns == "6ba7b812-9dad-11d1-80b4-00c04fd430c8") {
494
                if (document.getElementById('nb_nsc').value != "oid") {
495
                        document.getElementById('nb_nsc').value = "oid";
496
                        document.getElementById('nb_val').value = "2.999";
497
                }
498
        }
499
        else if (ns == "6ba7b814-9dad-11d1-80b4-00c04fd430c8") {
500
                if (document.getElementById('nb_nsc').value != "x500") {
501
                        document.getElementById('nb_nsc').value = "x500";
502
                        document.getElementById('nb_val').value = "UID=jsmith,DC=example,DC=net";
503
                }
504
        }
505
        else {
506
                if (document.getElementById('nb_nsc').value != "other") {
507
                        document.getElementById('nb_nsc').value = "other";
508
                        document.getElementById('nb_val').value = "";
509
                }
510
        }
511
}
2 daniel-mar 512
function nb_ns_choose() {
513
        var ns = document.getElementById('nb_nsc').value;
514
        if (ns == "dns") {
515
                document.getElementById('nb_ns').value = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
57 daniel-mar 516
                document.getElementById('nb_val').value = "www.example.com";
2 daniel-mar 517
        }
35 daniel-mar 518
        else if (ns == "url") {
2 daniel-mar 519
                document.getElementById('nb_ns').value = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
57 daniel-mar 520
                document.getElementById('nb_val').value = "http://www.example.com/";
2 daniel-mar 521
        }
35 daniel-mar 522
        else if (ns == "oid") {
2 daniel-mar 523
                document.getElementById('nb_ns').value = "6ba7b812-9dad-11d1-80b4-00c04fd430c8";
524
                document.getElementById('nb_val').value = "2.999";
525
        }
35 daniel-mar 526
        else if (ns == "x500") {
2 daniel-mar 527
                document.getElementById('nb_ns').value = "6ba7b814-9dad-11d1-80b4-00c04fd430c8";
528
                document.getElementById('nb_val').value = "UID=jsmith,DC=example,DC=net";
529
        }
35 daniel-mar 530
        /*
531
        else if (ns == "oidplus_ns") {
2 daniel-mar 532
                document.getElementById('nb_ns').value = "0943e3ce-4b79-11e5-b742-78e3b5fc7f22";
533
                document.getElementById('nb_val').value = "ipv4";
534
        }
35 daniel-mar 535
        else if (ns == "oidplus_ns_val") {
2 daniel-mar 536
                document.getElementById('nb_ns').value = "ad1654e6-7e15-11e4-9ef6-78e3b5fc7f22";
537
                document.getElementById('nb_val').value = "ipv4:8.8.8.8";
538
        }
35 daniel-mar 539
        else if (ns == "oidplus_ns_pubkey") {
28 daniel-mar 540
                document.getElementById('nb_ns').value = "fd16965c-8bab-11ed-8744-3c4a92df8582";
31 daniel-mar 541
                document.getElementById('nb_val').value = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqg/PnsC1WX3C1/mUSLuk0DIaDHtEsxBnG0auYJRJ1hBtbUUvItbK0odlKrX2SFo1MJJpu/SSxTzAgqkKZsZe3cCFkgA1svfuH9i94oGLjJ4n0kRJEGlanCmGndJBfIqGDJaQE2BJ8tLxeBrpkd9l0KvJsjhRmqJAb9KYK3KYFsWvT+wyjD3UJ1eHcgLbF/Qb3cwMU/u7Fs7ZpsNMW4phDPlsYsk9XHFpJ1/UCj6G53mYRfOC/ouDdGShlbVLB15s0V95QpnU/7lL8mJ2lE+sTZekGNBA4XbJv2gs21cR4E8zc/z+NyZS7117DYZoJqrAN8sKz6xGoKgQF6wueCK5qQIDAQAB";
28 daniel-mar 542
        }
543
        */
35 daniel-mar 544
        else if (ns == "other") {
2 daniel-mar 545
                document.getElementById('nb_ns').value = "";
546
                document.getElementById('nb_val').value = "";
547
        }
548
}
59 daniel-mar 549
nb_version_choose();
2 daniel-mar 550
nb_ns_choose();
551
</script>
552
 
61 daniel-mar 553
<h3 id="gen_uuidv8"><font color="green">New:</font> Generate Custom (version 8) UUID</h3>
34 daniel-mar 554
 
37 daniel-mar 555
<p><i>UUIDv8 is made of 122 bits application-specific / custom data. The other 6 bits are used to specify the variant and version of the UUID, to make it RFC-compatible.</i></p>
35 daniel-mar 556
 
557
<script>
558
function show_uuidv8_info() {
559
        document.getElementById("uuidv8_info_button").style.display = "none";
560
        document.getElementById("uuidv8_info").style.display = "block";
561
}
65 daniel-mar 562
function uuidv8_changedec(block, len) {
563
        var x = document.getElementById("v8_block"+block+"_dec").value;
564
        if (x.trim() == "") x = 0;
565
        x = parseInt(x);
566
        if (isNaN(x)) {
567
                x = "???";
568
        } else {
569
                x = x.toString(16).padStart(len, '0');
570
                if ((len > 0) && (x.length > len)) x = "Overflow";
571
        }
572
        document.getElementById("v8_block"+block+"_hex").value = x;
573
}
574
function uuidv8_changehex(block, len) {
575
        var x = document.getElementById("v8_block"+block+"_hex").value;
576
        if (x.trim() == "") x = 0;
577
        x = parseInt(x, 16);
578
        if (isNaN(x)) {
579
                x = "???";
580
        } else {
581
                x = x.toString().padStart(len, '0');
582
                if ((len > 0) && (x.length > len)) x = "Overflow"; // Note: For block 3/4, the overflow actually happens at 12/14 bits, not at 4 nibbles (16 bits)
583
        }
584
        document.getElementById("v8_block"+block+"_dec").value = x;
585
}
35 daniel-mar 586
</script>
62 daniel-mar 587
<p><a id="uuidv8_info_button" href="javascript:show_uuidv8_info()">Show format</a>
35 daniel-mar 588
<pre id="uuidv8_info" style="display:none">Variant 1, Version 8 UUID:
63 daniel-mar 589
- 48 bit Custom data [Block 1+2]
35 daniel-mar 590
-  4 bit Version (fix 0x8)
63 daniel-mar 591
- 12 bit Custom data [Block 3]
35 daniel-mar 592
-  2 bit Variant (fix 0b10)
63 daniel-mar 593
- 62 bit Custom data [Block 4+5]</pre></p>
35 daniel-mar 594
 
34 daniel-mar 595
<form method="GET" action="interprete_uuid.php">
596
        <input type="hidden" name="version" value="8">
65 daniel-mar 597
 
598
        <label>Block&nbsp;1 (32&nbsp;bits):</label>0x<input type="text" name="block1" value="00000000" maxlength="8" id="v8_block1_hex" onkeyup="uuidv8_changehex(1, 0)" style="width:150px" pattern="[0-9a-fA-F]+"> = Decimal
599
        <input type="number" name="block1dec" value="0" min="0" maxlength="20" id="v8_block1_dec" onmouseup="uuidv8_changedec(1, 8)" onkeyup="uuidv8_changedec(1, 8)" style="width:150px"><br>
600
 
601
        <label>Block&nbsp;2 (16&nbsp;bits):</label>0x<input type="text" name="block2" value="0000" maxlength="4" id="v8_block2_hex" onkeyup="uuidv8_changehex(2, 0)" style="width:150px" pattern="[0-9a-fA-F]+"> = Decimal
602
        <input type="number" name="block2dec" value="0" min="0" maxlength="20" id="v8_block2_dec" onmouseup="uuidv8_changedec(2, 4)" onkeyup="uuidv8_changedec(2, 4)" style="width:150px"><br>
603
 
604
        <label>Block&nbsp;3 (<abbr title="The high 4 bits are occupied by the UUID version = 8">12&nbsp;bits</abbr>):</label>0x<input type="text" name="block3" value="0000" maxlength="4" id="v8_block3_hex" onkeyup="uuidv8_changehex(3, 0)" style="width:150px" pattern="[0-9a-fA-F]+"> = Decimal
605
        <input type="number" name="block3dec" value="0" min="0" maxlength="20" id="v8_block3_dec" onmouseup="uuidv8_changedec(3, 4)" onkeyup="uuidv8_changedec(3, 4)" style="width:150px"><br>
606
 
607
        <label>Block&nbsp;4 (<abbr title="The high 2 bits are occupied by the UUID variant = 0b10">14&nbsp;bits</abbr>):</label>0x<input type="text" name="block4" value="0000" maxlength="4" id="v8_block4_hex" onkeyup="uuidv8_changehex(4, 0)" style="width:150px" pattern="[0-9a-fA-F]+"> = Decimal
608
        <input type="number" name="block4dec" value="0" min="0" maxlength="20" id="v8_block4_dec" onmouseup="uuidv8_changedec(4, 4)" onkeyup="uuidv8_changedec(4, 4)" style="width:150px"><br>
609
 
610
        <label>Block&nbsp;5 (48&nbsp;bits):</label>0x<input type="text" name="block5" value="000000000000" maxlength="12" id="v8_block5_hex" onkeyup="uuidv8_changehex(5, 0)" style="width:150px" pattern="[0-9a-fA-F]+"> = Decimal
611
        <input type="number" name="block5dec" value="0" min="0" maxlength="20" id="v8_block5_dec" onmouseup="uuidv8_changedec(5, 12)" onkeyup="uuidv8_changedec(5, 12)" style="width:150px"><br>
612
 
34 daniel-mar 613
        <font color="red">Warning</font>: These UUIDs do not contain a timestamp,
614
        therefore the uniqueness of these UUIDs is not guaranteed!<br><br>
59 daniel-mar 615
        <input type="hidden" name="uuid" value="CREATE"> <input type="submit" value="Create UUIDv8">
34 daniel-mar 616
</form>
617
 
31 daniel-mar 618
<h2 id="interpret_uuid">Interpret a UUID</h2>
2 daniel-mar 619
 
30 daniel-mar 620
<p>You can enter a UUID in the following notations:</p>
2 daniel-mar 621
 
622
<ul>
623
        <li>Classic notation (case insensitive, curly braces optional): <code>9e83839a-5967-11e4-8c1c-78e3b5fc7f22</code></li>
624
        <li>As OID: <code>2.25.210700883446948645633376489934419689250</code></li>
625
</ul>
626
 
627
<p>The script will output:</p>
628
 
629
<ul>
630
        <li>Notation as UUID and OID</li>
35 daniel-mar 631
        <li>Version, variant, and additional data (date and time, clock sequence, node id, etc.)</li>
2 daniel-mar 632
</ul>
633
 
30 daniel-mar 634
<p>Please enter a UUID or UUID OID:</p>
2 daniel-mar 635
 
636
<form method="GET" action="interprete_uuid.php">
32 daniel-mar 637
        <input type="text" name="uuid" value="" style="width:300px"> <input type="submit" value="Interprete">
2 daniel-mar 638
</form>
639
 
31 daniel-mar 640
<h2 id="interpret_mac">Interpret a MAC address (<abbr title="Media Access Control">MAC</abbr> /
26 daniel-mar 641
<abbr title="Extended Unique Identifier">EUI</abbr> /
642
<abbr title="Extended Local Identifier">ELI</abbr> /
643
<abbr title="Standard Assigned Identifier">SAI</abbr> /
644
<abbr title="Administratively Assigned Identifier">AAI</abbr>)</h2>
2 daniel-mar 645
 
30 daniel-mar 646
<p>You can enter a UUID in the following notations:</p>
2 daniel-mar 647
 
648
<ul>
649
        <li><code>AA-BB-CC-DD-EE-FF</code></li>
650
        <li><code>AA:BB:CC:DD:EE:FF</code></li>
651
        <li><code>AABBCC.DDEEFF</code> (case insensitive)</li>
16 daniel-mar 652
        <li><code>AA-BB-CC-DD-EE-FF-11-22</code> (EUI-64)</li>
653
        <li><code>AA:BB:CC:DD:EE:FF-11-22</code> (EUI-64)</li>
654
        <li><code>fe80::1322:33ff:fe44:5566</code> (IPv6 Link Local / EUI-64)</li>
2 daniel-mar 655
</ul>
656
 
657
<p>The script will output:</p>
658
 
659
<ul>
660
        <li>Information about the I/G and U/L flags.</li>
661
        <li>Information about the entry in the IEEE registry, if available.</li>
662
        <li>Information about the registrant, if available.</li>
663
</ul>
664
 
29 daniel-mar 665
<p>Please enter a MAC (EUI, ELI, SAI, AAI), or IPv6-Link-Local address:</p>
2 daniel-mar 666
 
667
<form method="GET" action="interprete_mac.php">
32 daniel-mar 668
        <input type="text" name="mac" value="" style="width:250px"> <input type="submit" value="Interprete">
2 daniel-mar 669
</form>
670
 
62 daniel-mar 671
<h3 id="gen_aai">Generate an <abbr title="Administratively Assigned Identifier">AAI</abbr></h3>
41 daniel-mar 672
 
673
<p><i>An Administratively Assigned Identifier (AAI) is a MAC address which can be locally defined
674
by applications or an administrator. Unlike the EUI, an AAI is NOT worldwide unique.</i></p>
675
 
676
<form method="GET" action="interprete_mac.php">
677
    <input type="hidden" name="aai_gen" value="1">
678
    <input type="hidden" name="aai_gen_bits" value="48">
679
    <input type="hidden" name="aai_gen_multicast" value="0">
680
    <input type="hidden" name="uuid" value="CREATE"> <input type="submit" value="Generate AAI-48">
681
</form>
682
 
683
<br>
684
 
685
<form method="GET" action="interprete_mac.php">
686
    <input type="hidden" name="aai_gen" value="1">
687
    <input type="hidden" name="aai_gen_bits" value="64">
688
    <input type="hidden" name="aai_gen_multicast" value="0">
689
    <input type="hidden" name="uuid" value="CREATE"> <input type="submit" value="Generate AAI-64">
690
</form>
691
 
692
<p>The following options are rather unusual, but are implemented for the sake of completeness:</p>
693
 
694
<form method="GET" action="interprete_mac.php">
695
    <input type="hidden" name="aai_gen" value="1">
696
    <input type="hidden" name="aai_gen_bits" value="48">
697
    <input type="hidden" name="aai_gen_multicast" value="1">
698
    <input type="hidden" name="uuid" value="CREATE"> <input type="submit" value="Generate Multicast AAI-48">
699
</form>
700
 
701
<br>
702
 
703
<form method="GET" action="interprete_mac.php">
704
    <input type="hidden" name="aai_gen" value="1">
705
    <input type="hidden" name="aai_gen_bits" value="64">
706
    <input type="hidden" name="aai_gen_multicast" value="1">
707
    <input type="hidden" name="uuid" value="CREATE"> <input type="submit" value="Generate Multicast AAI-64">
708
</form>
709
 
710
 
22 daniel-mar 711
<br><br><br>
712
 
2 daniel-mar 713
</body>
714
 
715
</html>