VirtualBox

source: vbox/trunk/src/libs/libtpms-0.10.0/tests/nvram_offsets.c

Last change on this file was 108932, checked in by vboxsync, 5 weeks ago

libtpms-0.10.0: Applied and adjusted our libtpms changes to 0.9.6. jiraref:VBP-1320

File size: 3.5 KB
Line 
1#include <assert.h>
2#include <stdlib.h>
3
4#include "Tpm.h"
5
6/* from Global.h */
7extern BYTE s_indexOrderlyRam[RAM_INDEX_SPACE];
8
9int main(void)
10{
11 PERSISTENT_DATA pd;
12
13 /* Check size of ppList that expands with new commands */
14 /* was 14 when COMPRESSED_LISTS was enabled */
15#define PD_PP_LIST_EXP_SIZE 17
16 if (sizeof(pd.ppList) != PD_PP_LIST_EXP_SIZE) {
17 fprintf(stderr,
18 "sizeof(PERSISTENT_DATA.ppList) does not have expected size "
19 "of %u bytes but %zu bytes\n",
20 PD_PP_LIST_EXP_SIZE, sizeof(pd.ppList));
21 return EXIT_FAILURE;
22 }
23
24 /* Check size of auditCommands that expands with new commands */
25 /* was 14 when COMPRESSED_LISTS was enabled */
26#define PD_AUDIT_COMMANDS_EXP_SIZE 17
27 if (sizeof(pd.auditCommands) != PD_AUDIT_COMMANDS_EXP_SIZE) {
28 fprintf(stderr,
29 "sizeof(PERSISTENT_DATA.auditCommands) does not have expected size "
30 "of %u bytes but %zu bytes\n",
31 PD_AUDIT_COMMANDS_EXP_SIZE, sizeof(pd.auditCommands));
32 return EXIT_FAILURE;
33 }
34
35 /* ensure that the NVRAM offset of NV_USER_DYNAMIC is at the expected
36 location so that there's enough memory for re-constructing NVRAM
37 indices etc. into the NVRAM */
38#define NV_INDEX_RAM_DATA_EXP_OFFSET 5120
39 if (NV_INDEX_RAM_DATA != NV_INDEX_RAM_DATA_EXP_OFFSET) {
40 /* If this ever changes due to growth of the preceding data
41 * structure, we need to adjust the total NVRAM memory size
42 * for the architecture where this changed (or have all
43 * architectures use the same offset.
44 */
45 fprintf(stderr,
46 "NV_INDEX_RAM_DATA not at expected offset %u but at %u\n",
47 NV_INDEX_RAM_DATA_EXP_OFFSET, (unsigned int)NV_INDEX_RAM_DATA);
48 return EXIT_FAILURE;
49 }
50
51#define NV_USER_DYNAMIC_EXP_OFFSET (5120 + 512)
52 if (NV_USER_DYNAMIC != NV_USER_DYNAMIC_EXP_OFFSET) {
53 fprintf(stderr,
54 "NV_USER_DYNAMIC not at expected offset %u but at %u\n",
55 NV_USER_DYNAMIC_EXP_OFFSET, (unsigned int)NV_USER_DYNAMIC);
56 return EXIT_FAILURE;
57 }
58
59 /*
60 * OBJECTs are directly written into NVRAM. We have to make sure that the
61 * size of the OBJECT is the same on all architectures so that a full
62 * NVRAM fits on all architectures
63 */
64#if RSA_4096
65# error Unsupported RSA key size
66#elif RSA_3072
67# define OBJECT_EXP_SIZE 2608
68#elif RSA_2048
69# define OBJECT_EXP_SIZE 1896
70#endif
71 if (sizeof(OBJECT) != OBJECT_EXP_SIZE) {
72 fprintf(stderr, "sizeof(OBJECT) does not have expected size of %u bytes"
73 "but %zu bytes\n", OBJECT_EXP_SIZE, sizeof(OBJECT));
74 fprintf(stderr, "sizeof(TPMT_PUBLIC) is now %zu bytes;"
75 "was 356/484 bytes for 2048/3072 bit RSA keys\n", sizeof(TPMT_PUBLIC));
76 fprintf(stderr, "sizeof(TPMT_SENSITIVE) is now %zu bytes;"
77 "was 776/1096 bytes for 2048/3072 bit RSA keys\n", sizeof(TPMT_SENSITIVE));
78 fprintf(stderr, "sizeof(privateExponent_t) is now %zu bytes;"
79 "was 608/864 bytes for 2048/3072 bit RSA keys\n", sizeof(privateExponent_t));
80 return EXIT_FAILURE;
81 }
82
83 /* Same for NV_INDEX */
84#define NV_INDEX_EXP_SIZE 148
85 if (sizeof(NV_INDEX) != NV_INDEX_EXP_SIZE) {
86 fprintf(stderr,
87 "sizeof(NV_INDEX) does not have expected size of %u bytes"
88 "but %zu bytes\n", NV_INDEX_EXP_SIZE, sizeof(NV_INDEX));
89 return EXIT_FAILURE;
90 }
91
92 return EXIT_SUCCESS;
93}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette