qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] util: add is_equal to UUID API


From: Roman Kagan
Subject: Re: [Qemu-devel] [PATCH] util: add is_equal to UUID API
Date: Mon, 27 Nov 2017 14:02:11 +0300
User-agent: Mutt/1.9.1 (2017-09-22)

On Fri, Nov 24, 2017 at 06:34:03PM +0100, Thomas Huth wrote:
> On 24.11.2017 15:32, Roman Kagan wrote:
> > +++ b/tests/test-uuid.c
> > @@ -116,6 +116,29 @@ static void test_uuid_is_null(void)
> >      g_assert_false(qemu_uuid_is_null(&uuid_not_null_2));
> >  }
> >  
> > +static void test_uuid_is_equal(void)
> > +{
> > +    int i;
> > +    QemuUUID uuid;
> > +    QemuUUID uuid_null = { };
> > +    QemuUUID uuid_not_null = { { {
> > +        0x58, 0x6e, 0xce, 0x27, 0x7f, 0x09, 0x41, 0xe0,
> > +        0x9e, 0x74, 0xe9, 0x01, 0x31, 0x7e, 0x9d, 0x42
> > +    } } };
> > +    QemuUUID uuid_null_2 = uuid_null;
> > +    QemuUUID uuid_not_null_2 = uuid_not_null;
> > +
> > +    g_assert(qemu_uuid_is_equal(&uuid_null, &uuid_null_2));
> > +    g_assert(qemu_uuid_is_equal(&uuid_not_null, &uuid_not_null_2));
> > +    g_assert_false(qemu_uuid_is_equal(&uuid_null, &uuid_not_null));
> > +
> > +    for (i = 0; i < 100; ++i) {
> > +        qemu_uuid_generate(&uuid);
> > +        g_assert_false(qemu_uuid_is_equal(&uuid_null, &uuid));
> > +        g_assert_false(qemu_uuid_is_equal(&uuid_not_null, &uuid));
> 
> Isn't there a very low chance that the last line triggers by accident?
> Or uuid_no_null guaranteed to not match the generated one? In the latter
> case, a comment with a short explanation might be helpful here...

No, uuid_not_null passes the same validity criteria as the generated
ones so the collision probablity is not zero.

If we had an ideal random number generator, the 122 random bits would
coincide with a probability of 1 / (2 ** 122) ~= 2e-37 which I guess is
small enough in practical terms, so as a byproduct we'll test how random
the generated uuids are.

Which BTW may need certain attention: currently qemu_uuid_generate()
uses g_random_int() while, say, vmgenid wants it "cryptographically
random"random".

But that's another story...

Roman.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]