diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2024-02-21 07:43:53 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2024-02-21 07:43:53 +0100 |
commit | 4928cf0220752bc593f58faecaa4fb932ce7017c (patch) | |
tree | 34465dd7cec16a98d4f0d78f0bc60eaefb58ab5b /lib | |
parent | b4186752c6abece215a27bfad014164accfe3e28 (diff) | |
parent | 9f868f78bc5473d02a1e85debfa302ba370cbc2e (diff) | |
download | barebox-4928cf0220752bc593f58faecaa4fb932ce7017c.tar.gz barebox-4928cf0220752bc593f58faecaa4fb932ce7017c.tar.xz |
Merge branch 'for-next/partitions'
Diffstat (limited to 'lib')
-rw-r--r-- | lib/uuid.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/uuid.c b/lib/uuid.c index db75be1725..60a651e330 100644 --- a/lib/uuid.c +++ b/lib/uuid.c @@ -8,9 +8,39 @@ #include <linux/uuid.h> #include <module.h> +#include <stdlib.h> #include <linux/export.h> const guid_t guid_null; EXPORT_SYMBOL(guid_null); const uuid_t uuid_null; EXPORT_SYMBOL(uuid_null); + +/** + * generate_random_uuid - generate a random UUID + * @uuid: where to put the generated UUID + * + * Random UUID interface + * + * Used to create a Boot ID or a filesystem UUID/GUID, but can be + * useful for other kernel drivers. + */ +void generate_random_uuid(unsigned char uuid[16]) +{ + get_random_bytes(uuid, 16); + /* Set UUID version to 4 --- truly random generation */ + uuid[6] = (uuid[6] & 0x0F) | 0x40; + /* Set the UUID variant to DCE */ + uuid[8] = (uuid[8] & 0x3F) | 0x80; +} +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); |