summaryrefslogtreecommitdiffstats
path: root/libuuid/man/uuid_generate.3
blob: cb88247d43da75dc166cfaff1734a3b93d698fef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
'\" t
.\"     Title: uuid_generate
.\"    Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.20
.\"      Date: 2024-01-31
.\"    Manual: Programmer's Manual
.\"    Source: util-linux 2.40
.\"  Language: English
.\"
.TH "UUID_GENERATE" "3" "2024-01-31" "util\-linux 2.40" "Programmer\*(Aqs Manual"
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.ss \n[.ss] 0
.nh
.ad l
.de URL
\fI\\$2\fP <\\$1>\\$3
..
.als MTO URL
.if \n[.g] \{\
.  mso www.tmac
.  am URL
.    ad l
.  .
.  am MTO
.    ad l
.  .
.  LINKSTYLE blue R < >
.\}
.SH "NAME"
uuid_generate, uuid_generate_random, uuid_generate_time, uuid_generate_time_safe \- create a new unique UUID value
.SH "SYNOPSIS"
.sp
\fB#include <uuid.h>\fP
.sp
\fBvoid uuid_generate(uuid_t \fIout\fP);\fP
.br
\fBvoid uuid_generate_random(uuid_t \fIout\fP);\fP
.br
\fBvoid uuid_generate_time(uuid_t \fIout\fP);\fP
.br
\fBint uuid_generate_time_safe(uuid_t \fIout\fP);\fP
.br
\fBvoid uuid_generate_md5(uuid_t \fIout\fP, const uuid_t \fIns\fP, const char \fI*name\fP, size_t \fIlen\fP);\fP
.br
\fBvoid uuid_generate_sha1(uuid_t \fIout\fP, const uuid_t \fIns\fP, const char \fI*name\fP, size_t \fIlen\fP);\fP
.SH "DESCRIPTION"
.sp
The \fBuuid_generate\fP() function creates a new universally unique identifier (UUID). The uuid will be generated based on high\-quality randomness from \fBgetrandom\fP(2), \fI/dev/urandom\fP, or \fI/dev/random\fP if available. If it is not available, then \fBuuid_generate\fP() will use an alternative algorithm which uses the current time, the local ethernet MAC address (if available), and random data generated using a pseudo\-random generator.
.sp
The \fBuuid_generate_random\fP() function forces the use of the all\-random UUID format, even if a high\-quality random number generator is not available, in which case a pseudo\-random generator will be substituted. Note that the use of a pseudo\-random generator may compromise the uniqueness of UUIDs generated in this fashion.
.sp
The \fBuuid_generate_time\fP() function forces the use of the alternative algorithm which uses the current time and the local ethernet MAC address (if available). This algorithm used to be the default one used to generate UUIDs, but because of the use of the ethernet MAC address, it can leak information about when and where the UUID was generated. This can cause privacy problems in some applications, so the \fBuuid_generate\fP() function only uses this algorithm if a high\-quality source of randomness is not available. To guarantee uniqueness of UUIDs generated by concurrently running processes, the uuid library uses a global clock state counter (if the process has permissions to gain exclusive access to this file) and/or the \fBuuidd\fP(8) daemon, if it is running already or can be spawned by the process (if installed and the process has enough permissions to run it). If neither of these two synchronization mechanisms can be used, it is theoretically possible that two concurrently running processes obtain the same UUID(s). To tell whether the UUID has been generated in a safe manner, use \fBuuid_generate_time_safe\fP.
.sp
The \fBuuid_generate_time_safe\fP() function is similar to \fBuuid_generate_time\fP(), except that it returns a value which denotes whether any of the synchronization mechanisms (see above) has been used.
.sp
The UUID is 16 bytes (128 bits) long, which gives approximately 3.4x10^38 unique values (there are approximately 10^80 elementary particles in the universe according to Carl Sagan\(cqs \fICosmos\fP). The new UUID can reasonably be considered unique among all UUIDs created on the local system, and among UUIDs created on other systems in the past and in the future.
.sp
The \fBuuid_generate_md5\fP() and \fBuuid_generate_sha1\fP() functions generate an MD5 and SHA1 hashed (predictable) UUID based on a well\-known UUID providing the namespace and an arbitrary binary string. The UUIDs conform to V3 and V5 UUIDs per \c
.URL "https://tools.ietf.org/html/rfc4122" "RFC\-4122" "."
.SH "RETURN VALUE"
.sp
The newly created UUID is returned in the memory location pointed to by \fIout\fP. \fBuuid_generate_time_safe\fP() returns zero if the UUID has been generated in a safe manner, \-1 otherwise.
.SH "CONFORMING TO"
.sp
This library generates UUIDs compatible with OSF DCE 1.1, and hash based UUIDs V3 and V5 compatible with \c
.URL "https://tools.ietf.org/html/rfc4122" "RFC\-4122" "."
.SH "AUTHORS"
.sp
Theodore Y. Ts\(cqo
.SH "SEE ALSO"
.sp
\fBuuidgen\fP(1),
\fBuuid\fP(3),
\fBuuid_clear\fP(3),
\fBuuid_compare\fP(3),
\fBuuid_copy\fP(3),
\fBuuid_is_null\fP(3),
\fBuuid_parse\fP(3),
\fBuuid_time\fP(3),
\fBuuid_unparse\fP(3),
\fBuuidd\fP(8)
.SH "REPORTING BUGS"
.sp
For bug reports, use the issue tracker at \c
.URL "https://github.com/util\-linux/util\-linux/issues" "" "."
.SH "AVAILABILITY"
.sp
The \fBlibuuid\fP library is part of the util\-linux package since version 2.15.1. It can be downloaded from \c
.URL "https://www.kernel.org/pub/linux/utils/util\-linux/" "Linux Kernel Archive" "."