开发者

Test vectors for UUID version 5 (converting hash into guid) generation algorithm?

i'm trying to find 开发者_StackOverflowsome test vectors to check my implementation of RFC 4122 of UUID version 5.

4.3 Algorithm for Creating a Name-Based UUID

Version 3 of a UUID is for putting an MD5 hash into a GUID.

Version 5 of a UUID is for putting an SHA1 hash into a GUID.

The RFC has sample implementation in C:

void uuid_create_sha1_from_name(
   uuid_t *uuid,         /* resulting UUID */
   uuid_t nsid,          /* UUID of the namespace */
   void *name,           /* the name from which to generate a UUID */
   int namelen           /* the length of the name */
);

i've written my own implementation in the language that i'm using. Considering the amount of headaches caused by endian vs network order, i am sure my implementation is wrong.

i'd like some sample data, e.g.:

uuid = NameToGUID(
      {6ba7b811-9dad-11d1-80b4-00c04fd430c8}, //Namespace_URL
      "https://stackoverflow.com/questions/5515880"); //a url
CheckEquals(
      {8ABAD867-F515-3CF6-BB62-5F0C88B3BB11}, //expected uuid
      uuid);

See also

  • How to Create Deterministic Guids


The german Wikipedia entry for UUIDs got an example for www.example.org:

6ba7b810-9dad-11d1-80b4-00c04fd430c8 // namespace UUID
www.example.org                      // url
74738ff5-5367-5958-9aee-98fffdcd1876 // expected UUID

Apart from that, Java offers a UUID class you could use to generate test data. (EDIT: This only seems to be able to generate version 1,2,3 and 4 UUIDs.)

There's an answer in the question you linked that mentions some libraries that can generate version 3/5 UUIDs:

There seem to be a few libraries out there for generating version 3/5 UUIDs, including the python uuid module, boost.uuid (C++) and OSSP UUID. (I haven't looked for any .net ones)


OP Edit

The example on the DE wikipedia has a slight mistake:

  • it claims to be using the DNS name www.example.org
  • the given ASCII byte sequence is for www.example.com
  • but the SHA1 hash is using www.example.org.

i would edit the page to change the byte sequence from
0x63 0x6f 0x6d "com"
to
0x6f 0x72 0x67 "org"

but i don't speak german, don't want to create an account, and am just all around too lazy

The example boils down to

Namespace_DNS: {6ba7b810-9dad-11d1-80b4-00c04fd430c8}
Name:          "www.example.org"

concatenate the byte sequences:

Bytes:         6b a7 b8 10 9d ad 11 d1 80 b4 00 c0 4f d4 30 c8   {6ba7b810-9dad-11d1-80b4-00c04fd430c8}
               77 77 77 2e 65 78 61 6d 70 6c 65 2e 6f 72 67      "www.example.org"

Hash the byte sequence with SHA1, and copy most of it directly into a UUID:

SHA1 Digest:   74738ff5 5367 e958 9aee98fffdcd187694028007
UUID (v5):     74738ff5-5367-5958-9aee-98fffdcd1876
                             ^    ^

And take note of the conversion of one of the nibbles to 5 (to signify version 5).
And the top 2 bits of another byte are set to binary 10xxxxxx.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜