On Fri, Jun 19, 2009 at 12:31 PM, Colin Watson<[email protected]> wrote:
>> How about this?
>>
>>         i = open("/dev/urandom", O_RDONLY);
>>         if (i >= 0) {
>>                 read(i, buf, 16);
>
> I'd recommend using full_read.
>
>>                 close(i);
>>         }
>>         /* Paranoia. /dev/urandom may be missing.
>>          * rand() is guaranteed to generate at least [0, 2^15) range,
>>          * but lowest bits in some libc are not so "random".  */
>>         srand(monotonic_us());
>>         pid = getpid();
>>         while (1) {
>>                 for (i = 0; i < 16; i++)
>>                         buf[i] ^= rand() >> 5;
>>                 if (pid == 0)
>>                         break;
>>                 srand(pid);
>>                 pid = 0;
>>         }
>
> I haven't checked this in detail, but it looks superficially OK.
>
>>         buf[4 + 2    ] = (buf[4 + 2    ] & 0x0f) | 0x40; /* 
>> time_hi_and_version */
>>         buf[4 + 2 + 2] = (buf[4 + 2 + 2] & 0x3f) | 0x80; /* 
>> clk_seq_and_variant */
>
> You should probably also borrow Rob's recommendation of setting the
> multicast bit in the node ID so that your random UUIDs can't be confused
> with those generated from network cards.
>
>          buf[4 + 4 + 2] |= 1;


On Fri, Jun 19, 2009 at 12:34 PM, Colin Watson <[email protected]> wrote:
    On Fri, Jun 19, 2009 at 12:28:19PM +0200, Denys Vlasenko wrote:
    > I have
    >
    > # mkswap --version
    > mkswap (util-linux-ng 2.13.1)
    >
    > and experimentally it does not seem to set or clear any bits in node id.
    > It only sets version and variant.

    I agree it doesn't (from the source). Based on the RFC, I think this is
    probably a util-linux bug ...

RFC does not say that this should be done in UUIDs version 4.
It says it should be done for version 1.

> I've attached two alternative patches to this mail:
>
>  1) Add support for CONFIG_FEATURE_MKSWAP_UUID which can be used
>     instead of the bloaty CONFIG_DESKTOP.

Applied, thanks.
--
vda
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to