Rev 72 | Rev 75 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 72 | Rev 74 | ||
---|---|---|---|
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-09-23 |
6 | * Version 2023-10-05 |
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 367... | Line 367... | ||
367 | NameSpaceUuid<DNS> := "6ba7b810-9dad-11d1-80b4-00c04fd430c8". |
367 | NameSpaceUuid<DNS> := "6ba7b810-9dad-11d1-80b4-00c04fd430c8". |
368 | NameSpaceUuid<URL> := "6ba7b811-9dad-11d1-80b4-00c04fd430c8". |
368 | NameSpaceUuid<URL> := "6ba7b811-9dad-11d1-80b4-00c04fd430c8". |
369 | NameSpaceUuid<OID> := "6ba7b812-9dad-11d1-80b4-00c04fd430c8". |
369 | NameSpaceUuid<OID> := "6ba7b812-9dad-11d1-80b4-00c04fd430c8". |
370 | NameSpaceUuid<X500> := "6ba7b814-9dad-11d1-80b4-00c04fd430c8". |
370 | NameSpaceUuid<X500> := "6ba7b814-9dad-11d1-80b4-00c04fd430c8". |
371 | 371 | ||
372 | <u>As defined by <a href="https://datatracker.ietf.org/doc/draft-ietf-uuidrev-rfc4122bis/">draft-ietf-uuidrev-rfc4122bis-11</a>:</u> |
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> )). |
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> )). |
374 | <?php |
374 | <?php |
375 | 375 | ||
376 | $tmp = []; |
376 | $tmp = []; |
377 | foreach (get_uuidv8_hash_space_ids() as list($algo,$space,$friendlyName,$author,$available)) { |
377 | foreach (get_uuidv8_hash_space_ids() as list($algo,$space,$friendlyName,$author,$available)) { |
Line 386... | Line 386... | ||
386 | echo $line; |
386 | echo $line; |
387 | } |
387 | } |
388 | 388 | ||
389 | ?> |
389 | ?> |
390 | 390 | ||
391 | <u>Custom implementation ("Raw Hash"):</u> |
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> )). |
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> )). |
393 | 393 | ||
394 | </pre></p> |
394 | </pre></p> |
395 | 395 | ||
396 | <style> |
396 | <style> |
Line 430... | Line 430... | ||
430 | foreach ($tmp as $html) { |
430 | foreach ($tmp as $html) { |
431 | echo "\t\t$html\n"; |
431 | echo "\t\t$html\n"; |
432 | } |
432 | } |
433 | } |
433 | } |
434 | 434 | ||
435 | echo "\t\t<option disabled>--- UUIDv8 (Raw Hash) ---</option>\n"; |
435 | echo "\t\t<option disabled>--- UUIDv8 (defined by Internet Draft 12, Appendix C.2) ---</option>\n"; |
436 | $tmp = []; |
436 | $tmp = []; |
437 | $algos = hash_algos(); |
437 | $algos = hash_algos(); |
438 | $algos[] = 'shake128'; |
438 | $algos[] = 'shake128'; |
439 | $algos[] = 'shake256'; |
439 | $algos[] = 'shake256'; |
440 | foreach ($algos as $algo) { |
440 | foreach ($algos as $algo) { |
Line 443... | Line 443... | ||
443 | $friendlyName = strtoupper($algo); |
443 | $friendlyName = strtoupper($algo); |
444 | 444 | ||
445 | if ($algo == 'shake128') $bits = 999; |
445 | if ($algo == 'shake128') $bits = 999; |
446 | else if ($algo == 'shake256') $bits = 999; |
446 | else if ($algo == 'shake256') $bits = 999; |
447 | else $bits = strlen(hash($algo, '', true)) * 8; |
447 | else $bits = strlen(hash($algo, '', true)) * 8; |
448 | if ($bits < 128) $friendlyName .= " (Small hash size! $bits bits)"; |
448 | if ($bits < 128) $friendlyName .= " (Small hash size! $bits bits)"; // <-- this is not described in Appendix B.2 |
449 | 449 | ||
450 | $space = $algo; |
450 | $space = $algo; |
451 | $tmp[$friendlyName] = '<option value="8_namebased_'.$space.'">'.htmlentities($friendlyName).'</option>'; |
451 | $tmp[$friendlyName] = '<option value="8_namebased_'.$space.'">'.htmlentities($friendlyName).'</option>'; |
452 | } |
452 | } |
453 | natsort($tmp); |
453 | natsort($tmp); |