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_Read_fp.h" |
10 | | #include "NV_spt_fp.h" |
11 | | // |
12 | | // |
13 | | // Error Returns Meaning |
14 | | // |
15 | | // TPM_RC_NV_AUTHORIZATION the authorization was valid but the authorizing entity (authHandle) is |
16 | | // not allowed to read from the Index referenced by nvIndex |
17 | | // TPM_RC_NV_LOCKED the Index referenced by nvIndex is read locked |
18 | | // TPM_RC_NV_RANGE read range defined by size and offset is outside the range of the |
19 | | // Index referenced by nvIndex |
20 | | // TPM_RC_NV_UNINITIALIZED the Index referenced by nvIndex has not been initialized (written) |
21 | | // |
22 | | TPM_RC |
23 | | TPM2_NV_Read( |
24 | | NV_Read_In *in, // IN: input parameter list |
25 | | NV_Read_Out *out // OUT: output parameter list |
26 | | ) |
27 | 0 | { |
28 | 0 | NV_INDEX nvIndex; |
29 | 0 | TPM_RC result; |
30 | | |
31 | | // Input Validation |
32 | | |
33 | | // Get NV index info |
34 | 0 | NvGetIndexInfo(in->nvIndex, &nvIndex); |
35 | | |
36 | | // Common read access checks. NvReadAccessChecks() returns |
37 | | // TPM_RC_NV_AUTHORIZATION, TPM_RC_NV_LOCKED, or TPM_RC_NV_UNINITIALIZED |
38 | | // error may be returned at this point |
39 | 0 | result = NvReadAccessChecks(in->authHandle, in->nvIndex); |
40 | 0 | if(result != TPM_RC_SUCCESS) |
41 | 0 | return result; |
42 | | |
43 | | // Make sure the data will fit the return buffer |
44 | 0 | if( in->size > MAX_NV_BUFFER_SIZE) |
45 | 0 | return TPM_RC_VALUE + RC_NV_Read_size; |
46 | | |
47 | | // Verify that the offset is not too large |
48 | 0 | if(in->offset > nvIndex.publicArea.dataSize) |
49 | 0 | return TPM_RC_VALUE + RC_NV_Read_offset; |
50 | | |
51 | | // Make sure that the selection is within the range of the Index |
52 | 0 | if(in->size > (nvIndex.publicArea.dataSize - in->offset)) |
53 | 0 | return TPM_RC_NV_RANGE; |
54 | | |
55 | | // Command Output |
56 | | |
57 | | // Set the return size |
58 | 0 | out->data.t.size = in->size; |
59 | | // Perform the read |
60 | 0 | NvGetIndexData(in->nvIndex, &nvIndex, in->offset, in->size, out->data.t.buffer); |
61 | |
|
62 | 0 | return TPM_RC_SUCCESS; |
63 | 0 | } |