uuid_generate.3 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. .\" Copyright 1999 Andreas Dilger ([email protected])
  2. .\"
  3. .\" %Begin-Header%
  4. .\" Redistribution and use in source and binary forms, with or without
  5. .\" modification, are permitted provided that the following conditions
  6. .\" are met:
  7. .\" 1. Redistributions of source code must retain the above copyright
  8. .\" notice, and the entire permission notice in its entirety,
  9. .\" including the disclaimer of warranties.
  10. .\" 2. Redistributions in binary form must reproduce the above copyright
  11. .\" notice, this list of conditions and the following disclaimer in the
  12. .\" documentation and/or other materials provided with the distribution.
  13. .\" 3. The name of the author may not be used to endorse or promote
  14. .\" products derived from this software without specific prior
  15. .\" written permission.
  16. .\"
  17. .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  18. .\" WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19. .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
  20. .\" WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
  21. .\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22. .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  23. .\" OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  24. .\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  25. .\" LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  27. .\" USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
  28. .\" DAMAGE.
  29. .\" %End-Header%
  30. .\"
  31. .\" Created Wed Mar 10 17:42:12 1999, Andreas Dilger
  32. .TH UUID_GENERATE 3 "May 2009" "util-linux" "Libuuid API"
  33. .SH NAME
  34. uuid_generate, uuid_generate_random, uuid_generate_time,
  35. uuid_generate_time_safe \- create a new unique UUID value
  36. .SH SYNOPSIS
  37. .nf
  38. .B #include <uuid.h>
  39. .sp
  40. .BI "void uuid_generate(uuid_t " out );
  41. .BI "void uuid_generate_random(uuid_t " out );
  42. .BI "void uuid_generate_time(uuid_t " out );
  43. .BI "int uuid_generate_time_safe(uuid_t " out );
  44. .BI "void uuid_generate_md5(uuid_t " out ", const uuid_t " ns ", const char " *name ", size_t " len ");
  45. .BI "void uuid_generate_sha1(uuid_t " out ", const uuid_t " ns ", const char " *name ", size_t " len ");
  46. .fi
  47. .SH DESCRIPTION
  48. The
  49. .B uuid_generate
  50. function creates a new universally unique identifier (UUID). The uuid will
  51. be generated based on high-quality randomness from
  52. .IR /dev/urandom ,
  53. if available. If it is not available, then
  54. .B uuid_generate
  55. will use an alternative algorithm which uses the current time, the
  56. local ethernet MAC address (if available), and random data generated
  57. using a pseudo-random generator.
  58. .sp
  59. The
  60. .B uuid_generate_random
  61. function forces the use of the all-random UUID format, even if
  62. a high-quality random number generator (i.e.,
  63. .IR /dev/urandom )
  64. is not available, in which case a pseudo-random
  65. generator will be substituted. Note that the use of a pseudo-random
  66. generator may compromise the uniqueness of UUIDs
  67. generated in this fashion.
  68. .sp
  69. The
  70. .B uuid_generate_time
  71. function forces the use of the alternative algorithm which uses the
  72. current time and the local ethernet MAC address (if available).
  73. This algorithm used to be the default one used to generate UUIDs, but
  74. because of the use of the ethernet MAC address, it can leak
  75. information about when and where the UUID was generated. This can cause
  76. privacy problems in some applications, so the
  77. .B uuid_generate
  78. function only uses this algorithm if a high-quality source of
  79. randomness is not available. To guarantee uniqueness of UUIDs generated
  80. by concurrently running processes, the uuid library uses a global
  81. clock state counter (if the process has permissions to gain exclusive access
  82. to this file) and/or the
  83. .B uuidd
  84. daemon, if it is running already or can be spawned by the process (if
  85. installed and the process has enough permissions to run it). If neither of
  86. these two synchronization mechanisms can be used, it is theoretically possible
  87. that two concurrently running processes obtain the same UUID(s). To tell
  88. whether the UUID has been generated in a safe manner, use
  89. .BR uuid_generate_time_safe .
  90. .sp
  91. The
  92. .B uuid_generate_time_safe
  93. function is similar to
  94. .BR uuid_generate_time ,
  95. except that it returns a value which denotes whether any of the synchronization
  96. mechanisms (see above) has been used.
  97. .sp
  98. The UUID is 16 bytes (128 bits) long, which gives approximately 3.4x10^38
  99. unique values (there are approximately 10^80 elementary particles in
  100. the universe according to Carl Sagan's
  101. .IR Cosmos ).
  102. The new UUID can reasonably be considered unique among all UUIDs created
  103. on the local system, and among UUIDs created on other systems in the past
  104. and in the future.
  105. .sp
  106. The
  107. .B uuid_generate_md5
  108. and
  109. .B uuid_generate_sha1
  110. functions generate an MD5 and SHA1 hashed (predictable) UUID based on a
  111. well-known UUID providing the namespace and an arbitrary binary string. The UUIDs
  112. conform to V3 and V5 UUIDs per RFC-4122.
  113. .SH RETURN VALUE
  114. The newly created UUID is returned in the memory location pointed to by
  115. .IR out .
  116. .B uuid_generate_time_safe
  117. returns zero if the UUID has been generated in a safe manner, \-1 otherwise.
  118. .SH "CONFORMING TO"
  119. This library generates UUIDs compatible with OSF DCE 1.1, and hash based UUIDs
  120. V3 and V5 compatible with RFC-4122.
  121. .SH AUTHOR
  122. Theodore Y.\& Ts'o
  123. .SH AVAILABILITY
  124. .B libuuid
  125. is part of the util-linux package since version 2.15.1 and is available from
  126. https://www.kernel.org/pub/linux/utils/util-linux/.
  127. .SH "SEE ALSO"
  128. .BR uuidgen (1),
  129. .BR uuid (3),
  130. .BR uuid_clear (3),
  131. .BR uuid_compare (3),
  132. .BR uuid_copy (3),
  133. .BR uuid_is_null (3),
  134. .BR uuid_parse (3),
  135. .BR uuid_time (3),
  136. .BR uuid_unparse (3),
  137. .BR uuidd (8)