summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>2020-02-24 17:37:50 +0200
committerDavid Sterba <dsterba@suse.com>2020-03-23 17:01:47 +0100
commit48a2e88f53aea4dface64883157ad3c428132f75 (patch)
treea98c9c07b374ed0412968b414dee66fb533034b4 /lib
parentd01cd62400b3a42d012069518614d944c35f9c99 (diff)
downloadlinux-48a2e88f53aea4dface64883157ad3c428132f75.tar.bz2
uuid: Provide a GUID generator for raw buffer
In some cases we would like to generate a GUID and export it. Though it would require either casting to internal kernel types or an intermediate buffer. Instead we may achieve this by supplying a pointer to raw buffer and make a complimentary API to existing one for UUIDs. Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/uuid.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/uuid.c b/lib/uuid.c
index b6a1edb61d87..562d53977cab 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -40,6 +40,16 @@ void generate_random_uuid(unsigned char uuid[16])
}
EXPORT_SYMBOL(generate_random_uuid);
+void generate_random_guid(unsigned char guid[16])
+{
+ get_random_bytes(guid, 16);
+ /* Set GUID version to 4 --- truly random generation */
+ guid[7] = (guid[7] & 0x0F) | 0x40;
+ /* Set the GUID variant to DCE */
+ guid[8] = (guid[8] & 0x3F) | 0x80;
+}
+EXPORT_SYMBOL(generate_random_guid);
+
static void __uuid_gen_common(__u8 b[16])
{
prandom_bytes(b, 16);