| 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> |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 TPM_CHECK(TlclSelfTestFull()); | 24 TPM_CHECK(TlclSelfTestFull()); |
| 25 TPM_CHECK(TlclAssertPhysicalPresence()); | 25 TPM_CHECK(TlclAssertPhysicalPresence()); |
| 26 TPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x))); | 26 TPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x))); |
| 27 TPM_CHECK(TlclWrite(INDEX0, (uint8_t*) &zero, sizeof(uint32_t))); | 27 TPM_CHECK(TlclWrite(INDEX0, (uint8_t*) &zero, sizeof(uint32_t))); |
| 28 TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x))); | 28 TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x))); |
| 29 TPM_CHECK(TlclWrite(INDEX1, (uint8_t*) &zero, sizeof(uint32_t))); | 29 TPM_CHECK(TlclWrite(INDEX1, (uint8_t*) &zero, sizeof(uint32_t))); |
| 30 TPM_CHECK(TlclSetGlobalLock()); | 30 TPM_CHECK(TlclSetGlobalLock()); |
| 31 | 31 |
| 32 // Verifies that write to index0 fails. | 32 // Verifies that write to index0 fails. |
| 33 x = 1; | 33 x = 1; |
| 34 result = TlclWrite(INDEX0, (uint8_t*) &x, sizeof(x)); | 34 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))); | 35 TPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x))); |
| 37 assert(x == 0); | 36 assert(x == 0); |
| 38 | 37 |
| 39 // Verifies that write to index1 is still possible. | 38 // Verifies that write to index1 is still possible. |
| 40 x = 2; | 39 x = 2; |
| 41 TPM_CHECK(TlclWrite(INDEX1, (uint8_t*) &x, sizeof(x))); | 40 TPM_CHECK(TlclWrite(INDEX1, (uint8_t*) &x, sizeof(x))); |
| 42 TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x))); | 41 TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x))); |
| 43 assert(x == 2); | 42 assert(x == 2); |
| 44 | 43 |
| 45 // Turns off PP. | 44 // Turns off PP. |
| 46 TlclLockPhysicalPresence(); | 45 TlclLockPhysicalPresence(); |
| 47 | 46 |
| 48 // Verifies that write to index1 fails. | 47 // Verifies that write to index1 fails. |
| 49 x = 3; | 48 x = 3; |
| 50 result = TlclWrite(INDEX1, (uint8_t*) &x, sizeof(x)); | 49 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))); | 50 TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x))); |
| 53 assert(x == 2); | 51 assert(x == 2); |
| 54 printf("TEST SUCCEEDED\n"); | 52 printf("TEST SUCCEEDED\n"); |
| 55 exit(0); | 53 exit(0); |
| 56 } | 54 } |
| OLD | NEW |