Rev 74 | Rev 76 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 74 | Rev 75 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * UUID & MAC Utils |
4 | * UUID & MAC Utils |
5 | * Copyright 2017 - 2023 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2017 - 2023 Daniel Marschall, ViaThinkSoft |
6 | * Version 2023-10-05 |
6 | * Version 2023-10-06 |
7 | * |
7 | * |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
9 | * you may not use this file except in compliance with 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 |
10 | * You may obtain a copy of the License at |
11 | * |
11 | * |
Line 40... | Line 40... | ||
40 | 40 | ||
41 | <h2>Overview</h2> |
41 | <h2>Overview</h2> |
42 | 42 | ||
43 | <ul> |
43 | <ul> |
44 | <li><a href="#gen_uuid">Generate random and/or time-based UUIDs</a><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> |
45 | <li><a href="#gen_uuidv7"><font color="green">New:</font> Generate Unix Epoch time-based (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> |
46 | <li><a href="#gen_uuidv6"><font color="green">New:</font> Generate reordered Gregorian time-based (version 6) UUID</a></li> |
47 | <li><a href="#gen_uuidv4">Generate random (version 4) 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> |
48 | <li><a href="#gen_uuidv1">Generate Gregorian time-based (version 1) UUID</a></li> |
49 | </ul></li> |
49 | </ul></li> |
50 | <li><a href="#gen_other_uuid">Generate other UUID types</a><ul> |
50 | <li><a href="#gen_other_uuid">Generate other UUID types</a><ul> |
51 | <li><a href="#gen_uuid_ncs">NCS (variant 0) UUID</a></li> |
51 | <li><a href="#gen_uuid_ncs">NCS (variant 0) UUID</a></li> |
52 | <li><a href="#gen_uuidv2">Generate DCE Security (version 2) UUID</a></li> |
52 | <li><a href="#gen_uuidv2">Generate DCE Security (version 2) UUID</a></li> |
53 | <li><a href="#gen_uuidv35">Generate name-based (version 3 / 5 / <font color="green">New: 8</font>) UUID</a></li> |
53 | <li><a href="#gen_uuidv35">Generate name-based (version 3 / 5 / <font color="green">New: 8</font>) UUID</a></li> |
Line 59... | Line 59... | ||
59 | </ul></li> |
59 | </ul></li> |
60 | </ul> |
60 | </ul> |
61 | 61 | ||
62 | <h2 id="gen_uuid">Generate random and/or time-based UUIDs</h2> |
62 | <h2 id="gen_uuid">Generate random and/or time-based UUIDs</h2> |
63 | 63 | ||
64 | <h3 id="gen_uuidv7"><font color="green">New:</font> Generate Unix Epoch Time (version 7) UUID ⭐</h3> |
64 | <h3 id="gen_uuidv7"><font color="green">New:</font> Generate Unix Epoch time-based (version 7) UUID ⭐</h3> |
65 | 65 | ||
66 | <p><i>A UUIDv7 measures time in the Unix Epoch with an accuracy |
66 | <p><i>A UUIDv7 measures time in the Unix Epoch with an accuracy |
67 | between 1ms and 245ns, depending on how many bits are spent for the timestamp (48-60 bits). |
67 | between 1ms and 245ns, depending on how many bits are spent for the timestamp (48-60 bits). |
68 | The rest of the UUID (62-74 bits) is filled with random data. |
68 | The rest of the UUID (62-74 bits) is filled with random data. |
69 | The timestamp is at the front of the UUID, therefore the UUIDs are monotonically increasing, |
69 | The timestamp is at the front of the UUID, therefore the UUIDs are monotonically increasing, |
70 | which is good for ordering them and using them for database indexes. |
70 | which is good for using them in database indexes. |
71 | Since this UUID version does not contain a MAC address, it is |
71 | Since this UUID version does not contain a MAC address, it is also |
72 | recommended due to the improved privacy.</i></p> |
72 | recommended due to the improved privacy.</i></p> |
73 | 73 | ||
74 | <script> |
74 | <script> |
75 | function show_uuidv7_info() { |
75 | function show_uuidv7_info() { |
76 | document.getElementById("uuidv7_info_button").style.display = "none"; |
76 | document.getElementById("uuidv7_info_button").style.display = "none"; |
Line 123... | Line 123... | ||
123 | <form method="GET" action="interprete_uuid.php"> |
123 | <form method="GET" action="interprete_uuid.php"> |
124 | <input type="hidden" name="version" value="7"> |
124 | <input type="hidden" name="version" value="7"> |
125 | <input type="hidden" name="uuid" value="CREATE"> <input type="submit" value="Create and display another UUID"> |
125 | <input type="hidden" name="uuid" value="CREATE"> <input type="submit" value="Create and display another UUID"> |
126 | </form> |
126 | </form> |
127 | 127 | ||
128 | <h3 id="gen_uuidv6"><font color="green">New:</font> Generate reordered time-based (version 6) UUID ⏰</h3> |
128 | <h3 id="gen_uuidv6"><font color="green">New:</font> Generate reordered Gregorian time-based (version 6) UUID ⏰</h3> |
129 | 129 | ||
130 | <p><i>Like UUIDv1, this kind of UUID is made of the MAC address of the generating computer, |
130 | <p><i>Like UUIDv1, this kind of UUID is made of the MAC address of the generating computer, |
131 | the time, and a clock sequence. However, the components in UUIDv6 are reordered (time is at the beginning), |
131 | the time, and a clock sequence. However, the components in UUIDv6 are reordered (time is at the beginning), |
132 | so that UUIDs are monotonically increasing, |
- | |
133 | which is good for ordering them and using them for database indexes..</i></p> |
132 | so that UUIDs are monotonically increasing, which is good for using them in database indexes.</i></p> |
134 | 133 | ||
135 | <script> |
134 | <script> |
136 | function show_uuidv6_info() { |
135 | function show_uuidv6_info() { |
137 | document.getElementById("uuidv6_info_button").style.display = "none"; |
136 | document.getElementById("uuidv6_info_button").style.display = "none"; |
138 | document.getElementById("uuidv6_info").style.display = "block"; |
137 | document.getElementById("uuidv6_info").style.display = "block"; |
Line 200... | Line 199... | ||
200 | <form method="GET" action="interprete_uuid.php"> |
199 | <form method="GET" action="interprete_uuid.php"> |
201 | <input type="hidden" name="version" value="4"> |
200 | <input type="hidden" name="version" value="4"> |
202 | <input type="hidden" name="uuid" value="CREATE"> <input type="submit" value="Create and display another UUID"> |
201 | <input type="hidden" name="uuid" value="CREATE"> <input type="submit" value="Create and display another UUID"> |
203 | </form> |
202 | </form> |
204 | 203 | ||
205 | <h3 id="gen_uuidv1">Generate time-based (version 1) UUID ⏰</h3> |
204 | <h3 id="gen_uuidv1">Generate Gregorian time-based (version 1) UUID ⏰</h3> |
206 | 205 | ||
207 | <p><i>A UUIDv1 is made of the MAC address of the generating computer, |
206 | <p><i>A UUIDv1 is made of the MAC address of the generating computer, |
208 | the time, and a clock sequence.</i></p> |
207 | the time, and a clock sequence.</i></p> |
209 | 208 | ||
210 | <script> |
209 | <script> |
Line 359... | Line 358... | ||
359 | - 12 bit Hash Mid |
358 | - 12 bit Hash Mid |
360 | - 2 bit Variant (fix 0b10) |
359 | - 2 bit Variant (fix 0b10) |
361 | - 62 bit Hash Low |
360 | - 62 bit Hash Low |
362 | 361 | ||
363 | 362 | ||
364 | <u>As defined by <a href="https://datatracker.ietf.org/doc/rfc4122/">RFC4122</a>:</u> |
- | |
365 | 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> )). |
- | |
366 | 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> )). |
- | |
367 | NameSpaceUuid<DNS> := "6ba7b810-9dad-11d1-80b4-00c04fd430c8". |
- | |
368 | NameSpaceUuid<URL> := "6ba7b811-9dad-11d1-80b4-00c04fd430c8". |
- | |
369 | NameSpaceUuid<OID> := "6ba7b812-9dad-11d1-80b4-00c04fd430c8". |
- | |
370 | NameSpaceUuid<X500> := "6ba7b814-9dad-11d1-80b4-00c04fd430c8". |
- | |
371 | - | ||
372 | <u>As defined by <a href="https://datatracker.ietf.org/doc/draft-ietf-uuidrev-rfc4122bis/11/">draft-ietf-uuidrev-rfc4122bis-11</a>:</u> |
- | |
373 | 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<<i>HashAlgo</i>>] || Binary[<i>NameSpaceUuid</i>] || <i>Data</i> )). |
363 | <u>As shown in <a href="https://datatracker.ietf.org/doc/draft-ietf-uuidrev-rfc4122bis/">draft-ietf-uuidrev-rfc4122bis-12</a> Appendix C.2:</u> |
374 | <?php |
- | |
375 | - | ||
376 | $tmp = []; |
- | |
377 | foreach (get_uuidv8_hash_space_ids() as list($algo,$space,$friendlyName,$author,$available)) { |
- | |
378 | $line = str_pad('HashSpaceUuid<'.htmlentities($friendlyName).'>', 34, ' ', STR_PAD_RIGHT); |
- | |
379 | $line .= ':= "'.$space.'".'; |
- | |
380 | if (!$available) $line .= " (Currently not available on this system)"; |
- | |
381 | $line .= "\n"; |
- | |
382 | $tmp[$friendlyName] = $line; |
- | |
383 | } |
- | |
384 | ksort($tmp); |
- | |
385 | foreach ($tmp as $line) { |
- | |
386 | echo $line; |
- | |
387 | } |
- | |
388 | - | ||
389 | ?> |
- | |
390 | - | ||
391 | <u>As defined by <a href="https://datatracker.ietf.org/doc/draft-ietf-uuidrev-rfc4122bis/">draft-ietf-uuidrev-rfc4122bis-12</a>:</u> |
- | |
392 | 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> )). |
364 | 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> )). |
393 | 365 | ||
394 | </pre></p> |
366 | </pre></p> |
395 | 367 | ||
396 | <style> |
368 | <style> |
Line 404... | Line 376... | ||
404 | 376 | ||
405 | <form method="GET" action="interprete_uuid.php"> |
377 | <form method="GET" action="interprete_uuid.php"> |
406 | <label>Hash algorithm:</label><select name="version" id="nb_version" onchange="javascript:nb_version_choose();"> |
378 | <label>Hash algorithm:</label><select name="version" id="nb_version" onchange="javascript:nb_version_choose();"> |
407 | <?php |
379 | <?php |
408 | 380 | ||
409 | echo "\t\t<option disabled>--- UUIDv3 (RFC 4122) ---</option>\n"; |
381 | echo "\t\t<option disabled>--- UUIDv3 (defined in RFC 4122) ---</option>\n"; |
410 | echo "\t\t<option value=\"3\">MD5</option>\n"; |
382 | echo "\t\t<option value=\"3\">MD5</option>\n"; |
411 | echo "\t\t<option disabled>--- UUIDv5 (RFC 4122) ---</option>\n"; |
383 | echo "\t\t<option disabled>--- UUIDv5 (defined in RFC 4122) ---</option>\n"; |
412 | echo "\t\t<option value=\"5\" selected>SHA1</option>\n"; |
384 | echo "\t\t<option value=\"5\" selected>SHA1</option>\n"; |
413 | - | ||
414 | $categories = []; |
- | |
415 | foreach (get_uuidv8_hash_space_ids() as list($algo,$space,$friendlyName,$author,$available)) { |
- | |
416 | if (!in_array($author, $categories)) $categories[] = $author; |
- | |
417 | } |
- | |
418 | sort($categories); |
- | |
419 | - | ||
420 | foreach ($categories as $category) { |
- | |
421 | echo "\t\t<option disabled>--- UUIDv8 (defined by ".htmlentities($category).") ---</option>\n"; |
- | |
422 | $tmp = []; |
- | |
423 | foreach (get_uuidv8_hash_space_ids() as list($algo,$space,$friendlyName,$author,$available)) { |
- | |
424 | if ($author != $category) continue; |
- | |
425 | if ($available) { |
- | |
426 | $tmp[$friendlyName] = '<option value="8_namebased_'.$space.'">'.htmlentities($friendlyName).'</option>'; |
- | |
427 | } |
- | |
428 | } |
- | |
429 | ksort($tmp); |
- | |
430 | foreach ($tmp as $html) { |
- | |
431 | echo "\t\t$html\n"; |
- | |
432 | } |
- | |
433 | } |
- | |
434 | - | ||
435 | echo "\t\t<option disabled>--- UUIDv8 (defined by Internet Draft 12, Appendix C.2) ---</option>\n"; |
385 | echo "\t\t<option disabled>--- UUIDv8 (shown in Internet Draft 12, Appendix C.2) ---</option>\n"; |
436 | $tmp = []; |
386 | $tmp = []; |
437 | $algos = hash_algos(); |
387 | $algos = hash_algos(); |
438 | $algos[] = 'shake128'; |
388 | $algos[] = 'shake128'; |
439 | $algos[] = 'shake256'; |
389 | $algos[] = 'shake256'; |
440 | foreach ($algos as $algo) { |
390 | foreach ($algos as $algo) { |
Line 443... | Line 393... | ||
443 | $friendlyName = strtoupper($algo); |
393 | $friendlyName = strtoupper($algo); |
444 | 394 | ||
445 | if ($algo == 'shake128') $bits = 999; |
395 | if ($algo == 'shake128') $bits = 999; |
446 | else if ($algo == 'shake256') $bits = 999; |
396 | else if ($algo == 'shake256') $bits = 999; |
447 | else $bits = strlen(hash($algo, '', true)) * 8; |
397 | else $bits = strlen(hash($algo, '', true)) * 8; |
448 | if ($bits < 128) $friendlyName .= " (Small hash size! $bits bits)"; // <-- this is not described in Appendix B.2 |
398 | if ($bits < 128) $friendlyName .= " (Small hash size! $bits bits)"; // <-- this is not described in Appendix C.2 |
449 | 399 | ||
450 | $space = $algo; |
400 | $space = $algo; |
451 | $tmp[$friendlyName] = '<option value="8_namebased_'.$space.'">'.htmlentities($friendlyName).'</option>'; |
401 | $tmp[$friendlyName] = '<option value="8_namebased_'.$space.'">'.htmlentities($friendlyName).'</option>'; |
452 | } |
402 | } |
453 | natsort($tmp); |
403 | natsort($tmp); |
454 | foreach ($tmp as $html) { |
404 | foreach ($tmp as $html) { |
455 | echo "\t\t$html\n"; |
405 | echo "\t\t$html\n"; |
456 | } |
406 | } |
457 | 407 | ||
458 | ?> |
408 | ?> |
459 | </select><font size="-1"><span id="nb_hash_info"></span></font><br> |
409 | </select><br> |
460 | <label>Namespace:</label><select name="namespace_choose" id="nb_nsc" onchange="javascript:nb_ns_choose();"> |
410 | <label>Namespace:</label><select name="namespace_choose" id="nb_nsc" onchange="javascript:nb_ns_choose();"> |
461 | <option value="dns">DNS</option> |
411 | <option value="dns">DNS</option> |
462 | <option value="url">URL</option> |
412 | <option value="url">URL</option> |
463 | <option value="oid">OID</option> |
413 | <option value="oid">OID</option> |
464 | <option value="x500">X.500 DN</option> |
414 | <option value="x500">X.500 DN</option> |
Line 474... | Line 424... | ||
474 | </form> |
424 | </form> |
475 | <script> |
425 | <script> |
476 | function nb_version_choose() { |
426 | function nb_version_choose() { |
477 | var ver = document.getElementById('nb_version').value; |
427 | var ver = document.getElementById('nb_version').value; |
478 | document.getElementById('nb_create_btn').value = 'Create UUIDv' + ver.substr(0,1); |
428 | document.getElementById('nb_create_btn').value = 'Create UUIDv' + ver.substr(0,1); |
479 | var x = ver.split('_namebased_'); |
- | |
480 | if ((x.length == 2) && (x[1].length == 36)) { |
- | |
481 | document.getElementById('nb_hash_info').innerHTML = ' (UUIDv8 Hash Space ID: ' + x[1] + ')'; |
- | |
482 | } else { |
- | |
483 | document.getElementById('nb_hash_info').innerHTML = ''; |
- | |
484 | } |
- | |
485 | - | ||
486 | } |
429 | } |
487 | function nb_ns_textchange() { |
430 | function nb_ns_textchange() { |
488 | var ns = document.getElementById('nb_ns').value.toLowerCase(); |
431 | var ns = document.getElementById('nb_ns').value.toLowerCase(); |
489 | if (ns == "6ba7b810-9dad-11d1-80b4-00c04fd430c8") { |
432 | if (ns == "6ba7b810-9dad-11d1-80b4-00c04fd430c8") { |
490 | if (document.getElementById('nb_nsc').value != "dns") { |
433 | if (document.getElementById('nb_nsc').value != "dns") { |
Line 713... | Line 656... | ||
713 | <input type="hidden" name="aai_gen_bits" value="64"> |
656 | <input type="hidden" name="aai_gen_bits" value="64"> |
714 | <input type="hidden" name="aai_gen_multicast" value="1"> |
657 | <input type="hidden" name="aai_gen_multicast" value="1"> |
715 | <input type="hidden" name="uuid" value="CREATE"> <input type="submit" value="Generate Multicast AAI-64"> |
658 | <input type="hidden" name="uuid" value="CREATE"> <input type="submit" value="Generate Multicast AAI-64"> |
716 | </form> |
659 | </form> |
717 | 660 | ||
718 | - | ||
719 | <br><br><br> |
661 | <br><br><br> |
720 | 662 | ||
721 | </body> |
663 | </body> |
722 | 664 | ||
723 | </html> |
665 | </html> |