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