| OLD | NEW |
| 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
| 3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
| 4 */ | 4 */ |
| 5 | 5 |
| 6 /* Test of two-stage locking using bGlobalLock and PP. | 6 /* Test of two-stage locking using bGlobalLock and PP. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include <stdio.h> | 9 #include <stdio.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| 11 #include <stdlib.h> | 11 #include <stdlib.h> |
| 12 | 12 |
| 13 #include "tlcl.h" | 13 #include "tlcl.h" |
| 14 #include "tlcl_tests.h" | 14 #include "tlcl_tests.h" |
| 15 #include "utility.h" | 15 #include "utility.h" |
| 16 | 16 |
| 17 int main(int argc, char** argv) { | 17 int main(int argc, char** argv) { |
| 18 uint32_t zero = 0; | 18 uint32_t zero = 0; |
| 19 uint32_t result; | |
| 20 uint32_t x; | 19 uint32_t x; |
| 21 | 20 |
| 22 TlclLibInit(); | 21 TlclLibInit(); |
| 23 TPM_CHECK(TlclStartupIfNeeded()); | 22 TPM_CHECK(TlclStartupIfNeeded()); |
| 24 TPM_CHECK(TlclSelfTestFull()); | 23 TPM_CHECK(TlclSelfTestFull()); |
| 25 TPM_CHECK(TlclAssertPhysicalPresence()); | 24 TPM_CHECK(TlclAssertPhysicalPresence()); |
| 26 TPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x))); | 25 TPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x))); |
| 27 TPM_CHECK(TlclWrite(INDEX0, (uint8_t*) &zero, sizeof(uint32_t))); | 26 TPM_CHECK(TlclWrite(INDEX0, (uint8_t*) &zero, sizeof(uint32_t))); |
| 28 TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x))); | 27 TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x))); |
| 29 TPM_CHECK(TlclWrite(INDEX1, (uint8_t*) &zero, sizeof(uint32_t))); | 28 TPM_CHECK(TlclWrite(INDEX1, (uint8_t*) &zero, sizeof(uint32_t))); |
| 30 TPM_CHECK(TlclSetGlobalLock()); | 29 TPM_CHECK(TlclSetGlobalLock()); |
| 31 | 30 |
| 32 // Verifies that write to index0 fails. | 31 // Verifies that write to index0 fails. |
| 33 x = 1; | 32 x = 1; |
| 34 result = TlclWrite(INDEX0, (uint8_t*) &x, sizeof(x)); | 33 TPM_EXPECT(TlclWrite(INDEX0, (uint8_t*) &x, sizeof(x)), TPM_E_AREA_LOCKED); |
| 35 assert(result == TPM_E_AREA_LOCKED); | |
| 36 TPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x))); | 34 TPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x))); |
| 37 assert(x == 0); | 35 assert(x == 0); |
| 38 | 36 |
| 39 // Verifies that write to index1 is still possible. | 37 // Verifies that write to index1 is still possible. |
| 40 x = 2; | 38 x = 2; |
| 41 TPM_CHECK(TlclWrite(INDEX1, (uint8_t*) &x, sizeof(x))); | 39 TPM_CHECK(TlclWrite(INDEX1, (uint8_t*) &x, sizeof(x))); |
| 42 TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x))); | 40 TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x))); |
| 43 assert(x == 2); | 41 assert(x == 2); |
| 44 | 42 |
| 45 // Turns off PP. | 43 // Turns off PP. |
| 46 TlclLockPhysicalPresence(); | 44 TlclLockPhysicalPresence(); |
| 47 | 45 |
| 48 // Verifies that write to index1 fails. | 46 // Verifies that write to index1 fails. |
| 49 x = 3; | 47 x = 3; |
| 50 result = TlclWrite(INDEX1, (uint8_t*) &x, sizeof(x)); | 48 TPM_EXPECT(TlclWrite(INDEX1, (uint8_t*) &x, sizeof(x)), TPM_E_BAD_PRESENCE); |
| 51 assert(result == TPM_E_BAD_PRESENCE); | |
| 52 TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x))); | 49 TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x))); |
| 53 assert(x == 2); | 50 assert(x == 2); |
| 54 printf("TEST SUCCEEDED\n"); | 51 printf("TEST SUCCEEDED\n"); |
| 55 exit(0); | 52 exit(0); |
| 56 } | 53 } |
| OLD | NEW |