Subversion Repositories uuid_mac_utils

Rev

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

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