How can I tell if an UUID generated by QUuid::createUuid() is based on entrophy of cryptographic quality?

Lennart Rolland

From the Qt5 reference on QUuid:

QUuid QUuid::createUuid() [static]

On any platform other than Windows, this function returns a new UUID with variant QUuid::DCE and version QUuid::Random. If the /dev/urandom device exists, then the numbers used to construct the UUID will be of cryptographic quality, which will make the UUID unique. Otherwise, the numbers of the UUID will be obtained from the local pseudo-random number generator (qrand(), which is seeded by qsrand()) which is usually not of cryptograhic quality, which means that the UUID can't be guaranteed to be unique.

When on a platform with /dev/urandom, how can I tell if /dev/urandom in fact is available and will be used by this function when it runs?

I suspect it was not in my case, based on this little code that I ran mostly for curiosity's sake:

while(true){
        QUuid u=QUuid::createUuid();
        QString str=u.toString();
        if(str.contains("2222")){
            qDebug()<<"UUID:"<<str;
            return;
        }
    }

This produced the following output when I ran it repeatedly:

 1 UUID: "{8b42222b-bac3-4c93-b55d-0255a33115a2}"
 2 UUID: "{5122227e-473e-4885-8285-8780cc51f71a}"
 3 UUID: "{bfeed28f-f8da-4a69-9303-77388752222e}"
 4 UUID: "{0000beee-690c-4875-9589-9e222222cedc}"
 5 UUID: "{e5a2646d-1c81-4974-94ad-8b222265b67a}"
 6 UUID: "{bb77d756-6726-4e9f-94d8-3d4892222a2f}"

Notice the rather bizarre looking output on line #4, and the other apparent symmetries in the 3rd and 4th columns (except for the 4 in the start of column 3 which was to be expected).

Thanks!

Syon

enter image description here

Your output on line 4 is almost certainly just random chance. 6 UUIDs is not a large enough sample to provide any indication of randomness, if you really wanted to know for sure you would need to test a massive number of UUIDs (more than is realistically feasible).

Concerning column 3 and 4, as you've noted the leading "4" in the 3rd column is expected because it indicates the UUID version. The leading value in the 4th column (b 55d, 8 285, 9 303, ...) though is also expected, this value will always be 8, 9, a, or b. Outside of these values, I don't see any particular symmetries in the 3rd and 4th columns.

For checking if /dev/urandom or qrand() was used, the QUuid class does not make this information available, but if you really wanted to know you could always do what the QUuid class does and try to open and read data from /dev/urandom. I would argue that this is probably overkill though. While I certainly would not rely on qrand() in any situation where quality random numbers are needed for security, it's implementation (given how it's being seeded, ~line 959) is probably good enough for generating UUIDs.

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何确定QUuid :: createUuid()生成的UUID是否基于加密质量的证明?

来自分类Dev

How can I tell Spotlight to index my .dSYM bundles?

来自分类Dev

How can I tell if a hard drive will fit my laptop?

来自分类Dev

How can I tell if a hard drive will fit my laptop?

来自分类Dev

In F#, how do I tell if an object is an Async<_>, and how can I cast it to an Async<_>?

来自分类Dev

How can I define an UUID for a class, and use __uuidof, in the same way for g++ and Visual C++?

来自分类Dev

How do I tell if an XMLHttpRequest failed due to a network issue?

来自分类Dev

Can I assign function based on the condition in jquery?

来自分类Dev

What Is a .vrc file, how is is generated and can you remove it using the IDE?

来自分类Dev

How do I change the HTML content of a dynamically generated element in Jquery

来自分类Dev

Twitter Bootstrap 3 - how can I switch from a horizontal button group to vertical button group based on screen size?

来自分类Dev

How can I cancel an ngEvent?

来自分类Dev

How can I return a function?

来自分类Dev

How can you change the parameterless constructor of an Entity Framework 6 database-first generated class?

来自分类Dev

Golang Cryptographic Shuffle

来自分类Dev

How can I create a histogram in R?

来自分类Dev

How can I select with column of lists

来自分类Dev

How can I extract text from images?

来自分类Dev

How can I pipe input to a process?

来自分类Dev

How i can onUpgrade me database in Android

来自分类Dev

How can I check for reference equality in Perl?

来自分类Dev

How can I use the constraints in native webrtc?

来自分类Dev

How can I get the application path in C?

来自分类Dev

How can I have mocha reporter for protractor?

来自分类Dev

How can I create this complicated SQL query?

来自分类Dev

How can I highlight a line in TMemo?

来自分类Dev

How can I archive old git tags?

来自分类Dev

How can I limit the results in a PagingAndSortingRepository @Query?

来自分类Dev

How can I search a range of lines in python?

Related 相关文章

  1. 1

    如何确定QUuid :: createUuid()生成的UUID是否基于加密质量的证明?

  2. 2

    How can I tell Spotlight to index my .dSYM bundles?

  3. 3

    How can I tell if a hard drive will fit my laptop?

  4. 4

    How can I tell if a hard drive will fit my laptop?

  5. 5

    In F#, how do I tell if an object is an Async<_>, and how can I cast it to an Async<_>?

  6. 6

    How can I define an UUID for a class, and use __uuidof, in the same way for g++ and Visual C++?

  7. 7

    How do I tell if an XMLHttpRequest failed due to a network issue?

  8. 8

    Can I assign function based on the condition in jquery?

  9. 9

    What Is a .vrc file, how is is generated and can you remove it using the IDE?

  10. 10

    How do I change the HTML content of a dynamically generated element in Jquery

  11. 11

    Twitter Bootstrap 3 - how can I switch from a horizontal button group to vertical button group based on screen size?

  12. 12

    How can I cancel an ngEvent?

  13. 13

    How can I return a function?

  14. 14

    How can you change the parameterless constructor of an Entity Framework 6 database-first generated class?

  15. 15

    Golang Cryptographic Shuffle

  16. 16

    How can I create a histogram in R?

  17. 17

    How can I select with column of lists

  18. 18

    How can I extract text from images?

  19. 19

    How can I pipe input to a process?

  20. 20

    How i can onUpgrade me database in Android

  21. 21

    How can I check for reference equality in Perl?

  22. 22

    How can I use the constraints in native webrtc?

  23. 23

    How can I get the application path in C?

  24. 24

    How can I have mocha reporter for protractor?

  25. 25

    How can I create this complicated SQL query?

  26. 26

    How can I highlight a line in TMemo?

  27. 27

    How can I archive old git tags?

  28. 28

    How can I limit the results in a PagingAndSortingRepository @Query?

  29. 29

    How can I search a range of lines in python?

热门标签

归档