Coverage Report

Created: 2025-08-28 06:05

/src/tpm2/Unique.c
Line
Count
Source (jump to first uncovered line)
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
251
{
31
251
   const char                 *from = notReallyUnique;
32
251
   uint32_t                    retVal = 0;
33
251
   if(which == 0) // the authorities value
34
0
   {
35
0
       for(retVal = 0;
36
0
           *from != 0 && retVal < bSize;
37
0
           retVal++)
38
0
       {
39
0
           *b++ = *from++;
40
0
       }
41
0
   }
42
251
   else
43
251
   {
44
251
#define uSize sizeof(notReallyUnique)
45
251
       b = &b[((bSize < uSize) ? bSize : uSize) - 1];
46
251
       for(retVal = 0;
47
16.3k
           *from != 0 && retVal < bSize;
48
16.0k
           retVal++)
49
16.0k
       {
50
16.0k
           *b-- = *from++;
51
16.0k
       }
52
251
   }
53
251
   return retVal;
54
251
}