From 76245a33daf1e4a8dc724e9b7fd712bd41a7aee0 Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Tue, 6 Mar 2018 02:21:09 +0100 Subject: Remove libuuid usage (#16643) * Remove libuuid usage This change removes dependency on the libuuid library that is used for GUID creation only. It implements it using a random generator instead. It also modifies return type of PAL_Random to VOID since it was always returning TRUE and none of the existing callers were checking it. 1. Port the GUID creation to managed code. 2. Modify the PAL_Random to have 6 times better perf so that the perf of the CoCreateGuid that is used in the native runtime doesn't degrade that much w.r.t the previous state when the libuuid was used. 3. Use Interop.GetRandomBytes on Unix and fix Windows --- src/palrt/guid.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/palrt') diff --git a/src/palrt/guid.cpp b/src/palrt/guid.cpp index bd782c8502..14cd3bb490 100644 --- a/src/palrt/guid.cpp +++ b/src/palrt/guid.cpp @@ -24,3 +24,25 @@ DEFINE_GUID(IID_IClassFactory, 0x00000001, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x0 // objidl.idl DEFINE_GUID(IID_ISequentialStream, 0x0c733a30, 0x2a1c, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d); DEFINE_GUID(IID_IStream, 0x0000000c, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); + +// Create a random guid based on the https://www.ietf.org/rfc/rfc4122.txt +STDAPI +CoCreateGuid(OUT GUID * pguid) +{ + PAL_Random(pguid, sizeof(GUID)); + + static const USHORT VersionMask = 0xF000; + static const USHORT RandomGuidVersion = 0x4000; + + static const BYTE ClockSeqHiAndReservedMask = 0xC0; + static const BYTE ClockSeqHiAndReservedValue = 0x80; + + // Modify bits indicating the type of the GUID + + // time_hi_and_version + pguid->Data3 = (pguid->Data3 & ~VersionMask) | RandomGuidVersion; + // clock_seq_hi_and_reserved + pguid->Data4[0] = (pguid->Data4[0] & ~ClockSeqHiAndReservedMask) | ClockSeqHiAndReservedValue; + + return S_OK; +} -- cgit v1.2.3