Home | History | Annotate | Download | only in tpm2
      1 // This file was extracted from the TCG Published
      2 // Trusted Platform Module Library
      3 // Part 4: Supporting Routines
      4 // Family "2.0"
      5 // Level 00 Revision 01.16
      6 // October 30, 2014
      7 
      8 #include "stdint.h"
      9 #include "TpmBuildSwitches.h"
     10 const char notReallyUnique[] =
     11        "This is not really a unique value. A real unique value should"
     12        " be generated by the platform.";
     13 //
     14 //
     15 //      _plat__GetUnique()
     16 //
     17 //     This function is used to access the platform-specific unique value. This function places the unique value
     18 //     in the provided buffer (b) and returns the number of bytes transferred. The function will not copy more
     19 //     data than bSize.
     20 //
     21 //     NOTE:           If a platform unique value has unequal distribution of uniqueness and bSize is smaller than the size of the
     22 //                     unique value, the bSize portion with the most uniqueness should be returned.
     23 //
     24 LIB_EXPORT uint32_t
     25 _plat__GetUnique(
     26    uint32_t                    which,                // authorities (0) or details
     27    uint32_t                    bSize,                // size of the buffer
     28    unsigned char              *b                     // output buffer
     29 )
     30 {
     31    const char                 *from = notReallyUnique;
     32    uint32_t                    retVal = 0;
     33    if(which == 0) // the authorities value
     34    {
     35        for(retVal = 0;
     36            *from != 0 && retVal < bSize;
     37            retVal++)
     38        {
     39            *b++ = *from++;
     40        }
     41    }
     42    else
     43    {
     44 #define uSize sizeof(notReallyUnique)
     45        b = &b[((bSize < uSize) ? bSize : uSize) - 1];
     46        for(retVal = 0;
     47            *from != 0 && retVal < bSize;
     48            retVal++)
     49        {
     50            *b-- = *from++;
     51        }
     52    }
     53    return retVal;
     54 }
     55