• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stefanberger / libtpms / #2047

02 Jan 2026 05:02PM UTC coverage: 77.211% (-0.01%) from 77.225%
#2047

push

travis-ci

web-flow
Merge af9de2478 into 03ff2481e

1 of 1 new or added line in 1 file covered. (100.0%)

523 existing lines in 42 files now uncovered.

36060 of 46703 relevant lines covered (77.21%)

101760.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.95
/src/tpm2/CommandCodeAttributes.c
1
/********************************************************************************/
2
/*                                                                                */
3
/*                Functions for testing various command properties                */
4
/*                             Written by Ken Goldman                                */
5
/*                       IBM Thomas J. Watson Research Center                        */
6
/*                                                                                */
7
/*  Licenses and Notices                                                        */
8
/*                                                                                */
9
/*  1. Copyright Licenses:                                                        */
10
/*                                                                                */
11
/*  - Trusted Computing Group (TCG) grants to the user of the source code in        */
12
/*    this specification (the "Source Code") a worldwide, irrevocable,                 */
13
/*    nonexclusive, royalty free, copyright license to reproduce, create         */
14
/*    derivative works, distribute, display and perform the Source Code and        */
15
/*    derivative works thereof, and to grant others the rights granted herein.        */
16
/*                                                                                */
17
/*  - The TCG grants to the user of the other parts of the specification         */
18
/*    (other than the Source Code) the rights to reproduce, distribute,         */
19
/*    display, and perform the specification solely for the purpose of                 */
20
/*    developing products based on such documents.                                */
21
/*                                                                                */
22
/*  2. Source Code Distribution Conditions:                                        */
23
/*                                                                                */
24
/*  - Redistributions of Source Code must retain the above copyright licenses,         */
25
/*    this list of conditions and the following disclaimers.                        */
26
/*                                                                                */
27
/*  - Redistributions in binary form must reproduce the above copyright         */
28
/*    licenses, this list of conditions        and the following disclaimers in the         */
29
/*    documentation and/or other materials provided with the distribution.        */
30
/*                                                                                */
31
/*  3. Disclaimers:                                                                */
32
/*                                                                                */
33
/*  - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF        */
34
/*  LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH        */
35
/*  RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES)        */
36
/*  THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE.                */
37
/*  Contact TCG Administration (admin@trustedcomputinggroup.org) for                 */
38
/*  information on specification licensing rights available through TCG         */
39
/*  membership agreements.                                                        */
40
/*                                                                                */
41
/*  - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED         */
42
/*    WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR         */
43
/*    FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR                 */
44
/*    NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY                 */
45
/*    OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE.                */
46
/*                                                                                */
47
/*  - Without limitation, TCG and its members and licensors disclaim all         */
48
/*    liability, including liability for infringement of any proprietary         */
49
/*    rights, relating to use of information in this specification and to the        */
50
/*    implementation of this specification, and TCG disclaims all liability for        */
51
/*    cost of procurement of substitute goods or services, lost profits, loss         */
52
/*    of use, loss of data or any incidental, consequential, direct, indirect,         */
53
/*    or special damages, whether under contract, tort, warranty or otherwise,         */
54
/*    arising in any way out of use or reliance upon this specification or any         */
55
/*    information herein.                                                        */
56
/*                                                                                */
57
/*  (c) Copyright IBM Corp. and others, 2016 - 2023                                */
58
/*                                                                                */
59
/********************************************************************************/
60

61
/* 9.3 CommandCodeAttributes.c */
62
/* 9.3.1 Introduction */
63
/* This file contains the functions for testing various command properties. */
64
/* 9.3.2 Includes and Defines */
65
#include "Tpm.h"
66
#include "CommandCodeAttributes_fp.h"
67
/* Set the default value for CC_VEND if not already set */
68
#ifndef CC_VEND
69
#define     CC_VEND     (TPM_CC)(0x20000000)
70
#endif
71
typedef UINT16          ATTRIBUTE_TYPE;
72
/* The following file is produced from the command tables in part 3 of the specification. It defines
73
   the attributes for each of the commands. */
74
/* NOTE: This file is currently produced by an automated process. Files produced from Part 2 or Part
75
   3 tables through automated processes are not included in the specification so that there is no
76
   ambiguity about the table containing the information being the normative definition. */
77
#define _COMMAND_CODE_ATTRIBUTES_
78
#include    "CommandAttributeData.h"
79
/* 9.3.3 Command Attribute Functions */
80
/* 9.3.3.1 NextImplementedIndex() */
81
/* This function is used when the lists are not compressed. In a compressed list, only the
82
   implemented commands are present. So, a search might find a value but that value may not be
83
   implemented. This function checks to see if the input commandIndex points to an implemented
84
   command and, if not, it searches upwards until it finds one. When the list is compressed, this
85
   function gets defined as a no-op. */
86
/* Return Value        Meaning */
87
/* UNIMPLEMENTED_COMMAND_INDEX        command is not implemented */
88
/* other        index of the command */
89

90
#if !COMPRESSED_LISTS
91
static COMMAND_INDEX
92
NextImplementedIndex(
162✔
93
                     COMMAND_INDEX       commandIndex
94
                     )
95
{
96
    for(;commandIndex < COMMAND_COUNT; commandIndex++)
163✔
97
        {
98
            if((s_commandAttributes[commandIndex] & IS_IMPLEMENTED) &&                 // libtpms changed
326✔
99
               RuntimeCommandsCheckEnabled(&g_RuntimeProfile.RuntimeCommands,         // libtpms added begin
163✔
100
                                           GET_ATTRIBUTE(s_ccAttr[commandIndex],
163✔
101
                                                         TPMA_CC, commandIndex)))// libtpms added end
102
                return commandIndex;
162✔
103
        }
104
    return UNIMPLEMENTED_COMMAND_INDEX;
105
}
106
#else
107
#define NextImplementedIndex(x) (x)
108
#endif
109
/* 9.3.3.2 GetClosestCommandIndex() */
110
/* This function returns the command index for the command with a value that is equal to or greater
111
   than the input value */
112
/* Return Value        Meaning */
113
/* UNIMPLEMENTED_COMMAND_INDEX        command is not implemented */
114
/* other        index of the command */
115

116
COMMAND_INDEX
117
GetClosestCommandIndex(
174✔
118
                       TPM_CC           commandCode    // IN: the command code to start at
119
                       )
120
{
121
    BOOL                vendor = (commandCode & CC_VEND) != 0;
174✔
122
    COMMAND_INDEX       searchIndex = (COMMAND_INDEX)commandCode;
174✔
123
    // The commandCode is a UINT32 and the search index is UINT16. We are going to
124
    // search for a match but need to make sure that the commandCode value is not
125
    // out of range. To do this, need to clear the vendor bit of the commandCode
126
    // (if set) and compare the result to the 16-bit searchIndex value. If it is
127
    // out of range, indicate that the command is not implemented
128
    if((commandCode & ~CC_VEND) != searchIndex)
174✔
129
        return UNIMPLEMENTED_COMMAND_INDEX;
130
    // if there is at least one vendor command, the last entry in the array will
131
    // have the v bit set. If the input commandCode is larger than the last
132
    // vendor-command, then it is out of range.
133
    if(vendor)
162✔
134
        {
135
#if VENDOR_COMMAND_ARRAY_SIZE > 0
136
            COMMAND_INDEX       commandIndex;
137
            COMMAND_INDEX       min;
138
            COMMAND_INDEX       max;
139
            int                 diff;
140
#if LIBRARY_COMMAND_ARRAY_SIZE == COMMAND_COUNT
141
#error "Constants are not consistent."
142
#endif
143
            // Check to see if the value is equal to or below the minimum
144
            // entry.
145
            // Note: Put this check first so that the typical case of only one vendor-
146
            // specific command doesn't waste any more time.
147
            if(GET_ATTRIBUTE(s_ccAttr[LIBRARY_COMMAND_ARRAY_SIZE], TPMA_CC,
148
                             commandIndex) >= searchIndex)
149
                {
150
                    // the vendor array is always assumed to be packed so there is
151
                    // no need to check to see if the command is implemented
152
                    return LIBRARY_COMMAND_ARRAY_SIZE;
153
                }
154
            // See if this is out of range on the top
155
            if(GET_ATTRIBUTE(s_ccAttr[COMMAND_COUNT - 1], TPMA_CC, commandIndex)
156
               < searchIndex)
157
                {
158
                    return UNIMPLEMENTED_COMMAND_INDEX;
159
                }
160
            commandIndex = UNIMPLEMENTED_COMMAND_INDEX; // Needs initialization to keep
161
            // compiler happy
162
            min = LIBRARY_COMMAND_ARRAY_SIZE;       // first vendor command
163
            max = COMMAND_COUNT - 1;                // last vendor command
164
            diff = 1;                               // needs initialization to keep
165
            // compiler happy
166
            while(min <= max)
167
                {
168
                    commandIndex = (min + max + 1) / 2;
169
                    diff = GET_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, commandIndex)
170
                           - searchIndex;
171
                    if(diff == 0)
172
                        return commandIndex;
173
                    if(diff > 0)
174
                        max = commandIndex - 1;
175
                    else
176
                        min = commandIndex + 1;
177
                }
178
            // didn't find and exact match. commandIndex will be pointing at the last
179
            // item tested. If 'diff' is positive, then the last item tested was
180
            // larger index of the command code so it is the smallest value
181
            // larger than the requested value.
182
            if(diff > 0)
183
                return commandIndex;
184
            // if 'diff' is negative, then the value tested was smaller than
185
            // the commandCode index and the next higher value is the correct one.
186
            // Note: this will necessarily be in range because of the earlier check
187
            // that the index was within range.
188
            return commandIndex + 1;
189
#else
190
            // If there are no vendor commands so anything with the vendor bit set is out
191
            // of range
192
            return UNIMPLEMENTED_COMMAND_INDEX;
193
#endif
194
        }
195
    // Get here if the V-Bit was not set in 'commandCode'
196
    if(GET_ATTRIBUTE(s_ccAttr[LIBRARY_COMMAND_ARRAY_SIZE - 1], TPMA_CC,
162✔
197
                     commandIndex) < searchIndex)
198
        {
199
            // requested index is out of the range to the top
200
#if VENDOR_COMMAND_ARRAY_SIZE > 0
201
            // If there are vendor commands, then the first vendor command
202
            // is the next value greater than the commandCode.
203
            // NOTE: we got here if the starting index did not have the V bit but we
204
            // reached the end of the array of library commands (non-vendor). Since
205
            // there is at least one vendor command, and vendor commands are always
206
            // in a compressed list that starts after the library list, the next
207
            // index value contains a valid vendor command.
208
            return LIBRARY_COMMAND_ARRAY_SIZE;
209
#else
210
            // if there are no vendor commands, then this is out of range
211
            return UNIMPLEMENTED_COMMAND_INDEX;
212
#endif
213
        }
214
    // If the request is lower than any value in the array, then return
215
    // the lowest value (needs to be an index for an implemented command
216
    if(GET_ATTRIBUTE(s_ccAttr[0], TPMA_CC, commandIndex) >= searchIndex)
162✔
217
        {
218
            return NextImplementedIndex(0);
114✔
219
        }
220
    else
221
        {
222
#if COMPRESSED_LISTS
223
            COMMAND_INDEX       commandIndex = UNIMPLEMENTED_COMMAND_INDEX;
224
            COMMAND_INDEX       min = 0;
225
            COMMAND_INDEX       max = LIBRARY_COMMAND_ARRAY_SIZE - 1;
226
            int                 diff = 1;
227
#if LIBRARY_COMMAND_ARRAY_SIZE == 0
228
#error  "Something is terribly wrong"
229
#endif
230
            // The s_ccAttr array contains an extra entry at the end (a zero value).
231
            // Don't count this as an array entry. This means that max should start
232
            // out pointing to the last valid entry in the array which is - 2
233
            pAssert(max == (sizeof(s_ccAttr) / sizeof(TPMA_CC)
234
                            - VENDOR_COMMAND_ARRAY_SIZE - 2));
235
            while(min <= max)
236
                {
237
                    commandIndex = (min + max + 1) / 2;
238
                    diff = GET_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC,
239
                                         commandIndex) - searchIndex;
240
                    if(diff == 0)
241
                        return commandIndex;
242
                    if(diff > 0)
243
                        max = commandIndex - 1;
244
                    else
245
                        min = commandIndex + 1;
246
                }
247
            // didn't find and exact match. commandIndex will be pointing at the
248
            // last item tested. If diff is positive, then the last item tested was
249
            // larger index of the command code so it is the smallest value
250
            // larger than the requested value.
251
            if(diff > 0)
252
                return commandIndex;
253
            // if diff is negative, then the value tested was smaller than
254
            // the commandCode index and the next higher value is the correct one.
255
            // Note: this will necessarily be in range because of the earlier check
256
            // that the index was within range.
257
            return commandIndex + 1;
258
#else
259
            // The list is not compressed so offset into the array by the command
260
            // code value of the first entry in the list. Then go find the first
261
            // implemented command.
262
            return NextImplementedIndex(searchIndex
48✔
263
                                        - (COMMAND_INDEX)GET_ATTRIBUTE(s_ccAttr[0], TPMA_CC, commandIndex)); // libtpms changed
48✔
264
#endif
265
        }
266
}
267
/* 9.3.3.3 CommandCodeToComandIndex() */
268
/* This function returns the index in the various attributes arrays of the command. */
269
/* Return Values Meaning */
270
/* UNIMPLEMENTED_COMMAND_INDEX command is not implemented */
271
/* other index of the command */
272
COMMAND_INDEX
273
CommandCodeToCommandIndex(
22,006✔
274
                          TPM_CC           commandCode    // IN: the command code to look up
275
                          )
276
{
277
    // Extract the low 16-bits of the command code to get the starting search index
278
    COMMAND_INDEX       searchIndex = (COMMAND_INDEX)commandCode;
22,006✔
279
    BOOL                vendor = (commandCode & CC_VEND) != 0;
22,006✔
280
    COMMAND_INDEX       commandIndex;
22,006✔
281
#if !COMPRESSED_LISTS
282
    if(!vendor)
22,006✔
283
        {
284
            commandIndex = searchIndex - (COMMAND_INDEX)GET_ATTRIBUTE(s_ccAttr[0], TPMA_CC, commandIndex); // libtpms changed
22,006✔
285
            // Check for out of range or unimplemented.
286
            // Note, since a COMMAND_INDEX is unsigned, if searchIndex is smaller than
287
            // the lowest value of command, it will become a 'negative' number making
288
            // it look like a large unsigned number, this will cause it to fail
289
            // the unsigned check below.
290
            if(commandIndex >= LIBRARY_COMMAND_ARRAY_SIZE
22,006✔
291
               || (s_commandAttributes[commandIndex] & IS_IMPLEMENTED) == 0
22,001✔
292
               || !RuntimeCommandsCheckEnabled(&g_RuntimeProfile.RuntimeCommands,// libtpms added
22,001✔
293
                                               commandCode))                         // libtpms added
294
                return UNIMPLEMENTED_COMMAND_INDEX;
7✔
295
            return commandIndex;
296
        }
297
#endif
298
    // Need this code for any vendor code lookup or for compressed lists
UNCOV
299
    commandIndex = GetClosestCommandIndex(commandCode);
×
300
    // Look at the returned value from get closest. If it isn't the one that was
301
    // requested, then the command is not implemented.
302
    // libtpms: Or it may be runtime-disabled
UNCOV
303
    if(commandIndex != UNIMPLEMENTED_COMMAND_INDEX)
×
304
        {
UNCOV
305
            if((GET_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, commandIndex)
×
306
                != searchIndex)
307
               || (IS_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, V)) != vendor
×
UNCOV
308
               || !RuntimeCommandsCheckEnabled(&g_RuntimeProfile.RuntimeCommands,// libtpms added
×
309
                                               commandCode))                         // libtpms added
310
                commandIndex = UNIMPLEMENTED_COMMAND_INDEX;
311
        }
312
    return commandIndex;
313
}
314
/* 9.3.3.4 GetNextCommandIndex() */
315
/* This function returns the index of the next implemented command. */
316
/* Return Values Meaning */
317
/* UNIMPLEMENTED_COMMAND_INDEX no more implemented commands */
318
/* other the index of the next implemented command */
319
COMMAND_INDEX
320
GetNextCommandIndex(
10,782✔
321
                    COMMAND_INDEX    commandIndex   // IN: the starting index
322
                    )
323
{
324
    while(++commandIndex < COMMAND_COUNT)
12,937✔
325
        {
326
            if(!RuntimeCommandsCheckEnabled(&g_RuntimeProfile.RuntimeCommands,          // libtpms added begin
12,816✔
327
                                            GET_ATTRIBUTE(s_ccAttr[commandIndex],
12,816✔
328
                                                          TPMA_CC, commandIndex)))
329
                continue;                                                          // libtpms added end
2,155✔
330
#if !COMPRESSED_LISTS
331
            if(s_commandAttributes[commandIndex] & IS_IMPLEMENTED)
10,661✔
332
#endif
333
                return commandIndex;
10,661✔
334
        }
335
    return UNIMPLEMENTED_COMMAND_INDEX;
336
}
337
/* 9.3.3.5 GetCommandCode() */
338
/* This function returns the commandCode associated with the command index */
339
TPM_CC
340
GetCommandCode(
57✔
341
               COMMAND_INDEX    commandIndex   // IN: the command index
342
               )
343
{
344
    TPM_CC           commandCode = GET_ATTRIBUTE(s_ccAttr[commandIndex],
57✔
345
                                                 TPMA_CC, commandIndex);
346
    if(IS_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, V))
57✔
UNCOV
347
        commandCode += CC_VEND;
×
348
    return commandCode;
57✔
349
}
350
/* 9.3.3.6 CommandAuthRole() */
351
/* This function returns the authorization role required of a handle. */
352
/* Return Values Meaning */
353
/* AUTH_NONE no authorization is required */
354
/* AUTH_USER user role authorization is required */
355
/* AUTH_ADMIN admin role authorization is required */
356
/* AUTH_DUP duplication role authorization is required */
357
AUTH_ROLE
358
CommandAuthRole(
17,385✔
359
                COMMAND_INDEX    commandIndex,  // IN: command index
360
                UINT32           handleIndex    // IN: handle index (zero based)
361
                )
362
{
363
    if(0 == handleIndex)
17,385✔
364
        {
365
            // Any authorization role set?
366
            COMMAND_ATTRIBUTES  properties = s_commandAttributes[commandIndex];
14,232✔
367
            if(properties & HANDLE_1_USER)
14,232✔
368
                return AUTH_USER;
369
            if(properties & HANDLE_1_ADMIN)
2,627✔
370
                return AUTH_ADMIN;
371
            if(properties & HANDLE_1_DUP)
2,058✔
372
                return AUTH_DUP;
33✔
373
        }
374
    else if(1 == handleIndex)
3,153✔
375
        {
376
            if(s_commandAttributes[commandIndex] & HANDLE_2_USER)
3,047✔
377
                return AUTH_USER;
825✔
378
        }
379
    return AUTH_NONE;
380
}
381
/* 9.3.3.7 EncryptSize() */
382
/* This function returns the size of the decrypt size field. This function returns 0 if encryption
383
   is not allowed */
384
/* Return Values Meaning */
385
/* 0 encryption not allowed */
386
/* 2 size field is two bytes */
387
/* 4 size field is four bytes */
388

389
int
390
EncryptSize(
306✔
391
            COMMAND_INDEX    commandIndex   // IN: command index
392
            )
393
{
394
    return ((s_commandAttributes[commandIndex] & ENCRYPT_2) ? 2 :
306✔
UNCOV
395
            (s_commandAttributes[commandIndex] & ENCRYPT_4) ? 4 : 0);
×
396
}
397

398
/* 9.3.3.8 DecryptSize() */
399
/* This function returns the size of the decrypt size field. This function returns 0 if decryption
400
   is not allowed */
401
/* Return Values Meaning */
402
/* 0 encryption not allowed */
403
/* 2 size field is two bytes */
404
/* 4 size field is four bytes */
405

406
int
407
DecryptSize(
322✔
408
            COMMAND_INDEX    commandIndex   // IN: command index
409
            )
410
{
411
    return ((s_commandAttributes[commandIndex] & DECRYPT_2) ? 2 :
322✔
UNCOV
412
            (s_commandAttributes[commandIndex] & DECRYPT_4) ? 4 : 0);
×
413
}
414

415
/* 9.3.3.9 IsSessionAllowed() */
416
/* This function indicates if the command is allowed to have sessions. */
417
/* This function must not be called if the command is not known to be implemented. */
418
/* Return Values Meaning */
419
/* TRUE session is allowed with this command */
420
/* FALSE session is not allowed with this command */
421

422
BOOL
423
IsSessionAllowed(
20,643✔
424
                 COMMAND_INDEX    commandIndex   // IN: the command to be checked
425
                 )
426
{
427
    return ((s_commandAttributes[commandIndex] & NO_SESSIONS) == 0);
20,643✔
428
}
429

430
/* 9.3.3.10 IsHandleInResponse() */
431
/* This function determines if a command has a handle in the response */
432

433
BOOL
434
IsHandleInResponse(
16,390✔
435
                   COMMAND_INDEX    commandIndex
436
                   )
437
{
438
    return ((s_commandAttributes[commandIndex] & R_HANDLE) != 0);
16,390✔
439
}
440

441
/* 9.3.3.11 IsWriteOperation() */
442
/* Checks to see if an operation will write to an NV Index and is subject to being blocked by
443
   read-lock */
444
BOOL
445
IsWriteOperation(
532✔
446
                 COMMAND_INDEX    commandIndex   // IN: Command to check
447
                 )
448
{
449
#ifdef  WRITE_LOCK
450
    return ((s_commandAttributes[commandIndex] & WRITE_LOCK) != 0);
451
#else
452
    if(!IS_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, V))
532✔
453
        {
454
            switch(GET_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, commandIndex))
532✔
455
                {
456
                  case TPM_CC_NV_Write:
242✔
457
#if CC_NV_Increment
458
                  case TPM_CC_NV_Increment:
459
#endif
460
#if CC_NV_SetBits
461
                  case TPM_CC_NV_SetBits:
462
#endif
463
#if CC_NV_Extend
464
                  case TPM_CC_NV_Extend:
465
#endif
466
#if CC_AC_Send
467
                  case TPM_CC_AC_Send:
468
#endif
469
                    // NV write lock counts as a write operation for authorization purposes.
470
                    // We check to see if the NV is write locked before we do the
471
                    // authorization. If it is locked, we fail the command early.
472
                  case TPM_CC_NV_WriteLock:
473
                    return TRUE;
242✔
474
                  default:
475
                    break;
476
                }
477
        }
478
    return FALSE;
479
#endif
480
}
481
/* 9.3.3.12 IsReadOperation() */
482
/* Checks to see if an operation will write to an NV Index and is subject to being blocked by
483
   write-lock. */
484
BOOL
UNCOV
485
IsReadOperation(
×
486
                COMMAND_INDEX    commandIndex   // IN: Command to check
487
                )
488
{
489
#ifdef  READ_LOCK
490
    return ((s_commandAttributes[commandIndex] & READ_LOCK) != 0);
491
#else
UNCOV
492
    if(!IS_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, V))
×
493
        {
494
            switch(GET_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, commandIndex))
×
495
                {
496
                  case TPM_CC_NV_Read:
×
497
                  case TPM_CC_PolicyNV:
498
                  case TPM_CC_NV_Certify:
499
                    // NV read lock counts as a read operation for authorization purposes.
500
                    // We check to see if the NV is read locked before we do the
501
                    // authorization. If it is locked, we fail the command early.
502
                  case TPM_CC_NV_ReadLock:
UNCOV
503
                    return TRUE;
×
504
                  default:
505
                    break;
506
                }
507
        }
508
    return FALSE;
509
#endif
510
}
511
/* 9.3.3.13 CommandCapGetCCList() */
512
/* This function returns a list of implemented commands and command attributes starting from the
513
   command in commandCode. */
514
/* Return Values Meaning */
515
/* YES more command attributes are available */
516
/* NO no more command attributes are available */
517
TPMI_YES_NO
518
CommandCapGetCCList(
46✔
519
                    TPM_CC           commandCode,   // IN: start command code
520
                    UINT32           count,         // IN: maximum count for number of entries in
521
                    //     'commandList'
522
                    TPML_CCA        *commandList    // OUT: list of TPMA_CC
523
                    )
524
{
525
    TPMI_YES_NO      more = NO;
46✔
526
    COMMAND_INDEX    commandIndex;
46✔
527
    // initialize output handle list count
528
    commandList->count = 0;
46✔
529
    for(commandIndex = GetClosestCommandIndex(commandCode);
46✔
530
        commandIndex != UNIMPLEMENTED_COMMAND_INDEX;
1,296✔
531
        commandIndex = GetNextCommandIndex(commandIndex))
1,250✔
532
        {
533
#if !COMPRESSED_LISTS
534
            // this check isn't needed for compressed lists.
535
            if(!(s_commandAttributes[commandIndex] & IS_IMPLEMENTED))
1,283✔
UNCOV
536
                continue;
×
537
#endif
538
            if (!RuntimeCommandsCheckEnabled(&g_RuntimeProfile.RuntimeCommands,        // libtpms added begin
1,283✔
539
                                             GET_ATTRIBUTE(s_ccAttr[commandIndex],
1,283✔
540
                                                           TPMA_CC, commandIndex)))
UNCOV
541
                continue;                                                        // libtpms added end
×
542
            if(commandList->count < count)
1,283✔
543
                {
544
                    // If the list is not full, add the attributes for this command.
545
                    commandList->commandAttributes[commandList->count]
1,250✔
546
                        = s_ccAttr[commandIndex];
1,250✔
547
                    commandList->count++;
1,250✔
548
                }
549
            else
550
                {
551
                    // If the list is full but there are more commands to report,
552
                    // indicate this and return.
553
                    more = YES;
554
                    break;
555
                }
556
        }
557
    return more;
46✔
558
}
559
//*** CommandCapGetOneCC()
560
// This function checks whether a command is implemented, and returns its
561
// attributes if so.
UNCOV
562
BOOL CommandCapGetOneCC(TPM_CC   commandCode,       // IN: command code
×
563
                        TPMA_CC* commandAttributes  // OUT: command attributes
564
                        )
565
{
UNCOV
566
    COMMAND_INDEX commandIndex = CommandCodeToCommandIndex(commandCode);
×
567
    if(commandIndex != UNIMPLEMENTED_COMMAND_INDEX)
×
568
        {
UNCOV
569
            *commandAttributes = s_ccAttr[commandIndex];
×
UNCOV
570
            return TRUE;
×
571
        }
572
    return FALSE;
573
}
574
#if 0 /* libtpms added */
575
/* 9.3.3.14 IsVendorCommand() */
576
/* Function indicates if a command index references a vendor command. */
577
/* Return Values Meaning */
578
/* TRUE command is a vendor command */
579
/* FALSE command is not a vendor command */
580

581
BOOL
582
IsVendorCommand(
583
                COMMAND_INDEX    commandIndex   // IN: command index to check
584
                )
585
{
586
    return (IS_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, V));
587
}
588
#endif /* libtpms added */
589

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc