From 3eee74f6d39b888b75e27de05eec9bb9da2afe56 Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Wed, 13 Dec 2023 20:32:19 -0500 Subject: [PATCH] rev180: Sync _plat__GetUnique with upstream The value returned from a call to this function is written into g_platformUniqueDetails but not used by libtpms since VENDOR_PERMANENT is not set. Signed-off-by: Stefan Berger --- src/tpm2/Unique.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/tpm2/Unique.c b/src/tpm2/Unique.c index 9f962827..379b703d 100644 --- a/src/tpm2/Unique.c +++ b/src/tpm2/Unique.c @@ -3,7 +3,6 @@ /* Secret Value to the TPM */ /* Written by Ken Goldman */ /* IBM Thomas J. Watson Research Center */ -/* $Id: Unique.c 1490 2019-07-26 21:13:22Z kgoldman $ */ /* */ /* Licenses and Notices */ /* */ @@ -68,6 +67,7 @@ //** Includes #include "Platform.h" +#include "Memory_fp.h" // libtpms: temporary const char notReallyUnique[] = "This is not really a unique value. A real " "unique value should" @@ -90,28 +90,16 @@ LIB_EXPORT uint32_t _plat__GetUnique(uint32_t which, // which vendor value to r unsigned char* b // output buffer ) { - const char* from = notReallyUnique; + //const char* from = notReallyUnique; // libtpms: deactivated uint32_t retVal = 0; - if(which == 0) // the authorities value + if(which == 1) { - for(retVal = 0; - *from != 0 && retVal < bSize; - retVal++) - { - *b++ = *from++; - } - } - else - { -#define uSize sizeof(notReallyUnique) - b = &b[((bSize < uSize) ? bSize : uSize) - 1]; - for(retVal = 0; - *from != 0 && retVal < bSize; - retVal++) - { - *b-- = *from++; - } + const size_t uSize = + sizeof(notReallyUnique) <= bSize ? sizeof(notReallyUnique) : bSize; + MemoryCopy(b, notReallyUnique, uSize); } + // else fall through to default 0 + return retVal; }