2 * Unix SMB/CIFS implementation.
4 * Copyright (C) Theodore Ts'o 1996, 1997,
5 * Copyright (C) Jim McDonough 2002.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 * Offset between 15-Oct-1582 and 1-Jan-70
27 #define TIME_OFFSET_HIGH 0x01B21DD2
28 #define TIME_OFFSET_LOW 0x13814000
33 uint16 time_hi_and_version
;
39 static void uuid_pack(const struct uuid
*uu
, GUID
*ptr
)
42 uint8
*out
= ptr
->info
;
58 tmp
= uu
->time_hi_and_version
;
68 memcpy(out
+10, uu
->node
, 6);
71 static void uuid_unpack(const GUID in
, struct uuid
*uu
)
73 const uint8
*ptr
= in
.info
;
77 tmp
= (tmp
<< 8) | *ptr
++;
78 tmp
= (tmp
<< 8) | *ptr
++;
79 tmp
= (tmp
<< 8) | *ptr
++;
83 tmp
= (tmp
<< 8) | *ptr
++;
87 tmp
= (tmp
<< 8) | *ptr
++;
88 uu
->time_hi_and_version
= tmp
;
91 tmp
= (tmp
<< 8) | *ptr
++;
94 memcpy(uu
->node
, ptr
, 6);
97 void uuid_generate_random(GUID
*out
)
102 generate_random_buffer(tmp
.info
, sizeof(tmp
.info
), True
);
103 uuid_unpack(tmp
, &uu
);
105 uu
.clock_seq
= (uu
.clock_seq
& 0x3FFF) | 0x8000;
106 uu
.time_hi_and_version
= (uu
.time_hi_and_version
& 0x0FFF) | 0x4000;