/src/tpm2/NV_UndefineSpace.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 3: Commands |
4 | | // Family "2.0" |
5 | | // Level 00 Revision 01.16 |
6 | | // October 30, 2014 |
7 | | |
8 | | #include "InternalRoutines.h" |
9 | | #include "NV_UndefineSpace_fp.h" |
10 | | // |
11 | | // |
12 | | // Error Returns Meaning |
13 | | // |
14 | | // TPM_RC_ATTRIBUTES TPMA_NV_POLICY_DELETE is SET in the Index referenced by |
15 | | // nvIndex so this command may not be used to delete this Index (see |
16 | | // TPM2_NV_UndefineSpaceSpecial()) |
17 | | // TPM_RC_NV_AUTHORIZATION attempt to use ownerAuth to delete an index created by the platform |
18 | | // |
19 | | TPM_RC |
20 | | TPM2_NV_UndefineSpace( |
21 | | NV_UndefineSpace_In *in // IN: input parameter list |
22 | | ) |
23 | 0 | { |
24 | 0 | TPM_RC result; |
25 | 0 | NV_INDEX nvIndex; |
26 | | |
27 | | // The command needs NV update. Check if NV is available. |
28 | | // A TPM_RC_NV_UNAVAILABLE or TPM_RC_NV_RATE error may be returned at |
29 | | // this point |
30 | 0 | result = NvIsAvailable(); |
31 | 0 | if(result != TPM_RC_SUCCESS) return result; |
32 | | |
33 | | // Indexes in the virtual range cannot be undefined. |
34 | 0 | if (_plat__NvGetHandleVirtualOffset(in->nvIndex)) |
35 | 0 | return TPM_RC_NV_AUTHORIZATION; |
36 | | |
37 | | // Check if there are platform-specific reasons to prohibit updating this |
38 | | // index. |
39 | 0 | if (!_plat__NvUpdateAllowed(in->nvIndex)) |
40 | 0 | return TPM_RC_NV_AUTHORIZATION; |
41 | | |
42 | | // Input Validation |
43 | | |
44 | | // Get NV index info |
45 | 0 | NvGetIndexInfo(in->nvIndex, &nvIndex); |
46 | | |
47 | | // This command can't be used to delete an index with TPMA_NV_POLICY_DELETE SET |
48 | 0 | if(SET == nvIndex.publicArea.attributes.TPMA_NV_POLICY_DELETE) |
49 | 0 | return TPM_RC_ATTRIBUTES + RC_NV_UndefineSpace_nvIndex; |
50 | | |
51 | | // The owner may only delete an index that was defined with ownerAuth. The |
52 | | // platform may delete an index that was created with either auth. |
53 | 0 | if( in->authHandle == TPM_RH_OWNER |
54 | 0 | && nvIndex.publicArea.attributes.TPMA_NV_PLATFORMCREATE == SET) |
55 | 0 | return TPM_RC_NV_AUTHORIZATION; |
56 | | |
57 | | // Internal Data Update |
58 | | |
59 | | // Call implementation dependent internal routine to delete NV index |
60 | 0 | NvDeleteEntity(in->nvIndex); |
61 | |
|
62 | 0 | return TPM_RC_SUCCESS; |
63 | 0 | } |