aboutsummaryrefslogtreecommitdiff
path: root/Unique.c
blob: 75142a4215554019f85693b56c3df582a6badd1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// This file was extracted from the TCG Published
// Trusted Platform Module Library
// Part 4: Supporting Routines
// Family "2.0"
// Level 00 Revision 01.16
// October 30, 2014

#include "stdint.h"
#include "TpmBuildSwitches.h"
const char notReallyUnique[] =
       "This is not really a unique value. A real unique value should"
       " be generated by the platform.";
//
//
//      _plat__GetUnique()
//
//     This function is used to access the platform-specific unique value. This function places the unique value
//     in the provided buffer (b) and returns the number of bytes transferred. The function will not copy more
//     data than bSize.
//
//     NOTE:           If a platform unique value has unequal distribution of uniqueness and bSize is smaller than the size of the
//                     unique value, the bSize portion with the most uniqueness should be returned.
//
LIB_EXPORT uint32_t
_plat__GetUnique(
   uint32_t                    which,                // authorities (0) or details
   uint32_t                    bSize,                // size of the buffer
   unsigned char              *b                     // output buffer
)
{
   const char                 *from = notReallyUnique;
   uint32_t                    retVal = 0;
   if(which == 0) // the authorities value
   {
       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++;
       }
   }
   return retVal;
}