'\" 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 \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" "."