blob: 1adf148213808580fe3ebb55e13144984dacf913 [file] [log] [blame]
Vadim Bendebury56797522015-05-20 10:32:25 -07001// 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_ChangeAuth_fp.h"
10//
11//
12// Error Returns Meaning
13//
14// TPM_RC_SIZE newAuth size is larger than the digest size of the Name algorithm for
15// the Index referenced by 'nvIndex
16//
17TPM_RC
18TPM2_NV_ChangeAuth(
19 NV_ChangeAuth_In *in // IN: input parameter list
20 )
21{
22 TPM_RC result;
23 NV_INDEX nvIndex;
24
25// Input Validation
26 // Check if NV is available. NvIsAvailable may return TPM_RC_NV_UNAVAILABLE
27 // TPM_RC_NV_RATE or TPM_RC_SUCCESS.
28 result = NvIsAvailable();
29 if(result != TPM_RC_SUCCESS) return result;
30
Louis Collard5cb743a2018-06-26 20:07:49 +080031 // Auth for Indexes in the virtual range cannot be changed.
32 if (_plat__NvGetHandleVirtualOffset(in->nvIndex))
33 return TPM_RC_NV_AUTHORIZATION;
34
Vadim Bendebury56797522015-05-20 10:32:25 -070035 // Read index info from NV
36 NvGetIndexInfo(in->nvIndex, &nvIndex);
37
38 // Remove any trailing zeros that might have been added by the caller
39 // to obfuscate the size.
40 MemoryRemoveTrailingZeros(&(in->newAuth));
41
42 // Make sure that the authValue is no larger than the nameAlg of the Index
43 if(in->newAuth.t.size > CryptGetHashDigestSize(nvIndex.publicArea.nameAlg))
44 return TPM_RC_SIZE + RC_NV_ChangeAuth_newAuth;
45
46// Internal Data Update
47 // Change auth
48 nvIndex.authValue = in->newAuth;
49 // Write index info back to NV
50 NvWriteIndexInfo(in->nvIndex, &nvIndex);
51
52 return TPM_RC_SUCCESS;
53}