blob: 5f95f78f59dc4f1b67a96086cf4e003ae4d750f5 [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
31 // Read index info from NV
32 NvGetIndexInfo(in->nvIndex, &nvIndex);
33
34 // Remove any trailing zeros that might have been added by the caller
35 // to obfuscate the size.
36 MemoryRemoveTrailingZeros(&(in->newAuth));
37
38 // Make sure that the authValue is no larger than the nameAlg of the Index
39 if(in->newAuth.t.size > CryptGetHashDigestSize(nvIndex.publicArea.nameAlg))
40 return TPM_RC_SIZE + RC_NV_ChangeAuth_newAuth;
41
42// Internal Data Update
43 // Change auth
44 nvIndex.authValue = in->newAuth;
45 // Write index info back to NV
46 NvWriteIndexInfo(in->nvIndex, &nvIndex);
47
48 return TPM_RC_SUCCESS;
49}