]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libuuid: fix v6 generation
authorThomas Weißschuh <thomas@t-8ch.de>
Wed, 15 May 2024 06:42:42 +0000 (06:42 +0000)
committerThomas Weißschuh <thomas@t-8ch.de>
Wed, 15 May 2024 06:50:22 +0000 (06:50 +0000)
get_clock_counter() does not return a gregorian timestamp as required
for v6.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
libuuid/src/gen_uuid.c

index aa353e443621036f9560c170dbba894314e1c341..e80e371c47371b24c55de36475db77148702852e 100644 (file)
@@ -665,13 +665,14 @@ int uuid_generate_time_safe(uuid_t out)
 void uuid_generate_time_v6(uuid_t out)
 {
        struct uuid uu = {};
-       uint64_t clock_reg;
+       uint32_t clock_high, clock_low;
+       uint16_t clock_seq;
 
-       clock_reg = get_clock_counter();
+       get_clock(&clock_high, &clock_low, &clock_seq, NULL);
 
-       uu.time_low = clock_reg >> 28;
-       uu.time_mid = clock_reg >> 12;
-       uu.time_hi_and_version = (clock_reg & 0x0FFF) | (6 << 12);
+       uu.time_low = (clock_high << 4) | (clock_low >> 28);
+       uu.time_mid = clock_low >> 12;
+       uu.time_hi_and_version = (clock_low & 0x0FFF) | (6 << 12);
 
        ul_random_get_bytes(&uu.clock_seq, 8);
        uu.clock_seq = (uu.clock_seq & 0x3FFF) | 0x8000;