summaryrefslogtreecommitdiff
path: root/tests/tpm_lite
diff options
context:
space:
mode:
authorJoel Kitching <kitching@google.com>2018-08-02 16:21:17 +0800
committerchrome-bot <chrome-bot@chromium.org>2018-08-03 01:31:21 -0700
commit9ad8a41b8cedef9ac1f0513992ce6958eb86c257 (patch)
tree2a1fe0e028829dc579840dce386047ce661ac6d3 /tests/tpm_lite
parentc239374ac3e1af342c10f4f3244bc98d76c2413a (diff)
downloadvboot-9ad8a41b8cedef9ac1f0513992ce6958eb86c257.tar.gz
vboot: bulk fix tabs and spacing inconsistency
Problem files were found with: find . -name '*.c' -o -name '*.h' | xargs grep '^ [^*]' and edited manually. Ignores utility/ and cgpt/, since they seem to globally adhere to a two-space tab convention. BUG=None TEST=make clean runtests TEST=emerge vboot_reference depthcharge Change-Id: I5a678484a119c8f1911f717e1968bdb4f1a0810f Reviewed-on: https://chromium-review.googlesource.com/1160131 Commit-Ready: Joel Kitching <kitching@chromium.org> Tested-by: Joel Kitching <kitching@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'tests/tpm_lite')
-rw-r--r--tests/tpm_lite/lock.c14
-rw-r--r--tests/tpm_lite/readonly.c134
-rw-r--r--tests/tpm_lite/startup.c36
-rw-r--r--tests/tpm_lite/tlcl_tests.c24
-rw-r--r--tests/tpm_lite/tlcl_tests.h16
-rw-r--r--tests/tpm_lite/tpmtest_earlyextend.c16
-rw-r--r--tests/tpm_lite/tpmtest_earlynvram.c16
-rw-r--r--tests/tpm_lite/tpmtest_earlynvram2.c16
-rw-r--r--tests/tpm_lite/tpmtest_enable.c32
-rw-r--r--tests/tpm_lite/tpmtest_fastenable.c42
-rw-r--r--tests/tpm_lite/tpmtest_globallock.c72
-rw-r--r--tests/tpm_lite/tpmtest_redefine_unowned.c68
-rw-r--r--tests/tpm_lite/tpmtest_spaceperm.c22
-rw-r--r--tests/tpm_lite/tpmtest_testsetup.c54
-rw-r--r--tests/tpm_lite/tpmtest_timing.c82
-rw-r--r--tests/tpm_lite/tpmtest_writelimit.c74
16 files changed, 364 insertions, 354 deletions
diff --git a/tests/tpm_lite/lock.c b/tests/tpm_lite/lock.c
index 2fd21b7e..bfc10e2e 100644
--- a/tests/tpm_lite/lock.c
+++ b/tests/tpm_lite/lock.c
@@ -15,15 +15,15 @@
int main(int argc, char** argv) {
- TlclLibInit();
+ TlclLibInit();
- TlclStartup();
- TlclSelfTestFull();
+ TlclStartup();
+ TlclSelfTestFull();
- TlclAssertPhysicalPresence();
+ TlclAssertPhysicalPresence();
- TlclWriteLock(INDEX0);
+ TlclWriteLock(INDEX0);
- printf("Locked 0x%x\n", INDEX0);
- exit(0);
+ printf("Locked 0x%x\n", INDEX0);
+ exit(0);
}
diff --git a/tests/tpm_lite/readonly.c b/tests/tpm_lite/readonly.c
index 97b90917..c3940e12 100644
--- a/tests/tpm_lite/readonly.c
+++ b/tests/tpm_lite/readonly.c
@@ -34,76 +34,82 @@
* of making this FUBAR).
*/
void InitializeSpaces(void) {
- uint32_t zero = 0;
- uint32_t perm = TPM_NV_PER_WRITE_STCLEAR | TPM_NV_PER_PPWRITE;
-
- printf("Initializing spaces\n");
- TlclSetNvLocked(); /* useful only the first time */
-
- TlclDefineSpace(INDEX0, perm, 4);
- TlclWrite(INDEX0, (uint8_t *) &zero, 4);
- TlclDefineSpace(INDEX1, perm, 4);
- TlclWrite(INDEX1, (uint8_t *) &zero, 4);
- TlclDefineSpace(INDEX2, perm, 4);
- TlclWrite(INDEX2, (uint8_t *) &zero, 4);
- TlclDefineSpace(INDEX3, perm, 4);
- TlclWrite(INDEX3, (uint8_t *) &zero, 4);
-
- perm = TPM_NV_PER_READ_STCLEAR | TPM_NV_PER_WRITE_STCLEAR |
- TPM_NV_PER_PPWRITE;
- TlclDefineSpace(INDEX_INITIALIZED, perm, 1);
+ uint32_t zero = 0;
+ uint32_t perm = TPM_NV_PER_WRITE_STCLEAR | TPM_NV_PER_PPWRITE;
+
+ printf("Initializing spaces\n");
+ TlclSetNvLocked(); /* useful only the first time */
+
+ TlclDefineSpace(INDEX0, perm, 4);
+ TlclWrite(INDEX0, (uint8_t *) &zero, 4);
+ TlclDefineSpace(INDEX1, perm, 4);
+ TlclWrite(INDEX1, (uint8_t *) &zero, 4);
+ TlclDefineSpace(INDEX2, perm, 4);
+ TlclWrite(INDEX2, (uint8_t *) &zero, 4);
+ TlclDefineSpace(INDEX3, perm, 4);
+ TlclWrite(INDEX3, (uint8_t *) &zero, 4);
+
+ perm = (TPM_NV_PER_READ_STCLEAR | TPM_NV_PER_WRITE_STCLEAR |
+ TPM_NV_PER_PPWRITE);
+ TlclDefineSpace(INDEX_INITIALIZED, perm, 1);
}
void EnterRecoveryMode(void) {
- printf("entering recovery mode");
- exit(0);
+ printf("entering recovery mode");
+ exit(0);
}
int main(int argc, char** argv) {
- uint8_t c;
- uint32_t index_0, index_1, index_2, index_3;
-
- TlclLibInit();
-
- TlclStartup();
- TlclSelfTestFull();
-
- TlclAssertPhysicalPresence();
-
- /* Checks if initialization has completed by trying to read-lock a space
- * that's created at the end of initialization.
- */
- if (TlclRead(INDEX_INITIALIZED, &c, 0) == TPM_E_BADINDEX) {
- /* The initialization did not complete.
- */
- InitializeSpaces();
- }
-
- /* Checks if spaces are OK or messed up.
- */
- if (TlclRead(INDEX0, (uint8_t*) &index_0, sizeof(index_0)) != TPM_SUCCESS ||
- TlclRead(INDEX1, (uint8_t*) &index_1, sizeof(index_1)) != TPM_SUCCESS ||
- TlclRead(INDEX2, (uint8_t*) &index_2, sizeof(index_2)) != TPM_SUCCESS ||
- TlclRead(INDEX3, (uint8_t*) &index_3, sizeof(index_3)) != TPM_SUCCESS) {
- EnterRecoveryMode();
- }
-
- /* Writes space, and locks it. Then attempts to write again. I really wish
- * I could use the imperative.
- */
- index_0 += 1;
- if (TlclWrite(INDEX0, (uint8_t*) &index_0, sizeof(index_0) != TPM_SUCCESS)) {
- error("could not write index 0\n");
- }
- TlclWriteLock(INDEX0);
- if (TlclWrite(INDEX0, (uint8_t*) &index_0, sizeof(index_0)) == TPM_SUCCESS) {
- error("index 0 is not locked\n");
- }
-
- /* Done for now.
- */
- printf("TEST SUCCEEDED\n");
- exit(0);
+ uint8_t c;
+ uint32_t index_0, index_1, index_2, index_3;
+
+ TlclLibInit();
+
+ TlclStartup();
+ TlclSelfTestFull();
+
+ TlclAssertPhysicalPresence();
+
+ /* Checks if initialization has completed by trying to read-lock a space
+ * that's created at the end of initialization.
+ */
+ if (TlclRead(INDEX_INITIALIZED, &c, 0) == TPM_E_BADINDEX) {
+ /* The initialization did not complete.
+ */
+ InitializeSpaces();
+ }
+
+ /* Checks if spaces are OK or messed up.
+ */
+ if (TlclRead(INDEX0, (uint8_t*) &index_0,
+ sizeof(index_0)) != TPM_SUCCESS ||
+ TlclRead(INDEX1, (uint8_t*) &index_1,
+ sizeof(index_1)) != TPM_SUCCESS ||
+ TlclRead(INDEX2, (uint8_t*) &index_2,
+ sizeof(index_2)) != TPM_SUCCESS ||
+ TlclRead(INDEX3, (uint8_t*) &index_3,
+ sizeof(index_3)) != TPM_SUCCESS) {
+ EnterRecoveryMode();
+ }
+
+ /* Writes space, and locks it. Then attempts to write again. I really wish
+ * I could use the imperative.
+ */
+ index_0 += 1;
+ if (TlclWrite(INDEX0, (uint8_t*) &index_0,
+ sizeof(index_0) != TPM_SUCCESS)) {
+ error("could not write index 0\n");
+ }
+ TlclWriteLock(INDEX0);
+ if (TlclWrite(INDEX0, (uint8_t*) &index_0,
+ sizeof(index_0)) == TPM_SUCCESS) {
+ error("index 0 is not locked\n");
+ }
+
+ /* Done for now.
+ */
+ printf("TEST SUCCEEDED\n");
+ exit(0);
}
diff --git a/tests/tpm_lite/startup.c b/tests/tpm_lite/startup.c
index 532ba8dd..3d901f39 100644
--- a/tests/tpm_lite/startup.c
+++ b/tests/tpm_lite/startup.c
@@ -11,22 +11,22 @@
#include "tlcl.h"
int main(int argc, char** argv) {
- uint32_t result;
- TlclLibInit();
- result = TlclStartup();
- if (result != 0) {
- printf("tpm startup failed with 0x%x\n", result);
- }
- result = TlclGetFlags(NULL, NULL, NULL);
- if (result != 0) {
- printf("tpm getflags failed with 0x%x\n", result);
- }
- printf("executing SelfTestFull\n");
- TlclSelfTestFull();
- result = TlclGetFlags(NULL, NULL, NULL);
- if (result != 0) {
- printf("tpm getflags failed with 0x%x\n", result);
- }
- printf("TEST SUCCEEDED\n");
- return 0;
+ uint32_t result;
+ TlclLibInit();
+ result = TlclStartup();
+ if (result != 0) {
+ printf("tpm startup failed with 0x%x\n", result);
+ }
+ result = TlclGetFlags(NULL, NULL, NULL);
+ if (result != 0) {
+ printf("tpm getflags failed with 0x%x\n", result);
+ }
+ printf("executing SelfTestFull\n");
+ TlclSelfTestFull();
+ result = TlclGetFlags(NULL, NULL, NULL);
+ if (result != 0) {
+ printf("tpm getflags failed with 0x%x\n", result);
+ }
+ printf("TEST SUCCEEDED\n");
+ return 0;
}
diff --git a/tests/tpm_lite/tlcl_tests.c b/tests/tpm_lite/tlcl_tests.c
index f36021f9..c164f4fe 100644
--- a/tests/tpm_lite/tlcl_tests.c
+++ b/tests/tpm_lite/tlcl_tests.c
@@ -14,16 +14,16 @@
const char* resilient_startup = NULL;
uint32_t TlclStartupIfNeeded(void) {
- static char* null_getenv = "some string"; /* just a unique address */
- uint32_t result = TlclStartup();
- if (resilient_startup == NULL) {
- resilient_startup = getenv("TLCL_RESILIENT_STARTUP");
- if (resilient_startup == NULL) {
- resilient_startup = null_getenv;
- }
- }
- if (resilient_startup == null_getenv) {
- return result;
- }
- return result == TPM_E_INVALID_POSTINIT ? TPM_SUCCESS : result;
+ static char* null_getenv = "some string"; /* just a unique address */
+ uint32_t result = TlclStartup();
+ if (resilient_startup == NULL) {
+ resilient_startup = getenv("TLCL_RESILIENT_STARTUP");
+ if (resilient_startup == NULL) {
+ resilient_startup = null_getenv;
+ }
+ }
+ if (resilient_startup == null_getenv) {
+ return result;
+ }
+ return result == TPM_E_INVALID_POSTINIT ? TPM_SUCCESS : result;
}
diff --git a/tests/tpm_lite/tlcl_tests.h b/tests/tpm_lite/tlcl_tests.h
index 5e23ee39..2b6bd6b8 100644
--- a/tests/tpm_lite/tlcl_tests.h
+++ b/tests/tpm_lite/tlcl_tests.h
@@ -16,14 +16,14 @@
/* Prints error and returns on failure */
#define TPM_CHECK(tpm_command) TPM_EXPECT(tpm_command, TPM_SUCCESS)
-#define TPM_EXPECT(tpm_command, expected_result) do { \
- uint32_t _result = (tpm_command); \
- uint32_t _exp = (expected_result); \
- if (_result != _exp) { \
- printf("TEST FAILED: line %d: " #tpm_command ": 0x%x" \
- " (expecting 0x%x)\n", __LINE__, _result, _exp); \
- return _result; \
- } \
+#define TPM_EXPECT(tpm_command, expected_result) do { \
+ uint32_t _result = (tpm_command); \
+ uint32_t _exp = (expected_result); \
+ if (_result != _exp) { \
+ printf("TEST FAILED: line %d: " #tpm_command ": 0x%x" \
+ " (expecting 0x%x)\n", __LINE__, _result, _exp); \
+ return _result; \
+ } \
} while (0)
diff --git a/tests/tpm_lite/tpmtest_earlyextend.c b/tests/tpm_lite/tpmtest_earlyextend.c
index 837960c1..8bab8afd 100644
--- a/tests/tpm_lite/tpmtest_earlyextend.c
+++ b/tests/tpm_lite/tpmtest_earlyextend.c
@@ -14,13 +14,13 @@
#include "tlcl_tests.h"
int main(int argc, char** argv) {
- uint8_t value_in[20];
- uint8_t value_out[20];
+ uint8_t value_in[20];
+ uint8_t value_out[20];
- TlclLibInit();
- TPM_CHECK(TlclStartup());
- TPM_CHECK(TlclContinueSelfTest());
- TPM_CHECK(TlclExtend(1, value_in, value_out));
- printf("TEST SUCCEEDED\n");
- exit(0);
+ TlclLibInit();
+ TPM_CHECK(TlclStartup());
+ TPM_CHECK(TlclContinueSelfTest());
+ TPM_CHECK(TlclExtend(1, value_in, value_out));
+ printf("TEST SUCCEEDED\n");
+ exit(0);
}
diff --git a/tests/tpm_lite/tpmtest_earlynvram.c b/tests/tpm_lite/tpmtest_earlynvram.c
index fa458338..d5ff77f5 100644
--- a/tests/tpm_lite/tpmtest_earlynvram.c
+++ b/tests/tpm_lite/tpmtest_earlynvram.c
@@ -17,13 +17,13 @@
#define INDEX0 0xcafe
int main(int argc, char** argv) {
- uint32_t x;
+ uint32_t x;
- TlclLibInit();
- TPM_CHECK(TlclStartup());
- TPM_CHECK(TlclContinueSelfTest());
- TPM_CHECK(TlclAssertPhysicalPresence());
- TPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x)));
- printf("TEST SUCCEEDED\n");
- return 0;
+ TlclLibInit();
+ TPM_CHECK(TlclStartup());
+ TPM_CHECK(TlclContinueSelfTest());
+ TPM_CHECK(TlclAssertPhysicalPresence());
+ TPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x)));
+ printf("TEST SUCCEEDED\n");
+ return 0;
}
diff --git a/tests/tpm_lite/tpmtest_earlynvram2.c b/tests/tpm_lite/tpmtest_earlynvram2.c
index 2bd2d712..88f6a6b4 100644
--- a/tests/tpm_lite/tpmtest_earlynvram2.c
+++ b/tests/tpm_lite/tpmtest_earlynvram2.c
@@ -15,13 +15,13 @@
#include "utility.h"
int main(int argc, char** argv) {
- uint32_t x;
+ uint32_t x;
- TlclLibInit();
- TPM_CHECK(TlclStartup());
- TPM_CHECK(TlclContinueSelfTest());
- TPM_CHECK(TlclAssertPhysicalPresence());
- TPM_CHECK(TlclWrite(INDEX0, (uint8_t*) &x, sizeof(x)));
- printf("TEST SUCCEEDED\n");
- return 0;
+ TlclLibInit();
+ TPM_CHECK(TlclStartup());
+ TPM_CHECK(TlclContinueSelfTest());
+ TPM_CHECK(TlclAssertPhysicalPresence());
+ TPM_CHECK(TlclWrite(INDEX0, (uint8_t*) &x, sizeof(x)));
+ printf("TEST SUCCEEDED\n");
+ return 0;
}
diff --git a/tests/tpm_lite/tpmtest_enable.c b/tests/tpm_lite/tpmtest_enable.c
index 9163ca17..645cd467 100644
--- a/tests/tpm_lite/tpmtest_enable.c
+++ b/tests/tpm_lite/tpmtest_enable.c
@@ -14,21 +14,21 @@
int main(int argc, char** argv) {
- uint8_t disable, deactivated;
+ uint8_t disable, deactivated;
- TlclLibInit();
- TPM_CHECK(TlclStartupIfNeeded());
- TPM_CHECK(TlclSelfTestFull());
- TPM_CHECK(TlclAssertPhysicalPresence());
- TPM_CHECK(TlclGetFlags(&disable, &deactivated, NULL));
- printf("disable is %d, deactivated is %d\n", disable, deactivated);
- TPM_CHECK(TlclSetEnable());
- TPM_CHECK(TlclSetDeactivated(0));
- TPM_CHECK(TlclGetFlags(&disable, &deactivated, NULL));
- printf("disable is %d, deactivated is %d\n", disable, deactivated);
- if (disable == 1 || deactivated == 1) {
- VbExError("failed to enable or activate");
- }
- printf("TEST SUCCEEDED\n");
- return 0;
+ TlclLibInit();
+ TPM_CHECK(TlclStartupIfNeeded());
+ TPM_CHECK(TlclSelfTestFull());
+ TPM_CHECK(TlclAssertPhysicalPresence());
+ TPM_CHECK(TlclGetFlags(&disable, &deactivated, NULL));
+ printf("disable is %d, deactivated is %d\n", disable, deactivated);
+ TPM_CHECK(TlclSetEnable());
+ TPM_CHECK(TlclSetDeactivated(0));
+ TPM_CHECK(TlclGetFlags(&disable, &deactivated, NULL));
+ printf("disable is %d, deactivated is %d\n", disable, deactivated);
+ if (disable == 1 || deactivated == 1) {
+ VbExError("failed to enable or activate");
+ }
+ printf("TEST SUCCEEDED\n");
+ return 0;
}
diff --git a/tests/tpm_lite/tpmtest_fastenable.c b/tests/tpm_lite/tpmtest_fastenable.c
index 821658ca..72989c1d 100644
--- a/tests/tpm_lite/tpmtest_fastenable.c
+++ b/tests/tpm_lite/tpmtest_fastenable.c
@@ -19,28 +19,28 @@
#include "tlcl_tests.h"
int main(int argc, char** argv) {
- uint8_t disable, deactivated;
- int i;
+ uint8_t disable, deactivated;
+ int i;
- TlclLibInit();
- TPM_CHECK(TlclStartupIfNeeded());
- TPM_CHECK(TlclSelfTestFull());
- TPM_CHECK(TlclAssertPhysicalPresence());
- TPM_CHECK(TlclGetFlags(&disable, &deactivated, NULL));
- printf("disable is %d, deactivated is %d\n", disable, deactivated);
+ TlclLibInit();
+ TPM_CHECK(TlclStartupIfNeeded());
+ TPM_CHECK(TlclSelfTestFull());
+ TPM_CHECK(TlclAssertPhysicalPresence());
+ TPM_CHECK(TlclGetFlags(&disable, &deactivated, NULL));
+ printf("disable is %d, deactivated is %d\n", disable, deactivated);
- for (i = 0; i < 2; i++) {
- TPM_CHECK(TlclForceClear());
- TPM_CHECK(TlclGetFlags(&disable, &deactivated, NULL));
- printf("disable is %d, deactivated is %d\n", disable, deactivated);
- VbAssert(disable == 1 && deactivated == 1);
- TPM_CHECK(TlclSetEnable());
- TPM_CHECK(TlclSetDeactivated(0));
- TPM_CHECK(TlclGetFlags(&disable, &deactivated, NULL));
- printf("disable is %d, deactivated is %d\n", disable, deactivated);
- VbAssert(disable == 0 && deactivated == 0);
- }
+ for (i = 0; i < 2; i++) {
+ TPM_CHECK(TlclForceClear());
+ TPM_CHECK(TlclGetFlags(&disable, &deactivated, NULL));
+ printf("disable is %d, deactivated is %d\n", disable, deactivated);
+ VbAssert(disable == 1 && deactivated == 1);
+ TPM_CHECK(TlclSetEnable());
+ TPM_CHECK(TlclSetDeactivated(0));
+ TPM_CHECK(TlclGetFlags(&disable, &deactivated, NULL));
+ printf("disable is %d, deactivated is %d\n", disable, deactivated);
+ VbAssert(disable == 0 && deactivated == 0);
+ }
- printf("TEST SUCCEEDED\n");
- return 0;
+ printf("TEST SUCCEEDED\n");
+ return 0;
}
diff --git a/tests/tpm_lite/tpmtest_globallock.c b/tests/tpm_lite/tpmtest_globallock.c
index 96fad9df..2e728524 100644
--- a/tests/tpm_lite/tpmtest_globallock.c
+++ b/tests/tpm_lite/tpmtest_globallock.c
@@ -15,39 +15,41 @@
#include "tlcl_tests.h"
int main(int argc, char** argv) {
- uint32_t zero = 0;
- uint32_t x;
-
- TlclLibInit();
- TPM_CHECK(TlclStartupIfNeeded());
- TPM_CHECK(TlclSelfTestFull());
- TPM_CHECK(TlclAssertPhysicalPresence());
- TPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x)));
- TPM_CHECK(TlclWrite(INDEX0, (uint8_t*) &zero, sizeof(uint32_t)));
- TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x)));
- TPM_CHECK(TlclWrite(INDEX1, (uint8_t*) &zero, sizeof(uint32_t)));
- TPM_CHECK(TlclSetGlobalLock());
-
- // Verifies that write to index0 fails.
- x = 1;
- TPM_EXPECT(TlclWrite(INDEX0, (uint8_t*) &x, sizeof(x)), TPM_E_AREA_LOCKED);
- TPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x)));
- VbAssert(x == 0);
-
- // Verifies that write to index1 is still possible.
- x = 2;
- TPM_CHECK(TlclWrite(INDEX1, (uint8_t*) &x, sizeof(x)));
- TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x)));
- VbAssert(x == 2);
-
- // Turns off PP.
- TlclLockPhysicalPresence();
-
- // Verifies that write to index1 fails.
- x = 3;
- TPM_EXPECT(TlclWrite(INDEX1, (uint8_t*) &x, sizeof(x)), TPM_E_BAD_PRESENCE);
- TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x)));
- VbAssert(x == 2);
- printf("TEST SUCCEEDED\n");
- exit(0);
+ uint32_t zero = 0;
+ uint32_t x;
+
+ TlclLibInit();
+ TPM_CHECK(TlclStartupIfNeeded());
+ TPM_CHECK(TlclSelfTestFull());
+ TPM_CHECK(TlclAssertPhysicalPresence());
+ TPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x)));
+ TPM_CHECK(TlclWrite(INDEX0, (uint8_t*) &zero, sizeof(uint32_t)));
+ TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x)));
+ TPM_CHECK(TlclWrite(INDEX1, (uint8_t*) &zero, sizeof(uint32_t)));
+ TPM_CHECK(TlclSetGlobalLock());
+
+ // Verifies that write to index0 fails.
+ x = 1;
+ TPM_EXPECT(TlclWrite(INDEX0, (uint8_t*) &x, sizeof(x)),
+ TPM_E_AREA_LOCKED);
+ TPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x)));
+ VbAssert(x == 0);
+
+ // Verifies that write to index1 is still possible.
+ x = 2;
+ TPM_CHECK(TlclWrite(INDEX1, (uint8_t*) &x, sizeof(x)));
+ TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x)));
+ VbAssert(x == 2);
+
+ // Turns off PP.
+ TlclLockPhysicalPresence();
+
+ // Verifies that write to index1 fails.
+ x = 3;
+ TPM_EXPECT(TlclWrite(INDEX1, (uint8_t*) &x, sizeof(x)),
+ TPM_E_BAD_PRESENCE);
+ TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x)));
+ VbAssert(x == 2);
+ printf("TEST SUCCEEDED\n");
+ exit(0);
}
diff --git a/tests/tpm_lite/tpmtest_redefine_unowned.c b/tests/tpm_lite/tpmtest_redefine_unowned.c
index c54e1178..522d999f 100644
--- a/tests/tpm_lite/tpmtest_redefine_unowned.c
+++ b/tests/tpm_lite/tpmtest_redefine_unowned.c
@@ -15,49 +15,49 @@
#include "tlcl_tests.h"
int main(int argc, char** argv) {
- uint32_t perm;
- uint32_t x;
+ uint32_t perm;
+ uint32_t x;
- TlclLibInit();
- TPM_CHECK(TlclStartupIfNeeded());
- TPM_CHECK(TlclSelfTestFull());
- TPM_CHECK(TlclAssertPhysicalPresence());
+ TlclLibInit();
+ TPM_CHECK(TlclStartupIfNeeded());
+ TPM_CHECK(TlclSelfTestFull());
+ TPM_CHECK(TlclAssertPhysicalPresence());
- VbAssert(!TlclIsOwned());
+ VbAssert(!TlclIsOwned());
- /* Ensures spaces exist. */
- TPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x)));
- TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x)));
+ /* Ensures spaces exist. */
+ TPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x)));
+ TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x)));
- /* Redefines spaces a couple of times. */
- perm = TPM_NV_PER_PPWRITE | TPM_NV_PER_GLOBALLOCK;
- TPM_CHECK(TlclDefineSpace(INDEX0, perm, 2 * sizeof(uint32_t)));
- TPM_CHECK(TlclDefineSpace(INDEX0, perm, sizeof(uint32_t)));
+ /* Redefines spaces a couple of times. */
+ perm = TPM_NV_PER_PPWRITE | TPM_NV_PER_GLOBALLOCK;
+ TPM_CHECK(TlclDefineSpace(INDEX0, perm, 2 * sizeof(uint32_t)));
+ TPM_CHECK(TlclDefineSpace(INDEX0, perm, sizeof(uint32_t)));
- perm = TPM_NV_PER_PPWRITE;
- TPM_CHECK(TlclDefineSpace(INDEX1, perm, 2 * sizeof(uint32_t)));
- TPM_CHECK(TlclDefineSpace(INDEX1, perm, sizeof(uint32_t)));
+ perm = TPM_NV_PER_PPWRITE;
+ TPM_CHECK(TlclDefineSpace(INDEX1, perm, 2 * sizeof(uint32_t)));
+ TPM_CHECK(TlclDefineSpace(INDEX1, perm, sizeof(uint32_t)));
- // Sets the global lock.
- TlclSetGlobalLock();
+ // Sets the global lock.
+ TlclSetGlobalLock();
- // Verifies that index0 cannot be redefined.
- TPM_EXPECT(TlclDefineSpace(INDEX0, perm, sizeof(uint32_t)),
- TPM_E_AREA_LOCKED);
+ // Verifies that index0 cannot be redefined.
+ TPM_EXPECT(TlclDefineSpace(INDEX0, perm, sizeof(uint32_t)),
+ TPM_E_AREA_LOCKED);
- // Checks that index1 can.
- TPM_CHECK(TlclDefineSpace(INDEX1, perm, 2 * sizeof(uint32_t)));
- TPM_CHECK(TlclDefineSpace(INDEX1, perm, sizeof(uint32_t)));
+ // Checks that index1 can.
+ TPM_CHECK(TlclDefineSpace(INDEX1, perm, 2 * sizeof(uint32_t)));
+ TPM_CHECK(TlclDefineSpace(INDEX1, perm, sizeof(uint32_t)));
- // Turns off PP.
- TlclLockPhysicalPresence();
+ // Turns off PP.
+ TlclLockPhysicalPresence();
- // Verifies that neither index0 nor index1 can be redefined.
- TPM_EXPECT(TlclDefineSpace(INDEX0, perm, sizeof(uint32_t)),
- TPM_E_BAD_PRESENCE);
- TPM_EXPECT(TlclDefineSpace(INDEX1, perm, sizeof(uint32_t)),
- TPM_E_BAD_PRESENCE);
+ // Verifies that neither index0 nor index1 can be redefined.
+ TPM_EXPECT(TlclDefineSpace(INDEX0, perm, sizeof(uint32_t)),
+ TPM_E_BAD_PRESENCE);
+ TPM_EXPECT(TlclDefineSpace(INDEX1, perm, sizeof(uint32_t)),
+ TPM_E_BAD_PRESENCE);
- printf("TEST SUCCEEDED\n");
- exit(0);
+ printf("TEST SUCCEEDED\n");
+ exit(0);
}
diff --git a/tests/tpm_lite/tpmtest_spaceperm.c b/tests/tpm_lite/tpmtest_spaceperm.c
index 71a65218..c2608e4b 100644
--- a/tests/tpm_lite/tpmtest_spaceperm.c
+++ b/tests/tpm_lite/tpmtest_spaceperm.c
@@ -18,19 +18,19 @@
#define PERMPP TPM_NV_PER_PPWRITE
int main(int argc, char** argv) {
- uint32_t perm;
+ uint32_t perm;
- TlclLibInit();
- TPM_CHECK(TlclStartupIfNeeded());
- TPM_CHECK(TlclContinueSelfTest());
- TPM_CHECK(TlclAssertPhysicalPresence());
+ TlclLibInit();
+ TPM_CHECK(TlclStartupIfNeeded());
+ TPM_CHECK(TlclContinueSelfTest());
+ TPM_CHECK(TlclAssertPhysicalPresence());
- TPM_CHECK(TlclGetPermissions(INDEX0, &perm));
- VbAssert((perm & PERMPPGL) == PERMPPGL);
+ TPM_CHECK(TlclGetPermissions(INDEX0, &perm));
+ VbAssert((perm & PERMPPGL) == PERMPPGL);
- TPM_CHECK(TlclGetPermissions(INDEX1, &perm));
- VbAssert((perm & PERMPP) == PERMPP);
+ TPM_CHECK(TlclGetPermissions(INDEX1, &perm));
+ VbAssert((perm & PERMPP) == PERMPP);
- printf("TEST SUCCEEDED\n");
- exit(0);
+ printf("TEST SUCCEEDED\n");
+ exit(0);
}
diff --git a/tests/tpm_lite/tpmtest_testsetup.c b/tests/tpm_lite/tpmtest_testsetup.c
index fac1951e..ce360994 100644
--- a/tests/tpm_lite/tpmtest_testsetup.c
+++ b/tests/tpm_lite/tpmtest_testsetup.c
@@ -15,31 +15,31 @@
#include "utility.h"
int main(int argc, char** argv) {
- uint32_t perm;
- uint32_t result;
- uint32_t x;
-
- TlclLibInit();
-
- TPM_CHECK(TlclStartupIfNeeded());
- TPM_CHECK(TlclSelfTestFull());
- TPM_CHECK(TlclAssertPhysicalPresence());
- TPM_CHECK(TlclForceClear());
- TPM_CHECK(TlclSetEnable());
- TPM_CHECK(TlclSetDeactivated(0));
-
- result = TlclRead(INDEX0, (uint8_t*) &x, sizeof(x));
- if (result == TPM_E_BADINDEX) {
- perm = TPM_NV_PER_PPWRITE | TPM_NV_PER_GLOBALLOCK;
- TPM_CHECK(TlclDefineSpace(INDEX0, perm, sizeof(uint32_t)));
- }
-
- result = TlclRead(INDEX1, (uint8_t*) &x, sizeof(x));
- if (result == TPM_E_BADINDEX) {
- perm = TPM_NV_PER_PPWRITE;
- TPM_CHECK(TlclDefineSpace(INDEX1, perm, sizeof(uint32_t)));
- }
-
- printf("TEST SUCCEEDED\n");
- exit(0);
+ uint32_t perm;
+ uint32_t result;
+ uint32_t x;
+
+ TlclLibInit();
+
+ TPM_CHECK(TlclStartupIfNeeded());
+ TPM_CHECK(TlclSelfTestFull());
+ TPM_CHECK(TlclAssertPhysicalPresence());
+ TPM_CHECK(TlclForceClear());
+ TPM_CHECK(TlclSetEnable());
+ TPM_CHECK(TlclSetDeactivated(0));
+
+ result = TlclRead(INDEX0, (uint8_t*) &x, sizeof(x));
+ if (result == TPM_E_BADINDEX) {
+ perm = TPM_NV_PER_PPWRITE | TPM_NV_PER_GLOBALLOCK;
+ TPM_CHECK(TlclDefineSpace(INDEX0, perm, sizeof(uint32_t)));
+ }
+
+ result = TlclRead(INDEX1, (uint8_t*) &x, sizeof(x));
+ if (result == TPM_E_BADINDEX) {
+ perm = TPM_NV_PER_PPWRITE;
+ TPM_CHECK(TlclDefineSpace(INDEX1, perm, sizeof(uint32_t)));
+ }
+
+ printf("TEST SUCCEEDED\n");
+ exit(0);
}
diff --git a/tests/tpm_lite/tpmtest_timing.c b/tests/tpm_lite/tpmtest_timing.c
index 677b533b..d86b4eee 100644
--- a/tests/tpm_lite/tpmtest_timing.c
+++ b/tests/tpm_lite/tpmtest_timing.c
@@ -21,48 +21,48 @@
/* Runs [op] and ensures it returns success and doesn't run longer than
* [time_limit] in milliseconds.
*/
-#define TTPM_CHECK(op, time_limit) do { \
- struct timeval before, after; \
- int time; \
- uint32_t __result; \
- gettimeofday(&before, NULL); \
- __result = op; \
- if (__result != TPM_SUCCESS) { \
- printf(#op ": error 0x%x\n", __result); \
- errors++; \
- } \
- gettimeofday(&after, NULL); \
- time = (int) ((after.tv_sec - before.tv_sec) * 1000 + \
- (after.tv_usec - before.tv_usec) / 1000); \
- printf(#op ": %d ms\n", time); \
- if (time > time_limit) { \
- printf(#op " exceeded " #time_limit " ms\n"); \
- time_limit_exceeded = 1; \
- } \
- } while (0)
+#define TTPM_CHECK(op, time_limit) do { \
+ struct timeval before, after; \
+ int time; \
+ uint32_t __result; \
+ gettimeofday(&before, NULL); \
+ __result = op; \
+ if (__result != TPM_SUCCESS) { \
+ printf(#op ": error 0x%x\n", __result); \
+ errors++; \
+ } \
+ gettimeofday(&after, NULL); \
+ time = (int) ((after.tv_sec - before.tv_sec) * 1000 + \
+ (after.tv_usec - before.tv_usec) / 1000); \
+ printf(#op ": %d ms\n", time); \
+ if (time > time_limit) { \
+ printf(#op " exceeded " #time_limit " ms\n"); \
+ time_limit_exceeded = 1; \
+ } \
+} while (0)
int main(int argc, char** argv) {
- uint32_t x;
- uint8_t in[20], out[20];
- int time_limit_exceeded = 0;
- int errors = 0;
+ uint32_t x;
+ uint8_t in[20], out[20];
+ int time_limit_exceeded = 0;
+ int errors = 0;
- TlclLibInit();
- TTPM_CHECK(0, 50);
- TTPM_CHECK(TlclStartupIfNeeded(), 50);
- TTPM_CHECK(TlclContinueSelfTest(), 100);
- TTPM_CHECK(TlclSelfTestFull(), 1000);
- TTPM_CHECK(TlclAssertPhysicalPresence(), 100);
- TTPM_CHECK(TlclWrite(INDEX0, (uint8_t*) &x, sizeof(x)), 100);
- TTPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x)), 100);
- TTPM_CHECK(TlclExtend(0, in, out), 200);
- TTPM_CHECK(TlclSetGlobalLock(), 50);
- TTPM_CHECK(TlclLockPhysicalPresence(), 100);
- if (time_limit_exceeded || errors > 0) {
- printf("TEST FAILED\n");
- exit(1);
- } else {
- printf("TEST SUCCEEDED\n");
- return 0;
- }
+ TlclLibInit();
+ TTPM_CHECK(0, 50);
+ TTPM_CHECK(TlclStartupIfNeeded(), 50);
+ TTPM_CHECK(TlclContinueSelfTest(), 100);
+ TTPM_CHECK(TlclSelfTestFull(), 1000);
+ TTPM_CHECK(TlclAssertPhysicalPresence(), 100);
+ TTPM_CHECK(TlclWrite(INDEX0, (uint8_t*) &x, sizeof(x)), 100);
+ TTPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x)), 100);
+ TTPM_CHECK(TlclExtend(0, in, out), 200);
+ TTPM_CHECK(TlclSetGlobalLock(), 50);
+ TTPM_CHECK(TlclLockPhysicalPresence(), 100);
+ if (time_limit_exceeded || errors > 0) {
+ printf("TEST FAILED\n");
+ exit(1);
+ } else {
+ printf("TEST SUCCEEDED\n");
+ return 0;
+ }
}
diff --git a/tests/tpm_lite/tpmtest_writelimit.c b/tests/tpm_lite/tpmtest_writelimit.c
index 952033cb..66dcc036 100644
--- a/tests/tpm_lite/tpmtest_writelimit.c
+++ b/tests/tpm_lite/tpmtest_writelimit.c
@@ -17,40 +17,42 @@
#define TPM_MAX_NV_WRITES_NOOWNER 64
int main(int argc, char** argv) {
- int i;
-
- uint32_t result;
-
- TlclLibInit();
-
- TPM_CHECK(TlclStartupIfNeeded());
- TPM_CHECK(TlclSelfTestFull());
- TPM_CHECK(TlclAssertPhysicalPresence());
- TPM_CHECK(TlclForceClear());
- TPM_CHECK(TlclSetEnable());
- TPM_CHECK(TlclSetDeactivated(0));
-
- for (i = 0; i < TPM_MAX_NV_WRITES_NOOWNER + 2; i++) {
- printf("writing %d\n", i);
- if ((result = TlclWrite(INDEX0, (uint8_t*)&i, sizeof(i))) != TPM_SUCCESS) {
- switch (result) {
- case TPM_E_MAXNVWRITES:
- VbAssert(i >= TPM_MAX_NV_WRITES_NOOWNER);
- break;
- default:
- VbExError("unexpected error code %d (0x%x)\n", result, result);
- }
- }
- }
-
- /* Reset write count */
- TPM_CHECK(TlclForceClear());
- TPM_CHECK(TlclSetEnable());
- TPM_CHECK(TlclSetDeactivated(0));
-
- /* Try writing again. */
- TPM_CHECK(TlclWrite(INDEX0, (uint8_t*)&i, sizeof(i)));
-
- printf("TEST SUCCEEDED\n");
- exit(0);
+ int i;
+
+ uint32_t result;
+
+ TlclLibInit();
+
+ TPM_CHECK(TlclStartupIfNeeded());
+ TPM_CHECK(TlclSelfTestFull());
+ TPM_CHECK(TlclAssertPhysicalPresence());
+ TPM_CHECK(TlclForceClear());
+ TPM_CHECK(TlclSetEnable());
+ TPM_CHECK(TlclSetDeactivated(0));
+
+ for (i = 0; i < TPM_MAX_NV_WRITES_NOOWNER + 2; i++) {
+ printf("writing %d\n", i);
+ if ((result = TlclWrite(INDEX0, (uint8_t*)&i,
+ sizeof(i))) != TPM_SUCCESS) {
+ switch (result) {
+ case TPM_E_MAXNVWRITES:
+ VbAssert(i >= TPM_MAX_NV_WRITES_NOOWNER);
+ break;
+ default:
+ VbExError("unexpected error code %d (0x%x)\n",
+ result, result);
+ }
+ }
+ }
+
+ /* Reset write count */
+ TPM_CHECK(TlclForceClear());
+ TPM_CHECK(TlclSetEnable());
+ TPM_CHECK(TlclSetDeactivated(0));
+
+ /* Try writing again. */
+ TPM_CHECK(TlclWrite(INDEX0, (uint8_t*)&i, sizeof(i)));
+
+ printf("TEST SUCCEEDED\n");
+ exit(0);
}