xref: /netbsd-src/crypto/external/cpl/tpm-tools/dist/src/tpm_mgmt/tpm_nvcommon.h (revision 431955c163a358f3111f7be0c1fa1643cab0b701)
1 /*
2  * The Initial Developer of the Original Code is International
3  * Business Machines Corporation. Portions created by IBM
4  * Corporation are Copyright (C) 2005 International Business
5  * Machines Corporation. All Rights Reserved.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the Common Public License as published by
9  * IBM Corporation; either version 1 of the License, or (at your option)
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * Common Public License for more details.
16  *
17  * You should have received a copy of the Common Public License
18  * along with this program; if not, a copy can be viewed at
19  * http://www.opensource.org/licenses/cpl1.0.php.
20  */
21 #ifndef TPM_NVCOMMON_H
22 #define TPM_NVCOMMON_H
23 
24 #include "tpm_tspi.h"
25 
26 
27 struct strings_with_values
28 {
29 	const char *name;
30 	UINT32 value;
31 	const char *desc;
32 };
33 
34 extern const struct strings_with_values permvalues[];
35 
36 int parseStringWithValues(const char *aArg,
37                           const struct strings_with_values *svals,
38                           unsigned int *x, unsigned int maximum,
39                           const char *name);
40 
41 char *printValueAsStrings(unsigned int value,
42                           const struct strings_with_values *svals);
43 
44 int parseHexOrDecimal(const char *aArg, unsigned int *x,
45                       unsigned int minimum, unsigned int maximum,
46                       const char *name);
47 
48 void displayStringsAndValues(const struct strings_with_values *svals, const char *indent);
49 
50 TSS_RESULT getNVDataPublic(TSS_HTPM hTpm, TPM_NV_INDEX nvindex, TPM_NV_DATA_PUBLIC **pub);
51 void freeNVDataPublic(TPM_NV_DATA_PUBLIC *pub);
52 
53 static inline UINT32
Decode_UINT32(BYTE * y)54 Decode_UINT32(BYTE * y)
55 {
56         UINT32 x = 0;
57 
58         x = y[0];
59         x = ((x << 8) | (y[1] & 0xFF));
60         x = ((x << 8) | (y[2] & 0xFF));
61         x = ((x << 8) | (y[3] & 0xFF));
62 
63         return x;
64 }
65 
66 #endif /* TPM_NVCOMMON_H */
67