[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: UUIDGEN in lisp
From: |
Jesper Harder |
Subject: |
Re: UUIDGEN in lisp |
Date: |
Sun, 15 Feb 2004 01:27:31 +0100 |
User-agent: |
Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (gnu/linux) |
Brad Collins <brad@studiojungle.net> writes:
> But I really do need to use a proper UUID.
>
> I've been trying to see how it's been done by others but it's not
> easy stuff. I still don't understand about high and low parts of a
> time stamp and how to convert them..
Well, the time-based UUID is annoying to generate -- it requires
system-wide storage of a seed. I don't see how you can guarantee
that your generator will use the same storage as, say, the Perl
generator and whatever else might generate UUIDs on ms-windows.
This type of UUID also leaks your MAC address.
Random-based UUIDs are much nicer. Below is an implementation. It
uses /dev/urandom as a source of high quality random bits on
GNU/Linux, but I don't know if the built-in `random' in Emacs used on
other systems qualifies as a "cryptographic strength random number
generator".
(defun uuid ()
"Generate a version 4 UUID."
(let ((bytes (uuid-random)))
(setf (nth 7 bytes)
(logior #B01000000 (logand #B01111111 (nth 7 bytes))))
(setf (nth 8 bytes)
(logior #B01000000 (logand #B01001111 (nth 8 bytes))))
(apply 'format
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x"
bytes)))
(defun uuid-random ()
"Return a list of 16 random bytes."
(if (file-readable-p "/dev/urandom")
(let (((coding-system-for-read 'binary)))
(mapcar 'identity
(substring
(string-as-unibyte
(shell-command-to-string
"dd count=16 bs=1 < /dev/urandom"))
0 16)))
(random t)
(mapcar 'random (make-list 16 255))))
- UUIDGEN in lisp, Brad Collins, 2004/02/13
- Re: UUIDGEN in lisp, Jesper Harder, 2004/02/13
- Re: UUIDGEN in lisp, Brad Collins, 2004/02/14
- Message not available
- Message not available
- Re: UUIDGEN in lisp, Jesper Harder, 2004/02/15
- Re: UUIDGEN in lisp, Eli Zaretskii, 2004/02/16
- Re: UUIDGEN in lisp, Brad Collins, 2004/02/16
- Message not available
- Re: UUIDGEN in lisp, Jesper Harder, 2004/02/16
- Re: UUIDGEN in lisp, Eli Zaretskii, 2004/02/16
- Message not available
- Re: UUIDGEN in lisp, Jesper Harder, 2004/02/16
- Re: UUIDGEN in lisp, Eli Zaretskii, 2004/02/17
- Message not available
- Re: UUIDGEN in lisp, Jesper Harder, 2004/02/17