Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to create Universally Unique Identifiers (UUIDs) in Linux ?

802 views
Skip to first unread message

Lee

unread,
Mar 21, 2005, 11:08:01 PM3/21/05
to
UUID [1]: In MS-Windows, the UUID structure defines Universally Unique
Identifiers (UUIDs). UUIDs provide unique designations of objects such as
interfaces, manager entry-point vectors, and client objects.

Is there a similar API function set in Linux to generate UUIDs? Can you
point any C++ demo/tutorial for this?

Thx.

[1]
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/rpc/rpc/uuid_1.asp


Larry I Smith

unread,
Mar 21, 2005, 11:30:27 PM3/21/05
to

'man uuidgen' for a command line utility:

uuidgen was written by Andreas Dilger for libuuid.

AVAILABILITY
uuidgen is part of libuuid from the e2fsprogs package
and is available from http://e2fsprogs.sourceforge.net.

So, 'libuuid' provides a UUID API. 'e2fsprogs' comes with
many Linux distros.

Regards,
Larry

--
Anti-spam address, change each 'X' to '.' to reply directly.

Lee

unread,
Mar 21, 2005, 11:32:29 PM3/21/05
to
Many thanks...


Kasper Dupont

unread,
Mar 22, 2005, 12:15:54 AM3/22/05
to
Lee wrote:
>
> UUID [1]: In MS-Windows, the UUID structure defines Universally Unique
> Identifiers (UUIDs). UUIDs provide unique designations of objects such as
> interfaces, manager entry-point vectors, and client objects.
>
> Is there a similar API function set in Linux to generate UUIDs? Can you
> point any C++ demo/tutorial for this?

You can read one from /proc/sys/kernel/random/uuid,
but that is not portable. Alternatively you can
just read a few bytes from the random device, and
use that to generate a uuid. This is a litle more
portable.

--
Kasper Dupont

Christopher Browne

unread,
Mar 21, 2005, 11:42:42 PM3/21/05
to
In the last exciting episode, <Lee> wrote:
> UUID [1]: In MS-Windows, the UUID structure defines Universally Unique
> Identifiers (UUIDs). UUIDs provide unique designations of objects such as
> interfaces, manager entry-point vectors, and client objects.
>
> Is there a similar API function set in Linux to generate UUIDs? Can you
> point any C++ demo/tutorial for this?

Certainly.

The term UUID is well-defined, having been established as part of DCE
back in the 1990s.
http://www.opengroup.org/onlinepubs/9629399/apdxa.htm

libuuid is the DCE 1.1-conformant library for this purpose that is
commonly found.

libuuid was included in the e2fsprogs package, used for putting unique
identifiers on filesystems.

It is quite likely that you'll have perfectly good documentation in
the manual page for uuidgen. Download the sources to it and you
should find sample code. It'll be in C; a C++ application should be
able to readily use the C library...
--
wm(X,Y):-write(X),write('@'),write(Y). wm('cbbrowne','gmail.com').
http://cbbrowne.com/info/spreadsheets.html
[LINK FROM XGP]

James McIninch

unread,
Mar 22, 2005, 9:07:28 PM3/22/05
to
<Lee> wrote:

> UUID [1]: In MS-Windows, the UUID structure defines Universally Unique
> Identifiers (UUIDs). UUIDs provide unique designations of objects such as
> interfaces, manager entry-point vectors, and client objects.

This is a common misunderstanding. UUIDs in Windows are not guaranteed to be
unique at all. They are semi-unique.

>
> Is there a similar API function set in Linux to generate UUIDs? Can you
> point any C++ demo/tutorial for this?

Do the same thing as Windows. Designate an enumerator, add a token, and
calculate a checksum. It's a straight-forward operation. That said, hoping
that you'll get a unique result isn't really a great idea (even if, in
practice, you almost always do). You should, instead, come up with a
logical solution to the problem at hand rather than use the
cross-your-fingers-and-hope-for-the-best approach Microsoft uses.

>
> Thx.
>
> [1]
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/rpc/rpc/uuid_1.asp

--
Remove '.nospam' from e-mail address to reply by e-mail

John Hasler

unread,
Mar 22, 2005, 8:52:12 AM3/22/05
to
Kasper Dupont writes:
> You can read one from /proc/sys/kernel/random/uuid, but that is not
> portable. Alternatively you can just read a few bytes from the random
> device, and use that to generate a uuid. This is a litle more portable.

And about as likely to be unique (or perhaps more so) than a "proper" uuid.
--
John Hasler
jo...@dhh.gt.org
Dancing Horse Hill
Elmwood, WI USA

Kasper Dupont

unread,
Mar 23, 2005, 3:07:53 AM3/23/05
to
John Hasler wrote:
>
> Kasper Dupont writes:
> > You can read one from /proc/sys/kernel/random/uuid, but that is not
> > portable. Alternatively you can just read a few bytes from the random
> > device, and use that to generate a uuid. This is a litle more portable.
>
> And about as likely to be unique (or perhaps more so) than a "proper" uuid.

Both the user mode uuidgen, and the one in the kernel
use randomness to generate the uuids. Here is the
source of the one used in the kernel. Apparently six
bits of the uuid have to be set to a specific value
to indicate that this is a random uuid. So there is
only 122 bits of randomness.

/*
* Generate random UUID
*/
void generate_random_uuid(unsigned char uuid_out[16])
{
get_random_bytes(uuid_out, 16);
/* Set UUID version to 4 --- truely random generation */
uuid_out[6] = (uuid_out[6] & 0x0F) | 0x40;
/* Set the UUID variant to DCE */
uuid_out[8] = (uuid_out[8] & 0x3F) | 0x80;
}

--
Kasper Dupont

Kasper Dupont

unread,
Mar 23, 2005, 3:20:43 AM3/23/05
to
James McIninch wrote:
>
> Do the same thing as Windows. Designate an enumerator, add a token, and
> calculate a checksum. It's a straight-forward operation. That said, hoping
> that you'll get a unique result isn't really a great idea (even if, in
> practice, you almost always do).

Expecting randomly generated 128 bit strings not
to bcollide is a reasonable choice. But I would
have prefered a few more bits than that.

--
Kasper Dupont

Lawrence D'Oliveiro

unread,
Mar 25, 2005, 4:14:10 AM3/25/05
to
In article <424126DB...@daimi.au.dk>,
Kasper Dupont <kas...@daimi.au.dk> wrote:

The man page for uuidgen mentions that it conforms to the OSF DCE 1.1
spec. Unless I'm mistaken, that would date from late 1980s/early 1990s,
when a 128-bit MD4 hash was considered ample.

But there's no reason why you have to stick with 128 bits nowadays,
surely. By all means feed a random seed into RIPE MD-160 or something to
generate a 160-bit hash and use that as a unique ID.

Kasper Dupont

unread,
Mar 25, 2005, 6:41:11 AM3/25/05
to
Lawrence D'Oliveiro wrote:
>
> But there's no reason why you have to stick with 128 bits nowadays,
> surely. By all means feed a random seed into RIPE MD-160 or something to
> generate a 160-bit hash and use that as a unique ID.

Why use a hash function, if you already have a random
input? Of course if the input is not entirely random,
a hash would make sense. But if you use /dev/*random
that should already have happened.

BTW, how is the performance and security of RIPE MD-160
compared to SHA1?

Is there any fast and secure 256 bit hash with a common
command line implementation like MD5 and SHA1?

--
Kasper Dupont

Lawrence D'Oliveiro

unread,
Mar 26, 2005, 9:41:32 PM3/26/05
to
In article <4243F8D7...@daimi.au.dk>,
Kasper Dupont <kas...@daimi.au.dk> wrote:

>BTW, how is the performance and security of RIPE MD-160
>compared to SHA1?

I don't know of any published papers reporting weaknesses in RIPE MD-160.

0 new messages